Beispiel #1
0
        protected CILMethodBaseImpl(
            CILReflectionContextImpl ctx,
            Int32 anID,
            System.Reflection.MethodBase method
            )
            : base(ctx, anID, (method is System.Reflection.ConstructorInfo) ? CILElementKind.Constructor : CILElementKind.Method, () => new CustomAttributeDataEventArgs(ctx, method))
        {
            ArgumentValidator.ValidateNotNull("Method", method);

            if (method.DeclaringType
#if WINDOWS_PHONE_APP
                .GetTypeInfo()
#endif
                .IsGenericType&& !method.DeclaringType
#if WINDOWS_PHONE_APP
                .GetTypeInfo()
#endif
                .IsGenericTypeDefinition)
            {
                throw new ArgumentException("This constructor may be used only on methods declared in genericless types or generic type definitions.");
            }
            if (method is System.Reflection.MethodInfo && method.GetGenericArguments().Any() && !method.IsGenericMethodDefinition)
            {
                throw new ArgumentException("This constructor may be used only on genericless methods or generic method definitions.");
            }

            InitFields(
                ref this.callingConvention,
                ref this.methodAttributes,
                ref this.methodKind,
                ref this.declaringType,
                ref this.parameters,
                ref this.il,
                ref this.methodImplementationAttributes,
                ref this.securityInfo,
                new SettableValueForEnums <CallingConventions>((CallingConventions)method.CallingConvention),
                new SettableValueForEnums <MethodAttributes>((MethodAttributes)method.Attributes),
                this.cilKind == CILElementKind.Constructor ? MethodKind.Constructor : MethodKind.Method,
                () => (CILType)ctx.Cache.GetOrAdd(method.DeclaringType),
                () => ctx.CollectionsFactory.NewListProxy <CILParameter>(method.GetParameters().Select(param => ctx.Cache.GetOrAdd(param)).ToList()),
                () =>
            {
                MethodIL result;
                if (ctx.Cache.ResolveMethodBaseID(this.id).HasILMethodBody())
                {
                    var args = new MethodBodyLoadArgs(method);
                    ctx.LaunchMethodBodyLoadEvent(args);
                    result = new CILAssemblyManipulator.Implementation.Physical.MethodILImpl(this.DeclaringType.Module, args);
                }
                else
                {
                    result = null;
                }
                return(result);
            },
                new SettableLazy <MethodImplAttributes>(() =>
            {
                var args = new MethodImplAttributesEventArgs(method);
                ctx.LaunchMethodImplAttributesEvent(args);
                return(args.MethodImplementationAttributes);
            }),
                new Lazy <DictionaryWithRoles <SecurityAction, ListProxy <SecurityInformation>, ListProxyQuery <SecurityInformation>, ListQuery <SecurityInformation> > >(this.SecurityInfoFromAttributes, LazyThreadSafetyMode.ExecutionAndPublication),
                true
                );
        }
 private static void ctx_MethodImplementationAttributesLoadEvent(object sender, MethodImplAttributesEventArgs e)
 {
     e.MethodImplementationAttributes = (MethodImplAttributes)e.Method.GetMethodImplementationFlags();
 }