From 602a2a53b42efb6805e47f0e31b2be35c2a758f5 Mon Sep 17 00:00:00 2001 From: neolithos Date: Sat, 20 Jun 2015 00:45:38 +0200 Subject: [PATCH] Fix: Bindingrestriction is wrong --- NeoLua/Lua.Runtime.cs | 2 + NeoLua/LuaType.cs | 2141 +++++++++++++++++++++-------------------- 2 files changed, 1077 insertions(+), 1066 deletions(-) diff --git a/NeoLua/Lua.Runtime.cs b/NeoLua/Lua.Runtime.cs index 1fe4390..f826817 100644 --- a/NeoLua/Lua.Runtime.cs +++ b/NeoLua/Lua.Runtime.cs @@ -73,6 +73,7 @@ public partial class Lua internal readonly static MethodInfo TypeGetGenericItemMethodInfo; internal readonly static MethodInfo TypeGetTypeMethodInfoArgType; internal readonly static PropertyInfo TypeTypePropertyInfo; + internal readonly static PropertyInfo TypeParentPropertyInfo; // LuaMethod internal readonly static ConstructorInfo MethodConstructorInfo; internal readonly static ConstructorInfo OverloadedMethodConstructorInfo; @@ -192,6 +193,7 @@ static Lua() TypeGetTypeMethodInfoArgIndex = tiLuaType.FindDeclaredMethod("GetType", ReflectionFlag.Static, typeof(int)); TypeGetTypeMethodInfoArgType = tiLuaType.FindDeclaredMethod("GetType", ReflectionFlag.Static, typeof(Type)); TypeTypePropertyInfo = tiLuaType.FindDeclaredProperty("Type", ReflectionFlag.None); + TypeParentPropertyInfo = tiLuaType.FindDeclaredProperty("Parent", ReflectionFlag.None); // LuaMethod var tiLuaMethod = typeof(LuaMethod).GetTypeInfo(); diff --git a/NeoLua/LuaType.cs b/NeoLua/LuaType.cs index 5323c0d..bd987d1 100644 --- a/NeoLua/LuaType.cs +++ b/NeoLua/LuaType.cs @@ -57,7 +57,7 @@ void ILuaTypeResolver.Refresh() { } Type ILuaTypeResolver.GetType(string sTypeName) { - lock(assemblies) + lock (assemblies) { foreach (var assembly in assemblies) { @@ -84,96 +84,96 @@ int ILuaTypeResolver.Version #region -- class LuaType ------------------------------------------------------------ /////////////////////////////////////////////////////////////////////////////// - /// Base class for the Type-Wrapper. - public sealed class LuaType : IDynamicMetaObjectProvider - { - #region -- class LuaTypeMetaObject ------------------------------------------------ - - /////////////////////////////////////////////////////////////////////////////// - /// - private class LuaTypeMetaObject : DynamicMetaObject - { - #region -- Ctor/Dtor ------------------------------------------------------------ - - public LuaTypeMetaObject(Expression expression, LuaType value) - : base(expression, BindingRestrictions.Empty, value) - { - } // ctor - - #endregion - - #region -- BindGetMember -------------------------------------------------------- - - public override DynamicMetaObject BindGetMember(GetMemberBinder binder) - { - LuaType val = ((LuaType)Value); - Type type = val.Type; - Expression expr; - - if (type != null) // we have a type, bind to the member - { - try - { - expr = Lua.EnsureType(LuaEmit.GetMember(Lua.GetRuntime(binder), null, type, binder.Name, binder.IgnoreCase, false), binder.ReturnType); - } - catch (LuaEmitException e) - { - expr = Lua.ThrowExpression(e.Message, binder.ReturnType); - } - return new DynamicMetaObject(expr, GetTypeResolvedRestriction(type)); - } - else - { - // Get the index for the access, as long is there no type behind - expr = Expression.Condition( - GetUpdateCondition(), - binder.GetUpdateExpression(binder.ReturnType), - Lua.EnsureType(Expression.Call(Lua.TypeGetTypeMethodInfoArgIndex, Expression.Constant(val.GetIndex(binder.Name, binder.IgnoreCase, null), typeof(int))), binder.ReturnType) - ); - return new DynamicMetaObject(expr, GetTypeNotResolvedRestriction()); - } - } // func BindGetMember - - #endregion - - #region -- BindSetMember -------------------------------------------------------- - - public override DynamicMetaObject BindSetMember(SetMemberBinder binder, DynamicMetaObject value) - { - Type type = ((LuaType)Value).Type; - - Expression expr; - if (type != null) - { - try - { - expr = Lua.EnsureType(LuaEmit.SetMember(Lua.GetRuntime(binder), null, type, binder.Name, binder.IgnoreCase, value.Expression, value.LimitType, false), binder.ReturnType); - } - catch (LuaEmitException e) - { - expr = Lua.ThrowExpression(e.Message, binder.ReturnType); - } + /// Base class for the Type-Wrapper. + public sealed class LuaType : IDynamicMetaObjectProvider + { + #region -- class LuaTypeMetaObject ------------------------------------------------ + + /////////////////////////////////////////////////////////////////////////////// + /// + private class LuaTypeMetaObject : DynamicMetaObject + { + #region -- Ctor/Dtor ------------------------------------------------------------ + + public LuaTypeMetaObject(Expression expression, LuaType value) + : base(expression, BindingRestrictions.Empty, value) + { + } // ctor + + #endregion + + #region -- BindGetMember -------------------------------------------------------- + + public override DynamicMetaObject BindGetMember(GetMemberBinder binder) + { + LuaType val = ((LuaType)Value); + Type type = val.Type; + Expression expr; + + if (type != null) // we have a type, bind to the member + { + try + { + expr = Lua.EnsureType(LuaEmit.GetMember(Lua.GetRuntime(binder), null, type, binder.Name, binder.IgnoreCase, false), binder.ReturnType); + } + catch (LuaEmitException e) + { + expr = Lua.ThrowExpression(e.Message, binder.ReturnType); + } + return new DynamicMetaObject(expr, GetTypeResolvedRestriction(type)); + } + else + { + // Get the index for the access, as long is there no type behind + expr = Expression.Condition( + GetUpdateCondition(), + binder.GetUpdateExpression(binder.ReturnType), + Lua.EnsureType(Expression.Call(Lua.TypeGetTypeMethodInfoArgIndex, Expression.Constant(val.GetIndex(binder.Name, binder.IgnoreCase, null), typeof(int))), binder.ReturnType) + ); + return new DynamicMetaObject(expr, GetTypeNotResolvedRestriction()); + } + } // func BindGetMember + + #endregion + + #region -- BindSetMember -------------------------------------------------------- + + public override DynamicMetaObject BindSetMember(SetMemberBinder binder, DynamicMetaObject value) + { + Type type = ((LuaType)Value).Type; + + Expression expr; + if (type != null) + { + try + { + expr = Lua.EnsureType(LuaEmit.SetMember(Lua.GetRuntime(binder), null, type, binder.Name, binder.IgnoreCase, value.Expression, value.LimitType, false), binder.ReturnType); + } + catch (LuaEmitException e) + { + expr = Lua.ThrowExpression(e.Message, binder.ReturnType); + } return new DynamicMetaObject(expr, GetTypeResolvedRestriction(type).Merge(Lua.GetSimpleRestriction(value))); - } - else - { - expr = Expression.Condition( - GetUpdateCondition(), - binder.GetUpdateExpression(binder.ReturnType), - Lua.ThrowExpression(String.Format(Properties.Resources.rsMemberNotWritable, "LuaType", binder.Name), binder.ReturnType) - ); - return new DynamicMetaObject(expr, GetTypeNotResolvedRestriction()); - } - } // proc BindSetMember - - #endregion - - #region -- BindGetIndex --------------------------------------------------------- - - public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes) - { - LuaType val = (LuaType)Value; - Type type = val.Type; + } + else + { + expr = Expression.Condition( + GetUpdateCondition(), + binder.GetUpdateExpression(binder.ReturnType), + Lua.ThrowExpression(String.Format(Properties.Resources.rsMemberNotWritable, "LuaType", binder.Name), binder.ReturnType) + ); + return new DynamicMetaObject(expr, GetTypeNotResolvedRestriction()); + } + } // proc BindSetMember + + #endregion + + #region -- BindGetIndex --------------------------------------------------------- + + public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes) + { + LuaType val = (LuaType)Value; + Type type = val.Type; if (type != null && indexes.Length == 0) { // create a array of the type @@ -232,93 +232,93 @@ public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMet ); } } - } // func BindGetIndex + } // func BindGetIndex - #endregion + #endregion - #region -- BindSetIndex --------------------------------------------------------- + #region -- BindSetIndex --------------------------------------------------------- - public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value) - { - return new DynamicMetaObject( - Lua.ThrowExpression(Properties.Resources.rsIndexNotFound, binder.ReturnType), - BindingRestrictions.GetTypeRestriction(Expression, LimitType) - ); - } // func BindSetIndex + public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value) + { + return new DynamicMetaObject( + Lua.ThrowExpression(Properties.Resources.rsIndexNotFound, binder.ReturnType), + BindingRestrictions.GetTypeRestriction(Expression, LimitType) + ); + } // func BindSetIndex - #endregion + #endregion - #region -- BindInvokeMember ----------------------------------------------------- + #region -- BindInvokeMember ----------------------------------------------------- - public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args) - { - Type type = ((LuaType)Value).Type; + public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args) + { + Type type = ((LuaType)Value).Type; - BindingRestrictions restrictions; - Expression expr; - if (type != null) - { - try - { + BindingRestrictions restrictions; + Expression expr; + if (type != null) + { + try + { MethodInfo mi = LuaEmit.FindMethod( type.GetRuntimeMethods().Where( c => String.Compare(binder.Name, c.Name, binder.IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0 && c.IsStatic ), args, mo => mo.LimitType, false ); - if (mi == null) - { + if (mi == null) + { var stringComparison = binder.IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; if (args.Length == 0 && String.Compare(binder.Name, "GetType", stringComparison) == 0) - { - restrictions = BindingRestrictions.GetInstanceRestriction(Expression, Value); - expr = Lua.EnsureType(Expression.Property(Lua.EnsureType(Expression, typeof(LuaType)), Lua.TypeTypePropertyInfo), binder.ReturnType); - } + { + restrictions = BindingRestrictions.GetInstanceRestriction(Expression, Value); + expr = Lua.EnsureType(Expression.Property(Lua.EnsureType(Expression, typeof(LuaType)), Lua.TypeTypePropertyInfo), binder.ReturnType); + } else if (String.Compare(binder.Name, "ctor", stringComparison) == 0) - { - return BindNewObject(type, args, binder.ReturnType); - } - else - { - restrictions = Lua.GetMethodSignatureRestriction(this, args); - expr = Lua.ThrowExpression(Properties.Resources.rsNilNotCallable, binder.ReturnType); - } - } - else - { - restrictions = Lua.GetMethodSignatureRestriction(this, args); - expr = Lua.EnsureType(LuaEmit.BindParameter(Lua.GetRuntime(binder), - a => Expression.Call(null, mi, a), - mi.GetParameters(), - args, - mo => mo.Expression, mo => mo.LimitType, false), binder.ReturnType, true); - } - } - catch (LuaEmitException e) - { - restrictions = BindingRestrictions.GetInstanceRestriction(Expression, Value); - expr = Lua.ThrowExpression(e.Message, binder.ReturnType); - } + { + return BindNewObject(type, args, binder.ReturnType); + } + else + { + restrictions = Lua.GetMethodSignatureRestriction(this, args); + expr = Lua.ThrowExpression(Properties.Resources.rsNilNotCallable, binder.ReturnType); + } + } + else + { + restrictions = Lua.GetMethodSignatureRestriction(this, args); + expr = Lua.EnsureType(LuaEmit.BindParameter(Lua.GetRuntime(binder), + a => Expression.Call(null, mi, a), + mi.GetParameters(), + args, + mo => mo.Expression, mo => mo.LimitType, false), binder.ReturnType, true); + } + } + catch (LuaEmitException e) + { + restrictions = BindingRestrictions.GetInstanceRestriction(Expression, Value); + expr = Lua.ThrowExpression(e.Message, binder.ReturnType); + } return new DynamicMetaObject(expr, restrictions.Merge(GetTypeResolvedRestriction(type))); - } - else - { - expr = Expression.Condition( - GetUpdateCondition(), - binder.GetUpdateExpression(binder.ReturnType), - Lua.ThrowExpression(Properties.Resources.rsNilNotCallable, binder.ReturnType) - ); + } + else + { + expr = Expression.Condition( + GetUpdateCondition(), + binder.GetUpdateExpression(binder.ReturnType), + Lua.ThrowExpression(Properties.Resources.rsNilNotCallable, binder.ReturnType) + ); - return new DynamicMetaObject(expr, GetTypeNotResolvedRestriction()); - } - } // func BindInvokeMember + return new DynamicMetaObject(expr, GetTypeNotResolvedRestriction()); + } + } // func BindInvokeMember - #endregion + #endregion - #region -- BindInvoke ----------------------------------------------------------- + #region -- BindInvoke ----------------------------------------------------------- - public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) - { - Type type = ((LuaType)Value).Type; + public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) + { + Type type = ((LuaType)Value).Type; if (type != null) { @@ -351,169 +351,175 @@ public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObj ); return new DynamicMetaObject(expr, BindingRestrictions.GetInstanceRestriction(Expression, Value)); } - } // func BindInvoke - - #endregion - - #region -- BindConvert ---------------------------------------------------------- - - public override DynamicMetaObject BindConvert(ConvertBinder binder) - { - if (binder.Type == typeof(Type)) - { - return new DynamicMetaObject( - Lua.EnsureType(Expression.Property(Lua.EnsureType(Expression, typeof(LuaType)), Lua.TypeTypePropertyInfo), typeof(Type)), - BindingRestrictions.GetTypeRestriction(Expression, typeof(LuaType)) - ); - } - return base.BindConvert(binder); - } // func BindConvert - - #endregion - - private DynamicMetaObject BindNewObject(Type typeNew, DynamicMetaObject[] args, Type returnType) - { - Expression expr; - try - { - var typeinfoNew=typeNew.GetTypeInfo(); + } // func BindInvoke + + #endregion + + #region -- BindConvert ---------------------------------------------------------- + + public override DynamicMetaObject BindConvert(ConvertBinder binder) + { + if (binder.Type == typeof(Type)) + { + return new DynamicMetaObject( + Lua.EnsureType(Expression.Property(Lua.EnsureType(Expression, typeof(LuaType)), Lua.TypeTypePropertyInfo), typeof(Type)), + BindingRestrictions.GetTypeRestriction(Expression, typeof(LuaType)) + ); + } + return base.BindConvert(binder); + } // func BindConvert + + #endregion + + private DynamicMetaObject BindNewObject(Type typeNew, DynamicMetaObject[] args, Type returnType) + { + Expression expr; + try + { + var typeinfoNew = typeNew.GetTypeInfo(); ConstructorInfo ci = typeinfoNew.IsValueType && args.Length == 0 ? // value-types with zero arguments always constructable null : LuaEmit.FindMember(typeNew.GetTypeInfo().DeclaredConstructors.Where(c => c.IsPublic), args, mo => mo.LimitType); - // ctor not found for a class + // ctor not found for a class if (ci == null && !typeinfoNew.IsValueType) - expr = Lua.ThrowExpression(String.Format(Properties.Resources.rsMemberNotResolved, typeNew.Name, "ctor"), returnType); - - // create the object - expr = Lua.EnsureType( - LuaEmit.BindParameter(null, - a => ci == null ? Expression.New(typeNew) : Expression.New(ci, a), - ci == null ? new ParameterInfo[0] : ci.GetParameters(), - args, - mo => mo.Expression, mo => mo.LimitType, false), - returnType, true - ); - } - catch (LuaEmitException e) - { - expr = Lua.ThrowExpression(e.Message, returnType); - } + expr = Lua.ThrowExpression(String.Format(Properties.Resources.rsMemberNotResolved, typeNew.Name, "ctor"), returnType); + + // create the object + expr = Lua.EnsureType( + LuaEmit.BindParameter(null, + a => ci == null ? Expression.New(typeNew) : Expression.New(ci, a), + ci == null ? new ParameterInfo[0] : ci.GetParameters(), + args, + mo => mo.Expression, mo => mo.LimitType, false), + returnType, true + ); + } + catch (LuaEmitException e) + { + expr = Lua.ThrowExpression(e.Message, returnType); + } return new DynamicMetaObject(expr, GetTypeResolvedRestriction(typeNew).Merge(Lua.GetMethodSignatureRestriction(null, args))); - } // func BindNewObject - - private BindingRestrictions GetTypeNotResolvedRestriction() - { - return BindingRestrictions.GetExpressionRestriction( - Expression.AndAlso( - Expression.TypeEqual(Expression, typeof(LuaType)), - Expression.Equal( - Expression.Property(Lua.EnsureType(Expression, typeof(LuaType)), Lua.TypeTypePropertyInfo), - Expression.Default(typeof(Type)) - ) - ) - ); - } // func GetTypeNotResolvedRestriction - - private BindingRestrictions GetTypeResolvedRestriction(Type type) - { - return BindingRestrictions.GetExpressionRestriction( - Expression.AndAlso( - Expression.TypeEqual(Expression, typeof(LuaType)), - Expression.Equal( - Expression.Property(Lua.EnsureType(Expression, typeof(LuaType)), Lua.TypeTypePropertyInfo), - Expression.Constant(type) - ) - ) - ); - } // func GetTypeResolvedRestriction - - private BinaryExpression GetUpdateCondition() - { - return Expression.NotEqual( - Expression.Property(Expression.Convert(Expression, typeof(LuaType)), Lua.TypeTypePropertyInfo), - Expression.Constant(null, typeof(Type)) - ); - } // func GetUpdateCondition - - public override IEnumerable GetDynamicMemberNames() - { - return ((LuaType)Value).index.Keys; - } // proc GetDynamicMemberNames - } // class LuaTypeMetaObject - - #endregion + } // func BindNewObject + + private BindingRestrictions GetTypeNotResolvedRestriction() + { + return BindingRestrictions.GetExpressionRestriction( + Expression.AndAlso( + Expression.TypeEqual(Expression, typeof(LuaType)), + Expression.AndAlso( + Expression.ReferenceEqual( + Expression.Property(Expression.Convert(Expression, typeof(LuaType)), Lua.TypeParentPropertyInfo), + Expression.Constant(((LuaType)Value).Parent) + ), + Expression.Equal( + Expression.Property(Lua.EnsureType(Expression, typeof(LuaType)), Lua.TypeTypePropertyInfo), + Expression.Default(typeof(Type)) + ) + ) + ) + ); + } // func GetTypeNotResolvedRestriction + + private BindingRestrictions GetTypeResolvedRestriction(Type type) + { + return BindingRestrictions.GetExpressionRestriction( + Expression.AndAlso( + Expression.TypeEqual(Expression, typeof(LuaType)), + Expression.Equal( + Expression.Property(Lua.EnsureType(Expression, typeof(LuaType)), Lua.TypeTypePropertyInfo), + Expression.Constant(type) + ) + ) + ); + } // func GetTypeResolvedRestriction + + private BinaryExpression GetUpdateCondition() + { + return Expression.NotEqual( + Expression.Property(Expression.Convert(Expression, typeof(LuaType)), Lua.TypeTypePropertyInfo), + Expression.Constant(null, typeof(Type)) + ); + } // func GetUpdateCondition + + public override IEnumerable GetDynamicMemberNames() + { + return ((LuaType)Value).index.Keys; + } // proc GetDynamicMemberNames + } // class LuaTypeMetaObject + + #endregion private LuaType parent; // Access to parent type or namespace private LuaType baseType; // If the type is inherited, then this points to the base type - private Type type; // Type that is represented, null if it is not resolved until now + private Type type; // Type that is represented, null if it is not resolved until now - private string sName; // Name of the unresolved type or namespace + private string sName; // Name of the unresolved type or namespace private string sAliasName = null; // Current alias name - private int iResolverVersion; // Number of loaded assemblies or -1 if the type is resolved as a namespace + private int iResolverVersion; // Number of loaded assemblies or -1 if the type is resolved as a namespace - private Dictionary index = null; // Index to speed up the search in big namespaces + private Dictionary index = null; // Index to speed up the search in big namespaces private List extensionMethods = null; // Liste with extension methods - #region -- Ctor/GetMetaObject ----------------------------------------------------- + #region -- Ctor/GetMetaObject ----------------------------------------------------- - private LuaType() - { - this.parent = null; + private LuaType() + { + this.parent = null; this.SetType(null, false); this.baseType = null; - this.sName = null; + this.sName = null; this.iResolverVersion = -2; - } // ctor + } // ctor - private LuaType(LuaType parent, string sName, Type type) - { - if (type == null) - throw new ArgumentNullException(); + private LuaType(LuaType parent, string sName, Type type) + { + if (type == null) + throw new ArgumentNullException(); - this.parent = parent; + this.parent = parent; this.SetType(type, false); this.sName = sName; this.iResolverVersion = 0; - } // ctor + } // ctor - private LuaType(LuaType parent, string sName) - { - if (String.IsNullOrEmpty(sName)) - throw new ArgumentNullException(); + private LuaType(LuaType parent, string sName) + { + if (String.IsNullOrEmpty(sName)) + throw new ArgumentNullException(); - this.parent = parent; + this.parent = parent; this.SetType(null, false); this.sName = sName; this.iResolverVersion = 0; - } // ctor - - /// - /// - public override string ToString() - { - return FullName; - } // func ToString - - /// Gets the dynamic interface of a type - /// - /// - public DynamicMetaObject GetMetaObject(Expression parameter) - { - return new LuaTypeMetaObject(parameter, this); - } // func GetMetaObject - - #endregion - - #region -- ResolveType, GetFullName ----------------------------------------------- - - private void ResolveType() - { - if (parent != null && // the root has no type + } // ctor + + /// + /// + public override string ToString() + { + return FullName; + } // func ToString + + /// Gets the dynamic interface of a type + /// + /// + public DynamicMetaObject GetMetaObject(Expression parameter) + { + return new LuaTypeMetaObject(parameter, this); + } // func GetMetaObject + + #endregion + + #region -- ResolveType, GetFullName ----------------------------------------------- + + private void ResolveType() + { + if (parent != null && // the root has no type iResolverVersion >= 0) // Namespace, there is no type - { - string sTypeName = FullName; + { + string sTypeName = FullName; iResolverVersion = 1; @@ -527,7 +533,7 @@ private void ResolveType() iResolverVersion = typeResolver.Version; } } - } // func GetItemType + } // func GetItemType private bool SetType(Type type, bool lUpdateKnownTypes) { @@ -553,27 +559,27 @@ private bool SetType(Type type, bool lUpdateKnownTypes) } } // proc SetType - private void GetFullName(StringBuilder sb) - { - if (parent != null) - { - string sName = Name; - if (parent.parent == null) - sb.Append(sName); - else - { - parent.GetFullName(sb); - if (sName[0] != '`' && sName[0] != '[') // is generic type - if (parent.IsNamespace) - sb.Append('.'); - else - sb.Append('+'); - sb.Append(sName); - } - } - } // proc GetFullName - - #endregion + private void GetFullName(StringBuilder sb) + { + if (parent != null) + { + string sName = Name; + if (parent.parent == null) + sb.Append(sName); + else + { + parent.GetFullName(sb); + if (sName[0] != '`' && sName[0] != '[') // is generic type + if (parent.IsNamespace) + sb.Append('.'); + else + sb.Append('+'); + sb.Append(sName); + } + } + } // proc GetFullName + + #endregion #region -- Extensions ------------------------------------------------------------- @@ -639,46 +645,46 @@ private void CollectExtensions(ref List methods, Predicate buildType) - { - int iIndex = FindIndexByName(sName, lIgnoreCase); - - // Name not found, create a new one - if (iIndex == -1) - { - // Create the new object - if (buildType == null) - iIndex = AddType(new LuaType(this, sName)); - else - iIndex = AddType(new LuaType(this, sName, buildType())); - - // Update the local index - if (index == null) - index = new Dictionary(); - - index[sName] = iIndex; - } - - // No type for this level, but sub-items -> it is a namespace - if (iResolverVersion >= 0 && GetType(iIndex).Type != null && Type == null) - { - LuaType c = this; + { + int iIndex = FindIndexByName(sName, lIgnoreCase); + + // Name not found, create a new one + if (iIndex == -1) + { + // Create the new object + if (buildType == null) + iIndex = AddType(new LuaType(this, sName)); + else + iIndex = AddType(new LuaType(this, sName, buildType())); + + // Update the local index + if (index == null) + index = new Dictionary(); + + index[sName] = iIndex; + } + + // No type for this level, but sub-items -> it is a namespace + if (iResolverVersion >= 0 && GetType(iIndex).Type != null && Type == null) + { + LuaType c = this; while (c.parent != null && c.iResolverVersion >= 0) - { + { c.iResolverVersion = -1; - c = c.parent; - } - } - - return iIndex; - } // func GetIndex - - private int FindIndexByName(string sName, bool lIgnoreCase) - { - int iIndex = -1; - if (index != null) - { - if (!index.TryGetValue(sName, out iIndex)) - { + c = c.parent; + } + } + + return iIndex; + } // func GetIndex + + private int FindIndexByName(string sName, bool lIgnoreCase) + { + int iIndex = -1; + if (index != null) + { + if (!index.TryGetValue(sName, out iIndex)) + { if (lIgnoreCase) { foreach (var k in index) @@ -692,56 +698,56 @@ private int FindIndexByName(string sName, bool lIgnoreCase) } else iIndex = -1; - } - } - return iIndex; - } // func FindIndexByName - - /// Get the generic type - /// Generic type - /// Arguments for the generic type - /// Created type. - public LuaType GetGenericItem(Type typeGeneric, LuaType[] arguments) - { - Type[] genericParameters = new Type[arguments.Length]; - - // Build the typename - StringBuilder sb = new StringBuilder(); - sb.Append('`').Append(arguments.Length).Append('['); - for (int i = 0; i < arguments.Length; i++) - { - if (i > 0) - sb.Append(','); - - Type typeTmp = genericParameters[i] = arguments[i].Type; - if (typeTmp == null) - throw new LuaRuntimeException(String.Format(Properties.Resources.rsClrGenericNoType, i), null); - - sb.Append('[').Append(typeTmp.AssemblyQualifiedName).Append(']'); - } - sb.Append(']'); - - // try to find the typename - lock (this) - return GetType(GetIndex(sb.ToString(), false, () => typeGeneric.MakeGenericType(genericParameters))); - } // func GetGenericItem - - #endregion - - #region -- Properties ------------------------------------------------------------- - - /// Name of the LuaType - public string Name { get { return sName; } } - /// FullName of the Clr-Type - public string FullName - { - get - { - StringBuilder sb = new StringBuilder(); - GetFullName(sb); - return sb.ToString(); - } - } // func FullName + } + } + return iIndex; + } // func FindIndexByName + + /// Get the generic type + /// Generic type + /// Arguments for the generic type + /// Created type. + public LuaType GetGenericItem(Type typeGeneric, LuaType[] arguments) + { + Type[] genericParameters = new Type[arguments.Length]; + + // Build the typename + StringBuilder sb = new StringBuilder(); + sb.Append('`').Append(arguments.Length).Append('['); + for (int i = 0; i < arguments.Length; i++) + { + if (i > 0) + sb.Append(','); + + Type typeTmp = genericParameters[i] = arguments[i].Type; + if (typeTmp == null) + throw new LuaRuntimeException(String.Format(Properties.Resources.rsClrGenericNoType, i), null); + + sb.Append('[').Append(typeTmp.AssemblyQualifiedName).Append(']'); + } + sb.Append(']'); + + // try to find the typename + lock (this) + return GetType(GetIndex(sb.ToString(), false, () => typeGeneric.MakeGenericType(genericParameters))); + } // func GetGenericItem + + #endregion + + #region -- Properties ------------------------------------------------------------- + + /// Name of the LuaType + public string Name { get { return sName; } } + /// FullName of the Clr-Type + public string FullName + { + get + { + StringBuilder sb = new StringBuilder(); + GetFullName(sb); + return sb.ToString(); + } + } // func FullName /// Alias name public string AliasName { get { return sAliasName; } } @@ -751,30 +757,33 @@ public string AliasOrFullName get { return sAliasName ?? FullName; } } // prop AliasOrFullName - /// Type that is represented by the LuaType - public Type Type - { - get - { - lock (this) - { - if (type == null) // no type found - ResolveType(); - return type; - } - } - } // prop Type - - /// Is the LuaType only a namespace at the time. + /// Type that is represented by the LuaType + public Type Type + { + get + { + lock (this) + { + if (type == null) // no type found + ResolveType(); + return type; + } + } + } // prop Type + + /// Is the LuaType only a namespace at the time. public bool IsNamespace { get { return iResolverVersion == -1 || type == null && iResolverVersion >= 0; } } - #endregion + /// Parent type + public LuaType Parent { get { return parent; } } + + #endregion - // -- Static -------------------------------------------------------------- + // -- Static -------------------------------------------------------------- - private static LuaType clr = new LuaType(); // root type - private static List types = new List(); // SubItems of this type - private static Dictionary knownTypes = new Dictionary(); // index for well known types + private static LuaType clr = new LuaType(); // root type + private static List types = new List(); // SubItems of this type + private static Dictionary knownTypes = new Dictionary(); // index for well known types private static ILuaTypeResolver typeResolver; static LuaType() @@ -823,154 +832,154 @@ static LuaType() piLookupReferencedAssemblies.SetValue(null, true); } // /sctor - #region -- Operator --------------------------------------------------------------- - - /// implicit convert to type - /// lua-type that should convert. - /// clr-type - public static implicit operator Type(LuaType type) - { - return type == null ? null : type.Type; - } // implicit to type - - #endregion - - #region -- AddType ---------------------------------------------------------------- - - private static int AddType(LuaType type) - { - int iIndex; - lock (types) - { - // add the type - iIndex = types.Count; - types.Add(type); - } - - // update type cache - if (type.Type != null) - lock (knownTypes) - knownTypes[type.FullName] = iIndex; - - return iIndex; - } // proc Add - - private static int GetTypeIndex(LuaType type) - { - lock (types) - { - int iReturn = types.IndexOf(type); + #region -- Operator --------------------------------------------------------------- + + /// implicit convert to type + /// lua-type that should convert. + /// clr-type + public static implicit operator Type(LuaType type) + { + return type == null ? null : type.Type; + } // implicit to type + + #endregion + + #region -- AddType ---------------------------------------------------------------- + + private static int AddType(LuaType type) + { + int iIndex; + lock (types) + { + // add the type + iIndex = types.Count; + types.Add(type); + } + + // update type cache + if (type.Type != null) + lock (knownTypes) + knownTypes[type.FullName] = iIndex; + + return iIndex; + } // proc Add + + private static int GetTypeIndex(LuaType type) + { + lock (types) + { + int iReturn = types.IndexOf(type); #if DEBUG - if (iReturn == -1) - throw new InvalidOperationException(); + if (iReturn == -1) + throw new InvalidOperationException(); #endif - return iReturn; - } - } // func - - #endregion - - #region -- GetType ---------------------------------------------------------------- - - internal static LuaType GetType(int iIndex) - { - lock (types) - return types[iIndex]; - } // func GetType - - private static LuaType GetType(LuaType current, int iOffset, string sFullName, bool lIgnoreCase, Type type) - { - string sCurrentName; - - // search for the offset - int iNextOffset; - if (iOffset > 0 && sFullName[iOffset - 1] == '`') // parse namespace - { - int iBracketCount = 0; - iNextOffset = iOffset; - iOffset--; - - // search for the first [ - while (iNextOffset < sFullName.Length && sFullName[iNextOffset] != '[') - iNextOffset++; - while (iNextOffset < sFullName.Length) - { - if (sFullName[iNextOffset] == '[') - iBracketCount++; - else if (sFullName[iNextOffset] == ']') - { - iBracketCount--; - if (iBracketCount == 0) - { - iNextOffset++; - break; - } - } - iNextOffset++; - } - - if (iNextOffset == sFullName.Length) - iNextOffset = -1; - } - else - iNextOffset = sFullName.IndexOfAny(new char[] { '.', '+', '`' }, iOffset); - - // Cut out the current name - if (iNextOffset == -1) - sCurrentName = sFullName.Substring(iOffset); - else - { - sCurrentName = sFullName.Substring(iOffset, iNextOffset - iOffset); - iNextOffset++; - } - - // try to find the name in the current namespace - int iIndex = current.GetIndex(sCurrentName, lIgnoreCase, type == null || iNextOffset > 0 ? (Func)null : () => type); - - // end of the type change found - if (iNextOffset == -1) - return GetType(iIndex); - else - return GetType(GetType(iIndex), iNextOffset, sFullName, lIgnoreCase, type); - } // func GetType - - /// Creates or looks up the LuaType for a clr-type. - /// clr-type, that should wrap. - /// Wrapped Type - public static LuaType GetType(Type type) - { - string sFullName = type.FullName; - lock (knownTypes) - { - int iIndex; - if (knownTypes.TryGetValue(sFullName, out iIndex)) - return GetType(iIndex); - } - return GetType(clr, 0, sFullName, false, type); - } // func GetType - - /// Creates or looks up the LuaType for a clr-type. - /// Full path to the type (clr-name). - /// - /// Must the type exist or it is possible to bound the type later. - /// Wrapped Type, is lLate is false also null is possible. - public static LuaType GetType(string sTypeName, bool lIgnoreCase = false, bool lLateAllowed = true) - { + return iReturn; + } + } // func + + #endregion + + #region -- GetType ---------------------------------------------------------------- + + internal static LuaType GetType(int iIndex) + { + lock (types) + return types[iIndex]; + } // func GetType + + private static LuaType GetType(LuaType current, int iOffset, string sFullName, bool lIgnoreCase, Type type) + { + string sCurrentName; + + // search for the offset + int iNextOffset; + if (iOffset > 0 && sFullName[iOffset - 1] == '`') // parse namespace + { + int iBracketCount = 0; + iNextOffset = iOffset; + iOffset--; + + // search for the first [ + while (iNextOffset < sFullName.Length && sFullName[iNextOffset] != '[') + iNextOffset++; + while (iNextOffset < sFullName.Length) + { + if (sFullName[iNextOffset] == '[') + iBracketCount++; + else if (sFullName[iNextOffset] == ']') + { + iBracketCount--; + if (iBracketCount == 0) + { + iNextOffset++; + break; + } + } + iNextOffset++; + } + + if (iNextOffset == sFullName.Length) + iNextOffset = -1; + } + else + iNextOffset = sFullName.IndexOfAny(new char[] { '.', '+', '`' }, iOffset); + + // Cut out the current name + if (iNextOffset == -1) + sCurrentName = sFullName.Substring(iOffset); + else + { + sCurrentName = sFullName.Substring(iOffset, iNextOffset - iOffset); + iNextOffset++; + } + + // try to find the name in the current namespace + int iIndex = current.GetIndex(sCurrentName, lIgnoreCase, type == null || iNextOffset > 0 ? (Func)null : () => type); + + // end of the type change found + if (iNextOffset == -1) + return GetType(iIndex); + else + return GetType(GetType(iIndex), iNextOffset, sFullName, lIgnoreCase, type); + } // func GetType + + /// Creates or looks up the LuaType for a clr-type. + /// clr-type, that should wrap. + /// Wrapped Type + public static LuaType GetType(Type type) + { + string sFullName = type.FullName; + lock (knownTypes) + { + int iIndex; + if (knownTypes.TryGetValue(sFullName, out iIndex)) + return GetType(iIndex); + } + return GetType(clr, 0, sFullName, false, type); + } // func GetType + + /// Creates or looks up the LuaType for a clr-type. + /// Full path to the type (clr-name). + /// + /// Must the type exist or it is possible to bound the type later. + /// Wrapped Type, is lLate is false also null is possible. + public static LuaType GetType(string sTypeName, bool lIgnoreCase = false, bool lLateAllowed = true) + { // search the tyle in the cache LuaType luaType = GetCachedType(sTypeName); - // create the lua type - if (luaType == null) - luaType = GetType(clr, 0, sTypeName, lIgnoreCase, Type.GetType(sTypeName, false)); + // create the lua type + if (luaType == null) + luaType = GetType(clr, 0, sTypeName, lIgnoreCase, Type.GetType(sTypeName, false)); - // Test the result - if (lLateAllowed) - return luaType; - else if (luaType.Type != null) - return luaType; - else - return null; - } // func GetType + // Test the result + if (lLateAllowed) + return luaType; + else if (luaType.Type != null) + return luaType; + else + return null; + } // func GetType /// Lookup for a well known type. /// Name of the type @@ -1047,123 +1056,123 @@ public static void RegisterMethodExtension(MethodInfo mi) throw new ArgumentException(String.Format(Properties.Resources.rsTypeExtentionInvalidMethod, mi.DeclaringType.Name, mi.Name)); } // proc RegisterMethodExtension - #endregion + #endregion - internal static Expression ConvertToLuaType(DynamicMetaObject a) - { - if (a.LimitType == typeof(LuaType)) - return Expression.Convert(a.Expression, typeof(LuaType)); + internal static Expression ConvertToLuaType(DynamicMetaObject a) + { + if (a.LimitType == typeof(LuaType)) + return Expression.Convert(a.Expression, typeof(LuaType)); else if (typeof(Type).GetTypeInfo().IsAssignableFrom(a.LimitType.GetTypeInfo())) - return Expression.Convert(Expression.Call(Lua.TypeGetTypeMethodInfoArgType, Expression.Convert(a.Expression, typeof(Type))), typeof(object)); - else - throw new ArgumentException(); - } // func ConvertToLuaType - - internal static Expression ConvertToType(DynamicMetaObject a) - { - if (a.LimitType == typeof(LuaType)) - return Expression.Convert(Expression.Property(Expression.Convert(a.Expression, typeof(LuaType)), Lua.TypeTypePropertyInfo), typeof(Type)); + return Expression.Convert(Expression.Call(Lua.TypeGetTypeMethodInfoArgType, Expression.Convert(a.Expression, typeof(Type))), typeof(object)); + else + throw new ArgumentException(); + } // func ConvertToLuaType + + internal static Expression ConvertToType(DynamicMetaObject a) + { + if (a.LimitType == typeof(LuaType)) + return Expression.Convert(Expression.Property(Expression.Convert(a.Expression, typeof(LuaType)), Lua.TypeTypePropertyInfo), typeof(Type)); else if (typeof(Type).GetTypeInfo().IsAssignableFrom(a.LimitType.GetTypeInfo())) - return Expression.Convert(a.Expression, typeof(Type)); - else - throw new ArgumentException(); - } // func ConvertToLuaType + return Expression.Convert(a.Expression, typeof(Type)); + else + throw new ArgumentException(); + } // func ConvertToLuaType - /// Root for all clr-types. - public static LuaType Clr { get { return clr; } } + /// Root for all clr-types. + public static LuaType Clr { get { return clr; } } /// Resolver for types. public static ILuaTypeResolver Resolver { get { return typeResolver; } set { typeResolver = value; } } - } // class LuaType - - #endregion - - #region -- interface ILuaMethod ----------------------------------------------------- - - /////////////////////////////////////////////////////////////////////////////// - /// - public interface ILuaMethod - { - /// Name of the member. - string Name { get; } - /// Type that is the owner of the member list - Type Type { get; } - /// Instance, that belongs to the member. - object Instance { get; } - } // interface ILuaMethod - - #endregion - - #region -- class LuaMethod ---------------------------------------------------------- - - /////////////////////////////////////////////////////////////////////////////// - /// Represents overloaded members. - public sealed class LuaMethod : ILuaMethod, IDynamicMetaObjectProvider - { - #region -- class LuaMethodMetaObject ---------------------------------------------- - - /////////////////////////////////////////////////////////////////////////////// - /// - private class LuaMethodMetaObject : DynamicMetaObject - { - public LuaMethodMetaObject(Expression expression, LuaMethod value) - : base(expression, BindingRestrictions.Empty, value) - { - } // ctor - - public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) - { - LuaMethod val = (LuaMethod)Value; - return LuaMethod.BindInvoke(Lua.GetRuntime(binder), Expression, val, val.method, args, binder.ReturnType); - } // proc BindInvoke - - public override DynamicMetaObject BindConvert(ConvertBinder binder) - { + } // class LuaType + + #endregion + + #region -- interface ILuaMethod ----------------------------------------------------- + + /////////////////////////////////////////////////////////////////////////////// + /// + public interface ILuaMethod + { + /// Name of the member. + string Name { get; } + /// Type that is the owner of the member list + Type Type { get; } + /// Instance, that belongs to the member. + object Instance { get; } + } // interface ILuaMethod + + #endregion + + #region -- class LuaMethod ---------------------------------------------------------- + + /////////////////////////////////////////////////////////////////////////////// + /// Represents overloaded members. + public sealed class LuaMethod : ILuaMethod, IDynamicMetaObjectProvider + { + #region -- class LuaMethodMetaObject ---------------------------------------------- + + /////////////////////////////////////////////////////////////////////////////// + /// + private class LuaMethodMetaObject : DynamicMetaObject + { + public LuaMethodMetaObject(Expression expression, LuaMethod value) + : base(expression, BindingRestrictions.Empty, value) + { + } // ctor + + public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) + { + LuaMethod val = (LuaMethod)Value; + return LuaMethod.BindInvoke(Lua.GetRuntime(binder), Expression, val, val.method, args, binder.ReturnType); + } // proc BindInvoke + + public override DynamicMetaObject BindConvert(ConvertBinder binder) + { if (typeof(Delegate).GetTypeInfo().IsAssignableFrom(binder.Type.GetTypeInfo())) // we expect a delegate - { - LuaMethod val = (LuaMethod)Value; - return CreateDelegate(Expression, val, binder.Type, val.method, binder.ReturnType); - } + { + LuaMethod val = (LuaMethod)Value; + return CreateDelegate(Expression, val, binder.Type, val.method, binder.ReturnType); + } else if (typeof(MethodInfo).GetTypeInfo().IsAssignableFrom(binder.Type.GetTypeInfo())) - { - return new DynamicMetaObject( - Expression.Property(Lua.EnsureType(Expression, typeof(LuaMethod)), Lua.MethodMethodPropertyInfo), - BindingRestrictions.GetTypeRestriction(Expression, typeof(LuaMethod)) - ); - } + { + return new DynamicMetaObject( + Expression.Property(Lua.EnsureType(Expression, typeof(LuaMethod)), Lua.MethodMethodPropertyInfo), + BindingRestrictions.GetTypeRestriction(Expression, typeof(LuaMethod)) + ); + } else if (typeof(Type).GetTypeInfo().IsAssignableFrom(binder.Type.GetTypeInfo())) - { - return ConvertToType(Expression, binder.ReturnType); - } - else - return base.BindConvert(binder); - } // func BindConvert - } // class LuaMethodMetaObject + { + return ConvertToType(Expression, binder.ReturnType); + } + else + return base.BindConvert(binder); + } // func BindConvert + } // class LuaMethodMetaObject - #endregion + #endregion - private readonly object instance; - private readonly MethodInfo method; + private readonly object instance; + private readonly MethodInfo method; - #region -- Ctor/Dtor -------------------------------------------------------------- + #region -- Ctor/Dtor -------------------------------------------------------------- - internal LuaMethod(object instance, MethodInfo method) - { - this.instance = instance; - this.method = method; + internal LuaMethod(object instance, MethodInfo method) + { + this.instance = instance; + this.method = method; - if (method == null) - throw new ArgumentNullException(); - } // ctor + if (method == null) + throw new ArgumentNullException(); + } // ctor - /// - /// - /// - public DynamicMetaObject GetMetaObject(Expression parameter) - { - return new LuaMethodMetaObject(parameter, this); - } // func GetMetaObject + /// + /// + /// + public DynamicMetaObject GetMetaObject(Expression parameter) + { + return new LuaMethodMetaObject(parameter, this); + } // func GetMetaObject - #endregion + #endregion /// /// @@ -1172,57 +1181,57 @@ public override string ToString() return method.ToString(); } // func ToString - /// Creates a delegate from the method - /// - /// - public Delegate CreateDelegate(Type typeDelegate) - { + /// Creates a delegate from the method + /// + /// + public Delegate CreateDelegate(Type typeDelegate) + { return method.CreateDelegate(typeDelegate, instance); - } // func CreateDelegate - - /// Name of the member. - public string Name { get { return method.Name; } } - /// Type that is the owner of the member list - public Type Type { get { return method.DeclaringType; } } - /// Instance, that belongs to the member. - public object Instance { get { return instance; } } - /// Access to the method. - public MethodInfo Method { get { return method; } } - /// Delegate of the Method - public Delegate Delegate { get { return Parser.CreateDelegate(instance, Method); } } - - // -- Static -------------------------------------------------------------- - - internal static DynamicMetaObject BindInvoke(Lua runtime, Expression methodExpression, ILuaMethod methodValue, MethodInfo mi, DynamicMetaObject[] args, Type typeReturn) - { - // create the call expression - Expression expr = Lua.EnsureType(LuaEmit.BindParameter(runtime, - a => Expression.Call(mi.IsStatic ? null : GetInstance(methodExpression, methodValue, methodValue.Type), mi, a), - mi.GetParameters(), - args, - mo => mo.Expression, mo => mo.LimitType, true), typeReturn, true); - - return new DynamicMetaObject(expr, BindInvokeRestrictions(methodExpression, methodValue).Merge(Lua.GetMethodSignatureRestriction(null, args))); - } // func BindInvoke - - private static Expression GetInstance(Expression methodExpression, ILuaMethod methodValue, Type returnType) - { - return Lua.EnsureType(Expression.Property(Lua.EnsureType(methodExpression, typeof(ILuaMethod)), Lua.MethodInstancePropertyInfo), returnType); - } //func GetInstance - - internal static DynamicMetaObject CreateDelegate(Expression methodExpression, ILuaMethod methodValue, Type typeDelegate, MethodInfo miTarget, Type typeReturn) - { - if (typeDelegate.GetTypeInfo().BaseType != typeof(MulticastDelegate)) - { - ParameterInfo[] pis = miTarget.GetParameters(); - Type[] parameters = new Type[pis.Length + 1]; - for (int i = 0; i < parameters.Length - 1; i++) - parameters[i] = pis[i].ParameterType; - parameters[parameters.Length - 1] = miTarget.ReturnType; - - typeDelegate = Expression.GetDelegateType(parameters); - } - + } // func CreateDelegate + + /// Name of the member. + public string Name { get { return method.Name; } } + /// Type that is the owner of the member list + public Type Type { get { return method.DeclaringType; } } + /// Instance, that belongs to the member. + public object Instance { get { return instance; } } + /// Access to the method. + public MethodInfo Method { get { return method; } } + /// Delegate of the Method + public Delegate Delegate { get { return Parser.CreateDelegate(instance, Method); } } + + // -- Static -------------------------------------------------------------- + + internal static DynamicMetaObject BindInvoke(Lua runtime, Expression methodExpression, ILuaMethod methodValue, MethodInfo mi, DynamicMetaObject[] args, Type typeReturn) + { + // create the call expression + Expression expr = Lua.EnsureType(LuaEmit.BindParameter(runtime, + a => Expression.Call(mi.IsStatic ? null : GetInstance(methodExpression, methodValue, methodValue.Type), mi, a), + mi.GetParameters(), + args, + mo => mo.Expression, mo => mo.LimitType, true), typeReturn, true); + + return new DynamicMetaObject(expr, BindInvokeRestrictions(methodExpression, methodValue).Merge(Lua.GetMethodSignatureRestriction(null, args))); + } // func BindInvoke + + private static Expression GetInstance(Expression methodExpression, ILuaMethod methodValue, Type returnType) + { + return Lua.EnsureType(Expression.Property(Lua.EnsureType(methodExpression, typeof(ILuaMethod)), Lua.MethodInstancePropertyInfo), returnType); + } //func GetInstance + + internal static DynamicMetaObject CreateDelegate(Expression methodExpression, ILuaMethod methodValue, Type typeDelegate, MethodInfo miTarget, Type typeReturn) + { + if (typeDelegate.GetTypeInfo().BaseType != typeof(MulticastDelegate)) + { + ParameterInfo[] pis = miTarget.GetParameters(); + Type[] parameters = new Type[pis.Length + 1]; + for (int i = 0; i < parameters.Length - 1; i++) + parameters[i] = pis[i].ParameterType; + parameters[parameters.Length - 1] = miTarget.ReturnType; + + typeDelegate = Expression.GetDelegateType(parameters); + } + return new DynamicMetaObject( Lua.EnsureType( Expression.Call( @@ -1234,227 +1243,227 @@ internal static DynamicMetaObject CreateDelegate(Expression methodExpression, IL ), BindInvokeRestrictions(methodExpression, methodValue) ); - } // func CreateDelegate - - internal static BindingRestrictions BindInvokeRestrictions(Expression methodExpression, ILuaMethod methodValue) - { - // create the restrictions - // expr is typeof(ILuaMethod) && expr.Type == type && !args! - return BindingRestrictions.GetExpressionRestriction( - Expression.AndAlso( - Expression.TypeIs(methodExpression, typeof(ILuaMethod)), - Expression.AndAlso( - Expression.Equal( - Expression.Property(Expression.Convert(methodExpression, typeof(ILuaMethod)), Lua.MethodTypePropertyInfo), - Expression.Constant(methodValue.Type) - ), - Expression.Equal( - Expression.Property(Expression.Convert(methodExpression, typeof(ILuaMethod)), Lua.MethodNamePropertyInfo), - Expression.Constant(methodValue.Name) - ) - ) - ) - ); - } // func BindInvokeRestrictions - - internal static DynamicMetaObject ConvertToType(Expression methodExpression, Type typeReturn) - { - return new DynamicMetaObject( - Lua.EnsureType(Expression.Property(Expression.Convert(methodExpression, typeof(ILuaMethod)), Lua.MethodTypePropertyInfo), typeReturn), - BindingRestrictions.GetTypeRestriction(methodExpression, typeof(ILuaMethod)) - ); - } // func ConvertToType - } // class LuaMethod - - #endregion - - #region -- class LuaOverloadedMethod ------------------------------------------------ - - /////////////////////////////////////////////////////////////////////////////// - /// Represents overloaded members. - public sealed class LuaOverloadedMethod : ILuaMethod, IDynamicMetaObjectProvider, IEnumerable - { - #region -- class LuaOverloadedMethodMetaObject ------------------------------------ - - /////////////////////////////////////////////////////////////////////////////// - /// - private class LuaOverloadedMethodMetaObject : DynamicMetaObject - { - public LuaOverloadedMethodMetaObject(Expression expression, LuaOverloadedMethod value) - : base(expression, BindingRestrictions.GetTypeRestriction(expression, typeof(LuaOverloadedMethod)), value) - { - } // ctor - - public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes) - { - LuaOverloadedMethod val = (LuaOverloadedMethod)Value; - - if (indexes.Any(c => !c.HasValue)) - return binder.Defer(indexes); - - // Access the normal index - if (indexes.Length == 1 && indexes[0].LimitType == typeof(int)) - return binder.FallbackGetIndex(this, indexes); - - // check, only types are allowed - if (indexes.Any(c => c.LimitType != typeof(LuaType) && !typeof(Type).GetTypeInfo().IsAssignableFrom(c.LimitType.GetTypeInfo()))) - { - return new DynamicMetaObject( - Lua.ThrowExpression(String.Format(Properties.Resources.rsClrGenericTypeExpected)), - Lua.GetMethodSignatureRestriction(this, indexes) - ); - } - - return new DynamicMetaObject( - Expression.Call( - Lua.EnsureType(Expression, typeof(LuaOverloadedMethod)), - Lua.OverloadedMethodGetMethodMethodInfo, - Expression.Constant(false), - Expression.NewArrayInit(typeof(Type), (from a in indexes select LuaType.ConvertToType(a)).AsEnumerable()) - ), - Lua.GetMethodSignatureRestriction(this, indexes) - ); - } // func BindGetIndex - - public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) - { - LuaOverloadedMethod val = (LuaOverloadedMethod)Value; + } // func CreateDelegate + + internal static BindingRestrictions BindInvokeRestrictions(Expression methodExpression, ILuaMethod methodValue) + { + // create the restrictions + // expr is typeof(ILuaMethod) && expr.Type == type && !args! + return BindingRestrictions.GetExpressionRestriction( + Expression.AndAlso( + Expression.TypeIs(methodExpression, typeof(ILuaMethod)), + Expression.AndAlso( + Expression.Equal( + Expression.Property(Expression.Convert(methodExpression, typeof(ILuaMethod)), Lua.MethodTypePropertyInfo), + Expression.Constant(methodValue.Type) + ), + Expression.Equal( + Expression.Property(Expression.Convert(methodExpression, typeof(ILuaMethod)), Lua.MethodNamePropertyInfo), + Expression.Constant(methodValue.Name) + ) + ) + ) + ); + } // func BindInvokeRestrictions + + internal static DynamicMetaObject ConvertToType(Expression methodExpression, Type typeReturn) + { + return new DynamicMetaObject( + Lua.EnsureType(Expression.Property(Expression.Convert(methodExpression, typeof(ILuaMethod)), Lua.MethodTypePropertyInfo), typeReturn), + BindingRestrictions.GetTypeRestriction(methodExpression, typeof(ILuaMethod)) + ); + } // func ConvertToType + } // class LuaMethod + + #endregion + + #region -- class LuaOverloadedMethod ------------------------------------------------ + + /////////////////////////////////////////////////////////////////////////////// + /// Represents overloaded members. + public sealed class LuaOverloadedMethod : ILuaMethod, IDynamicMetaObjectProvider, IEnumerable + { + #region -- class LuaOverloadedMethodMetaObject ------------------------------------ + + /////////////////////////////////////////////////////////////////////////////// + /// + private class LuaOverloadedMethodMetaObject : DynamicMetaObject + { + public LuaOverloadedMethodMetaObject(Expression expression, LuaOverloadedMethod value) + : base(expression, BindingRestrictions.GetTypeRestriction(expression, typeof(LuaOverloadedMethod)), value) + { + } // ctor + + public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes) + { + LuaOverloadedMethod val = (LuaOverloadedMethod)Value; + + if (indexes.Any(c => !c.HasValue)) + return binder.Defer(indexes); + + // Access the normal index + if (indexes.Length == 1 && indexes[0].LimitType == typeof(int)) + return binder.FallbackGetIndex(this, indexes); + + // check, only types are allowed + if (indexes.Any(c => c.LimitType != typeof(LuaType) && !typeof(Type).GetTypeInfo().IsAssignableFrom(c.LimitType.GetTypeInfo()))) + { + return new DynamicMetaObject( + Lua.ThrowExpression(String.Format(Properties.Resources.rsClrGenericTypeExpected)), + Lua.GetMethodSignatureRestriction(this, indexes) + ); + } + + return new DynamicMetaObject( + Expression.Call( + Lua.EnsureType(Expression, typeof(LuaOverloadedMethod)), + Lua.OverloadedMethodGetMethodMethodInfo, + Expression.Constant(false), + Expression.NewArrayInit(typeof(Type), (from a in indexes select LuaType.ConvertToType(a)).AsEnumerable()) + ), + Lua.GetMethodSignatureRestriction(this, indexes) + ); + } // func BindGetIndex + + public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) + { + LuaOverloadedMethod val = (LuaOverloadedMethod)Value; MethodInfo mi = LuaEmit.FindMethod(val.methods, args, mo => mo.LimitType, false); - if (mi == null) - return new DynamicMetaObject( - Lua.ThrowExpression(String.Format(Properties.Resources.rsMemberNotResolved, val.Type, val.Name)), - LuaMethod.BindInvokeRestrictions(Expression, val).Merge(Lua.GetMethodSignatureRestriction(null, args)) - ); - else - return LuaMethod.BindInvoke(Lua.GetRuntime(binder), Expression, val, mi, args, binder.ReturnType); - } // proc BindInvoke - - public override DynamicMetaObject BindConvert(ConvertBinder binder) - { - if (typeof(Delegate).GetTypeInfo().IsAssignableFrom(binder.Type.GetTypeInfo())) - { - // get the parameters from the invoke method + if (mi == null) + return new DynamicMetaObject( + Lua.ThrowExpression(String.Format(Properties.Resources.rsMemberNotResolved, val.Type, val.Name)), + LuaMethod.BindInvokeRestrictions(Expression, val).Merge(Lua.GetMethodSignatureRestriction(null, args)) + ); + else + return LuaMethod.BindInvoke(Lua.GetRuntime(binder), Expression, val, mi, args, binder.ReturnType); + } // proc BindInvoke + + public override DynamicMetaObject BindConvert(ConvertBinder binder) + { + if (typeof(Delegate).GetTypeInfo().IsAssignableFrom(binder.Type.GetTypeInfo())) + { + // get the parameters from the invoke method MethodInfo miInvoke = binder.Type.GetRuntimeMethods().Where(c => c.IsPublic && !c.IsStatic && c.Name == "Invoke").FirstOrDefault(); - if (miInvoke == null) - return base.BindConvert(binder); - else - { - LuaOverloadedMethod val = (LuaOverloadedMethod)Value; + if (miInvoke == null) + return base.BindConvert(binder); + else + { + LuaOverloadedMethod val = (LuaOverloadedMethod)Value; MethodInfo miTarget = LuaEmit.FindMethod(val.methods, miInvoke.GetParameters(), p => p.ParameterType, false); - return LuaMethod.CreateDelegate(Expression, val, binder.Type, miTarget, binder.ReturnType); - } - } + return LuaMethod.CreateDelegate(Expression, val, binder.Type, miTarget, binder.ReturnType); + } + } else if (typeof(Type).GetTypeInfo().IsAssignableFrom(binder.Type.GetTypeInfo())) - return LuaMethod.ConvertToType(Expression, binder.ReturnType); - else - return base.BindConvert(binder); - } // func BindConvert - } // class LuaOverloadedMethodMetaObject - - #endregion - - private readonly object instance; - private readonly MethodInfo[] methods; - - #region -- Ctor/Dtor -------------------------------------------------------------- - - internal LuaOverloadedMethod(object instance, MethodInfo[] methods) - { - this.instance = instance; - this.methods = methods; - - if (methods.Length == 0) - throw new ArgumentOutOfRangeException(); - } // ctor - - /// - /// - /// - public DynamicMetaObject GetMetaObject(Expression parameter) - { - return new LuaOverloadedMethodMetaObject(parameter, this); - } // func GetMetaObject - - #endregion - - #region -- GetDelegate, GetMethod ------------------------------------------------- - - private MethodInfo FindMethod(bool lExact, params Type[] types) - { - for (int i = 0; i < methods.Length; i++) - { - ParameterInfo[] parameters = methods[i].GetParameters(); - if (parameters.Length == types.Length) - { - bool lMatch = false; - - for (int j = 0; j < parameters.Length; j++) - { - bool lOutExact; - if (LuaEmit.TypesMatch(parameters[j].ParameterType, types[j], out lOutExact) && (!lExact || lOutExact)) - { - lMatch = true; - break; - } - } - - if (lMatch || types.Length == 0) - return methods[i]; - } - } - return null; - } // func FindMethod - - /// Finds the delegate from the signature. - /// true type must match exact. false, the types only should assignable. - /// Types - /// - public Delegate GetDelegate(bool lExact, params Type[] types) - { - MethodInfo mi = FindMethod(lExact, types); - return mi == null ? null : Parser.CreateDelegate(instance, mi); - } // func GetDelegate - - /// Gets the delegate from the index - /// Index - /// - public Delegate GetDelegate(int iIndex) - { - return iIndex >= 0 && iIndex < methods.Length ? Parser.CreateDelegate(instance, methods[iIndex]) : null; - } // func GetDelegate - - /// Finds the method from the signature - /// true type must match exact. false, the types only should assignable. - /// - /// - public LuaMethod GetMethod(bool lExact, params Type[] types) - { - MethodInfo mi = FindMethod(true, types); - return mi == null ? null : new LuaMethod(instance, mi); - } // func GetMethod - - /// Gets the method from the index - /// Index - /// - public LuaMethod GetMethod(int iIndex) - { - return iIndex >= 0 && iIndex < methods.Length ? new LuaMethod(instance, methods[iIndex]) : null; - } // func GetMethod - - #endregion - - /// - /// - public IEnumerator GetEnumerator() - { - for (int i = 0; i < methods.Length; i++) - yield return Parser.CreateDelegate(instance, methods[i]); - } // func GetEnumerator - - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } // func System.Collections.IEnumerable.GetEnumerator + return LuaMethod.ConvertToType(Expression, binder.ReturnType); + else + return base.BindConvert(binder); + } // func BindConvert + } // class LuaOverloadedMethodMetaObject + + #endregion + + private readonly object instance; + private readonly MethodInfo[] methods; + + #region -- Ctor/Dtor -------------------------------------------------------------- + + internal LuaOverloadedMethod(object instance, MethodInfo[] methods) + { + this.instance = instance; + this.methods = methods; + + if (methods.Length == 0) + throw new ArgumentOutOfRangeException(); + } // ctor + + /// + /// + /// + public DynamicMetaObject GetMetaObject(Expression parameter) + { + return new LuaOverloadedMethodMetaObject(parameter, this); + } // func GetMetaObject + + #endregion + + #region -- GetDelegate, GetMethod ------------------------------------------------- + + private MethodInfo FindMethod(bool lExact, params Type[] types) + { + for (int i = 0; i < methods.Length; i++) + { + ParameterInfo[] parameters = methods[i].GetParameters(); + if (parameters.Length == types.Length) + { + bool lMatch = false; + + for (int j = 0; j < parameters.Length; j++) + { + bool lOutExact; + if (LuaEmit.TypesMatch(parameters[j].ParameterType, types[j], out lOutExact) && (!lExact || lOutExact)) + { + lMatch = true; + break; + } + } + + if (lMatch || types.Length == 0) + return methods[i]; + } + } + return null; + } // func FindMethod + + /// Finds the delegate from the signature. + /// true type must match exact. false, the types only should assignable. + /// Types + /// + public Delegate GetDelegate(bool lExact, params Type[] types) + { + MethodInfo mi = FindMethod(lExact, types); + return mi == null ? null : Parser.CreateDelegate(instance, mi); + } // func GetDelegate + + /// Gets the delegate from the index + /// Index + /// + public Delegate GetDelegate(int iIndex) + { + return iIndex >= 0 && iIndex < methods.Length ? Parser.CreateDelegate(instance, methods[iIndex]) : null; + } // func GetDelegate + + /// Finds the method from the signature + /// true type must match exact. false, the types only should assignable. + /// + /// + public LuaMethod GetMethod(bool lExact, params Type[] types) + { + MethodInfo mi = FindMethod(true, types); + return mi == null ? null : new LuaMethod(instance, mi); + } // func GetMethod + + /// Gets the method from the index + /// Index + /// + public LuaMethod GetMethod(int iIndex) + { + return iIndex >= 0 && iIndex < methods.Length ? new LuaMethod(instance, methods[iIndex]) : null; + } // func GetMethod + + #endregion + + /// + /// + public IEnumerator GetEnumerator() + { + for (int i = 0; i < methods.Length; i++) + yield return Parser.CreateDelegate(instance, methods[i]); + } // func GetEnumerator + + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } // func System.Collections.IEnumerable.GetEnumerator /// /// @@ -1463,149 +1472,149 @@ public override string ToString() return methods[0].DeclaringType.Name + "." + methods[0].Name + " overloaded"; } // func ToString - /// - /// - /// - public LuaMethod this[int iIndex] { get { return GetMethod(iIndex); } } - /// - /// - /// - public LuaMethod this[params Type[] types] { get { return GetMethod(true, types); } } - - /// Name of the member. - public string Name { get { return methods[0].Name; } } - /// Type that is the owner of the member list - public Type Type { get { return methods[0].DeclaringType; } } - /// Instance, that belongs to the member. - public object Instance { get { return instance; } } - /// Count of overloade members. - public int Count { get { return methods.Length; } } + /// + /// + /// + public LuaMethod this[int iIndex] { get { return GetMethod(iIndex); } } + /// + /// + /// + public LuaMethod this[params Type[] types] { get { return GetMethod(true, types); } } + + /// Name of the member. + public string Name { get { return methods[0].Name; } } + /// Type that is the owner of the member list + public Type Type { get { return methods[0].DeclaringType; } } + /// Instance, that belongs to the member. + public object Instance { get { return instance; } } + /// Count of overloade members. + public int Count { get { return methods.Length; } } } // class LuaOverloadedMethod - #endregion - - #region -- class LuaEvent ----------------------------------------------------------- - - /////////////////////////////////////////////////////////////////////////////// - /// - public sealed class LuaEvent : ILuaMethod, IDynamicMetaObjectProvider - { - #region -- class LuaEventMetaObject ----------------------------------------------- - - private class LuaEventMetaObject : DynamicMetaObject - { - private const string csAdd = "add"; - private const string csDel = "del"; - private const string csRemove = "remove"; - - public LuaEventMetaObject(Expression parameter, LuaEvent value) - : base(parameter, BindingRestrictions.Empty, value) - { - } // ctor - - #region -- BindAddMethod, BindRemoveMethod, BindGetMember ----------------------- - - private DynamicMetaObject BindAddMethod(DynamicMetaObjectBinder binder, DynamicMetaObject[] args) - { - LuaEvent value = (LuaEvent)Value; - return LuaMethod.BindInvoke(Lua.GetRuntime(binder), Expression, value, value.eventInfo.AddMethod, args, binder.ReturnType); - } // func BindAddMethod - - private DynamicMetaObject BindRemoveMethod(DynamicMetaObjectBinder binder, DynamicMetaObject[] args) - { - LuaEvent value = (LuaEvent)Value; - return LuaMethod.BindInvoke(Lua.GetRuntime(binder), Expression, value, value.eventInfo.RemoveMethod, args, binder.ReturnType); - } // func BindRemoveMethod - - private DynamicMetaObject BindGetMember(DynamicMetaObjectBinder binder, PropertyInfo piMethodGet) - { - LuaEvent value = (LuaEvent)Value; - return new DynamicMetaObject( - Lua.EnsureType( - Expression.New(Lua.MethodConstructorInfo, - Expression.Property(Lua.EnsureType(Expression, typeof(ILuaMethod)), Lua.MethodInstancePropertyInfo), - Expression.Property(Lua.EnsureType(Expression, typeof(LuaEvent)), piMethodGet) - ), - binder.ReturnType - ), - LuaMethod.BindInvokeRestrictions(Expression, value) - ); - } // func BindGetMember - - #endregion - - #region -- Binder --------------------------------------------------------------- - - public override DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg) - { - if (binder.Operation == ExpressionType.LeftShift) // << translate to add, not useable under lua - return BindAddMethod(binder, new DynamicMetaObject[] { arg }); - else if (binder.Operation == ExpressionType.RightShift) // >> translate to remove, not useable under lua - return BindRemoveMethod(binder, new DynamicMetaObject[] { arg }); - else - return base.BindBinaryOperation(binder, arg); - } // func BindBinaryOperation - - public override DynamicMetaObject BindGetMember(GetMemberBinder binder) - { + #endregion + + #region -- class LuaEvent ----------------------------------------------------------- + + /////////////////////////////////////////////////////////////////////////////// + /// + public sealed class LuaEvent : ILuaMethod, IDynamicMetaObjectProvider + { + #region -- class LuaEventMetaObject ----------------------------------------------- + + private class LuaEventMetaObject : DynamicMetaObject + { + private const string csAdd = "add"; + private const string csDel = "del"; + private const string csRemove = "remove"; + + public LuaEventMetaObject(Expression parameter, LuaEvent value) + : base(parameter, BindingRestrictions.Empty, value) + { + } // ctor + + #region -- BindAddMethod, BindRemoveMethod, BindGetMember ----------------------- + + private DynamicMetaObject BindAddMethod(DynamicMetaObjectBinder binder, DynamicMetaObject[] args) + { + LuaEvent value = (LuaEvent)Value; + return LuaMethod.BindInvoke(Lua.GetRuntime(binder), Expression, value, value.eventInfo.AddMethod, args, binder.ReturnType); + } // func BindAddMethod + + private DynamicMetaObject BindRemoveMethod(DynamicMetaObjectBinder binder, DynamicMetaObject[] args) + { + LuaEvent value = (LuaEvent)Value; + return LuaMethod.BindInvoke(Lua.GetRuntime(binder), Expression, value, value.eventInfo.RemoveMethod, args, binder.ReturnType); + } // func BindRemoveMethod + + private DynamicMetaObject BindGetMember(DynamicMetaObjectBinder binder, PropertyInfo piMethodGet) + { + LuaEvent value = (LuaEvent)Value; + return new DynamicMetaObject( + Lua.EnsureType( + Expression.New(Lua.MethodConstructorInfo, + Expression.Property(Lua.EnsureType(Expression, typeof(ILuaMethod)), Lua.MethodInstancePropertyInfo), + Expression.Property(Lua.EnsureType(Expression, typeof(LuaEvent)), piMethodGet) + ), + binder.ReturnType + ), + LuaMethod.BindInvokeRestrictions(Expression, value) + ); + } // func BindGetMember + + #endregion + + #region -- Binder --------------------------------------------------------------- + + public override DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg) + { + if (binder.Operation == ExpressionType.LeftShift) // << translate to add, not useable under lua + return BindAddMethod(binder, new DynamicMetaObject[] { arg }); + else if (binder.Operation == ExpressionType.RightShift) // >> translate to remove, not useable under lua + return BindRemoveMethod(binder, new DynamicMetaObject[] { arg }); + else + return base.BindBinaryOperation(binder, arg); + } // func BindBinaryOperation + + public override DynamicMetaObject BindGetMember(GetMemberBinder binder) + { var stringComparison = binder.IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; if (String.Compare(binder.Name, csAdd, stringComparison) == 0) - { - return BindGetMember(binder, Lua.AddMethodInfoPropertyInfo); - } + { + return BindGetMember(binder, Lua.AddMethodInfoPropertyInfo); + } else if (String.Compare(binder.Name, csDel, stringComparison) == 0 || String.Compare(binder.Name, csRemove, stringComparison) == 0) - { - return BindGetMember(binder, Lua.RemoveMethodInfoPropertyInfo); - } - else - return base.BindGetMember(binder); - } // func BindGetMember - - public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args) - { + { + return BindGetMember(binder, Lua.RemoveMethodInfoPropertyInfo); + } + else + return base.BindGetMember(binder); + } // func BindGetMember + + public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args) + { var stringComparison = binder.IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; if (String.Compare(binder.Name, csAdd, stringComparison) == 0) - { - return BindAddMethod(binder, args); - } + { + return BindAddMethod(binder, args); + } else if (String.Compare(binder.Name, csDel, stringComparison) == 0 || String.Compare(binder.Name, csRemove, stringComparison) == 0) - { - return BindRemoveMethod(binder, args); - } - else - return base.BindInvokeMember(binder, args); - } // func BindInvokeMember + { + return BindRemoveMethod(binder, args); + } + else + return base.BindInvokeMember(binder, args); + } // func BindInvokeMember - #endregion - } // class LuaEventMetaObject + #endregion + } // class LuaEventMetaObject - #endregion + #endregion - private readonly object instance; - private readonly EventInfo eventInfo; + private readonly object instance; + private readonly EventInfo eventInfo; - #region -- Ctor/Dtor -------------------------------------------------------------- + #region -- Ctor/Dtor -------------------------------------------------------------- - internal LuaEvent(object instance, EventInfo eventInfo) - { - this.instance = instance; - this.eventInfo = eventInfo; + internal LuaEvent(object instance, EventInfo eventInfo) + { + this.instance = instance; + this.eventInfo = eventInfo; - if (eventInfo == null) - throw new ArgumentNullException(); - } // ctor + if (eventInfo == null) + throw new ArgumentNullException(); + } // ctor - /// - /// - /// - public DynamicMetaObject GetMetaObject(Expression parameter) - { - return new LuaEventMetaObject(parameter, this); - } // func GetMetaObject + /// + /// + /// + public DynamicMetaObject GetMetaObject(Expression parameter) + { + return new LuaEventMetaObject(parameter, this); + } // func GetMetaObject - #endregion + #endregion /// /// @@ -1614,17 +1623,17 @@ public override string ToString() return "event: " + eventInfo.Name; } // func ToString - /// Name of the event. - public string Name { get { return eventInfo.Name; } } - /// Type that is the owner of the member list - public Type Type { get { return eventInfo.DeclaringType; } } - /// Instance, that belongs to the member. - public object Instance { get { return instance; } } + /// Name of the event. + public string Name { get { return eventInfo.Name; } } + /// Type that is the owner of the member list + public Type Type { get { return eventInfo.DeclaringType; } } + /// Instance, that belongs to the member. + public object Instance { get { return instance; } } - internal MethodInfo AddMethodInfo { get { return eventInfo.AddMethod; } } - internal MethodInfo RemoveMethodInfo { get { return eventInfo.RemoveMethod; } } - internal MethodInfo RaiseMethodInfo { get { return eventInfo.RaiseMethod; } } - } // class LuaEvent + internal MethodInfo AddMethodInfo { get { return eventInfo.AddMethod; } } + internal MethodInfo RemoveMethodInfo { get { return eventInfo.RemoveMethod; } } + internal MethodInfo RaiseMethodInfo { get { return eventInfo.RaiseMethod; } } + } // class LuaEvent - #endregion + #endregion }