示例#1
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        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);
            }
        }
示例#2
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        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);
            }
        }