//----------------------------------------------------------------------------------------------------------------------------------------------------- internal HappilProperty(HappilClass happilClass, PropertyInfo declaration) { m_HappilClass = happilClass; m_Declaration = declaration; m_PropertyBuilder = happilClass.TypeBuilder.DefineProperty( happilClass.TakeMemberName(declaration.Name), declaration.Attributes, declaration.PropertyType, declaration.GetIndexParameters().Select(p => p.ParameterType).ToArray()); var getterDeclaration = declaration.GetGetMethod(); if (getterDeclaration != null) { var closedGetterMethodType = typeof(HappilMethod <>).MakeGenericType(getterDeclaration.ReturnType); m_GetterMethod = (HappilMethod)Activator.CreateInstance(closedGetterMethodType, happilClass, getterDeclaration); m_PropertyBuilder.SetGetMethod(m_GetterMethod.MethodBuilder); } var setterDeclaration = declaration.GetSetMethod(); if (setterDeclaration != null) { m_SetterMethod = new VoidHappilMethod(happilClass, setterDeclaration); m_PropertyBuilder.SetSetMethod(m_SetterMethod.MethodBuilder); } }
//----------------------------------------------------------------------------------------------------------------------------------------------------- internal HappilField(HappilClass happilClass, string name, Type fieldType, bool isStatic = false) { m_HappilClass = happilClass; m_Name = happilClass.TakeMemberName(name); m_IsStatic = isStatic; var actualType = TypeTemplate.Resolve(fieldType); var attributes = (isStatic ? FieldAttributes.Private | FieldAttributes.Static : FieldAttributes.Private); m_FieldBuilder = happilClass.TypeBuilder.DefineField(m_Name, actualType, attributes); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public HappilMethod(HappilClass happilClass, string name, Type returnType, Type[] argumentTypes) : this(happilClass) { m_IsStatic = true; m_MethodBuilder = happilClass.TypeBuilder.DefineMethod( happilClass.TakeMemberName(name), MethodAttributes.Static | MethodAttributes.Private | MethodAttributes.HideBySig, returnType, argumentTypes); m_Declaration = m_MethodBuilder; m_ArgumentTypes = argumentTypes; m_ArgumentNames = CreateDefaultArgumentNames(argumentTypes); m_ArgumentIsOut = new bool[m_ArgumentTypes.Length]; // all false }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public HappilMethod(HappilClass happilClass, MethodInfo declaration, MethodAttributes methodAttributes) : this(happilClass) { m_IsStatic = false; m_Declaration = declaration; m_MethodBuilder = happilClass.TypeBuilder.DefineMethod( happilClass.TakeMemberName(declaration.Name), methodAttributes, declaration.ReturnType, declaration.GetParameters().Select(p => p.ParameterType).ToArray()); //if ( !declaration.IsSpecialName ) //{ happilClass.TypeBuilder.DefineMethodOverride(m_MethodBuilder, declaration); //} m_ArgumentTypes = declaration.GetParameters().Select(p => p.ParameterType).ToArray(); m_ArgumentNames = declaration.GetParameters().Select(p => p.Name).ToArray(); m_ArgumentIsOut = declaration.GetParameters().Select(p => p.IsOut).ToArray(); }