//----------------------------------------------------------------------------------------------------------------------------------------------------- private HappilField(HappilClass happilClass, string name, bool isStatic, FieldBuilder fieldBuilder) { m_HappilClass = happilClass; m_Name = name; m_IsStatic = isStatic; m_FieldBuilder = fieldBuilder; }
//----------------------------------------------------------------------------------------------------------------------------------------------------- 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 HappilConstructor(HappilClass happilClass, Type[] argumentTypes) : base(happilClass) { m_ArgumentTypes = argumentTypes; m_ArgumentNames = CreateDefaultArgumentNames(argumentTypes); m_ArgumentIsOut = new bool[argumentTypes.Length]; // all false m_ConstructorBuilder = happilClass.TypeBuilder.DefineConstructor( MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, CallingConventions.HasThis, argumentTypes); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private HappilConstructor(HappilClass happilClass) : base(happilClass) { m_ArgumentTypes = new Type[0]; m_ArgumentNames = new string[0]; m_ArgumentIsOut = new bool[0]; m_ConstructorBuilder = happilClass.TypeBuilder.DefineConstructor( MethodAttributes.Private | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName | MethodAttributes.HideBySig | MethodAttributes.Static, CallingConventions.Standard, m_ArgumentTypes); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public HappilClassBody(HappilClass happilClass) { m_HappilClass = happilClass; m_ReflectedType = TypeTemplate.Resolve(typeof(TBase)); var members = TypeMembers.Of(m_ReflectedType); m_ImplementableMembers = members.ImplementableMembers; m_ImplementableMethods = members.ImplementableMethods.Where(m => !m.IsSpecialName).ToArray(); m_ImplementableProperties = members.ImplementableProperties; m_ImplementableEvents = members.ImplementableEvents; }
//----------------------------------------------------------------------------------------------------------------------------------------------------- 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 }
//----------------------------------------------------------------------------------------------------------------------------------------------------- internal HappilEvent(HappilClass happilClass, EventInfo declaration) { m_HappilClass = happilClass; m_Declaration = declaration; m_EventBuilder = happilClass.TypeBuilder.DefineEvent(declaration.Name, declaration.Attributes, declaration.EventHandlerType); using (CreateTypeTemplateScope()) { m_BackingField = new HappilField(happilClass, "m_" + declaration.Name + "EventHandler", typeof(TypeTemplate.TEventHandler)); m_AddMethod = new VoidHappilMethod(happilClass, declaration.GetAddMethod(), ContainedMethodAttributes); m_EventBuilder.SetAddOnMethod(m_AddMethod.MethodBuilder); m_RemoveMethod = new VoidHappilMethod(happilClass, declaration.GetRemoveMethod(), ContainedMethodAttributes); m_EventBuilder.SetRemoveOnMethod(m_RemoveMethod.MethodBuilder); } }
//----------------------------------------------------------------------------------------------------------------------------------------------------- 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(); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- protected HappilMethod(HappilClass happilClass) { m_HappilClass = happilClass; m_Statements = new List <IHappilStatement>(); m_BodyDefinitions = new List <Action>(capacity: 16); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public HappilMethod(HappilClass happilClass, MethodInfo declaration) : this(happilClass, declaration, GetMethodAttributesFor(declaration)) { }
//------------------------------------------------------------------------------------------------------------------------------------------------- public VoidHappilMethod(HappilClass happilClass, MethodInfo declaration, MethodAttributes methodAttributes) : base(happilClass, declaration, methodAttributes) { }
public VoidHappilMethod(HappilClass happilClass, MethodInfo declaration) : base(happilClass, declaration) { }
//----------------------------------------------------------------------------------------------------------------------------------------------------- //TODO: remove this constructor (update unit tests) internal HappilField(string name, Type fieldType) { m_HappilClass = null; m_Name = name; }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public static HappilConstructor CreateStaticConstructor(HappilClass ownerClass) { return(new HappilConstructor(ownerClass)); }