Пример #1
0
        private static string Serialize(System.Reflection.MethodBase methodBase)
        {
            StringBuilder st = new StringBuilder();

            st.Append(Serialize(methodBase.DeclaringType));

            st.Append(" ");
            st.Append(methodBase.Name);

            st.Append(SerializeGeneric(methodBase.GetGenericArguments()));
            st.Append("(");

            bool t = false;

            foreach (var item in methodBase.GetParameters())
            {
                if (t)
                {
                    st.Append(", ");
                }
                st.Append(Serialize(item.ParameterType));
                t = true;
            }

            st.Append(")");
            return(st.ToString());
        }
Пример #2
0
        internal MethodBaseInfo(System.Reflection.MethodBase methodInfo, TypeInfoProvider typeInfoProvider)
            : base(methodInfo, typeInfoProvider)
        {
            var genericArguments = methodInfo.IsGenericMethod ? methodInfo.GetGenericArguments() : null;

            GenericArgumentTypes = genericArguments is null || genericArguments.Length == 0
                ? null
                : genericArguments.Select(x => typeInfoProvider.Get(x, false, false)).ToList();

            var parameters = methodInfo.GetParameters();

            ParameterTypes = parameters.Length == 0
                ? null
                : parameters.Select(x => typeInfoProvider.Get(x.ParameterType, false, false)).ToList();
        }
Пример #3
0
        internal MethodBaseInfo(System.Reflection.MethodBase methodInfo, TypeInfoProvider typeInfoProvider)
            : base(methodInfo, typeInfoProvider)
        {
            var bindingFlags = methodInfo.IsStatic ? BindingFlags.Static : BindingFlags.Instance;

            bindingFlags |= methodInfo.IsPublic ? BindingFlags.Public : BindingFlags.NonPublic;
            BindingFlags  = bindingFlags;

            var genericArguments = methodInfo.IsGenericMethod ? methodInfo.GetGenericArguments() : null;

            GenericArgumentTypes = genericArguments is null || genericArguments.Length == 0
                ? null
                : genericArguments.Select(x => typeInfoProvider.Get(x, false, false)).ToList();

            var parameters = methodInfo.GetParameters();

            ParameterTypes = parameters.Length == 0
                ? null
                : parameters.Select(x => typeInfoProvider.Get(x.ParameterType, false, false)).ToList();
        }
Пример #4
0
        private static string GetDisplayName(System.Reflection.MethodBase method, string name, object[] arglist)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder(name);

            if (method.IsGenericMethod)
            {
                sb.Append("<");
                int cnt = 0;
                foreach (var t in method.GetGenericArguments())
                {
                    if (cnt++ > 0)
                    {
                        sb.Append(",");
                    }
                    sb.Append(t.Name);
                }
                sb.Append(">");
            }

            if (arglist != null)
            {
                sb.Append("(");

                for (int i = 0; i < arglist.Length; ++i)
                {
                    if (i > 0)
                    {
                        sb.Append(",");
                    }
                    sb.Append(GetDisplayString(arglist[i]));
                }

                sb.Append(")");
            }

            return(sb.ToString());
        }
Пример #5
0
        protected MethodBaseInfo(System.Reflection.MethodBase method, TypeInfoProvider typeInfoProvider)
            : base(method, typeInfoProvider)
        {
            var genericArguments = method.CheckNotNull(nameof(method)).IsGenericMethod ? method.GetGenericArguments() : null;

            GenericArgumentTypes = genericArguments
                                   .AsNullIfEmpty()?
                                   .Select(x => typeInfoProvider.GetTypeInfo(x, false, false))
                                   .ToList();
            ParameterTypes = method
                             .GetParameters()
                             .AsNullIfEmpty()?
                             .Select(x => typeInfoProvider.GetTypeInfo(x.ParameterType, false, false))
                             .ToList();
        }
Пример #6
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
                );
        }