Пример #1
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public PropertyMember(ClassType ownerClass, PropertyInfo declaration, FieldMember backingField = null)
            : base(ownerClass, declaration.Name)
        {
            m_Writers         = new List <PropertyWriterBase>();
            m_Declaration     = declaration;
            m_PropertyBuilder = ownerClass.TypeBuilder.DefineProperty(
                ownerClass.TakeMemberName(declaration.Name, mustUseThisName: true),
                declaration.Attributes,
                declaration.PropertyType,
                declaration.GetIndexParameters().Select(p => p.ParameterType).ToArray());

            var getterDeclaration = declaration.GetGetMethod();

            if (getterDeclaration != null)
            {
                m_GetterMethod = new MethodMember(ownerClass, new VirtualMethodFactory(ownerClass, getterDeclaration));
                m_PropertyBuilder.SetGetMethod((MethodBuilder)m_GetterMethod.MethodFactory.Builder);
            }

            var setterDeclaration = declaration.GetSetMethod();

            if (setterDeclaration != null)
            {
                m_SetterMethod = new MethodMember(ownerClass, new VirtualMethodFactory(ownerClass, setterDeclaration));
                m_PropertyBuilder.SetSetMethod((MethodBuilder)m_SetterMethod.MethodFactory.Builder);
            }

            m_BackingField = backingField;
        }
Пример #2
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public EventMember(ClassType ownerClass, EventInfo declaration)
            : base(ownerClass, declaration.Name)
        {
            m_Writers     = new List <EventWriterBase>();
            m_Declaration = declaration;
            m_UniqueName  = ownerClass.TakeMemberName(declaration.Name);

            m_EventBuilder = ownerClass.TypeBuilder.DefineEvent(
                m_UniqueName,
                declaration.Attributes,
                declaration.EventHandlerType);

            m_AddMethod = new MethodMember(ownerClass, new VirtualMethodFactory(ownerClass, declaration.GetAddMethod()));
            m_EventBuilder.SetAddOnMethod((MethodBuilder)m_AddMethod.MethodFactory.Builder);

            m_RemoveMethod = new MethodMember(ownerClass, new VirtualMethodFactory(ownerClass, declaration.GetRemoveMethod()));
            m_EventBuilder.SetRemoveOnMethod((MethodBuilder)m_RemoveMethod.MethodFactory.Builder);
        }
Пример #3
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public AnonymousMethodFactory(ClassType type, MethodMember hostMethod, Type[] argumentTypes, Type returnType, bool isStatic, bool isPublic)
        {
            var resolvedArgumentTypes = argumentTypes.Select(TypeTemplate.Resolve).ToArray();
            var resolvedReturnType    = (returnType != null ? TypeTemplate.Resolve(returnType) : null);
            var methodAttributes      = (MethodAttributes.Final | MethodAttributes.HideBySig | GetMethodModifierAttributes(isStatic, isPublic));

            m_MethodBuilder = type.TypeBuilder.DefineMethod(
                type.TakeMemberName(GetAnonymousMethodName(hostMethod.Name)),
                methodAttributes,
                resolvedReturnType,
                resolvedArgumentTypes);

            m_Signature = new MethodSignature(isStatic, isPublic, resolvedArgumentTypes, returnType: resolvedReturnType);

            m_Parameters = resolvedArgumentTypes.Select((argType, argIndex) => m_MethodBuilder.DefineParameter(
                                                            argIndex + 1,
                                                            ParameterAttributes.None,
                                                            "arg" + (argIndex + 1).ToString())).ToArray();

            if (!m_Signature.IsVoid)
            {
                m_ReturnParameter = m_MethodBuilder.DefineParameter(0, ParameterAttributes.Retval, strParamName: null);
            }
        }