当前位置: 首页>>代码示例>>C#>>正文


C# MethodBase.GetGenericArguments方法代码示例

本文整理汇总了C#中System.Reflection.MethodBase.GetGenericArguments方法的典型用法代码示例。如果您正苦于以下问题:C# MethodBase.GetGenericArguments方法的具体用法?C# MethodBase.GetGenericArguments怎么用?C# MethodBase.GetGenericArguments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.MethodBase的用法示例。


在下文中一共展示了MethodBase.GetGenericArguments方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FormatMethod

 protected virtual string FormatMethod(MethodBase method)
 {
     var sb = new StringBuilder();
     if (method.DeclaringType != null)
     {
         sb.Append(method.DeclaringType.FullName);
         sb.Append(".");
     }
     sb.Append(method.Name);
     if (method.IsGenericMethod)
     {
         sb.Append("<");
         sb.Append(string.Join(", ", method.GetGenericArguments().Select(t => t.Name)));
         sb.Append(">");
     }
     sb.Append("(");
     var f = false;
     foreach (var p in method.GetParameters())
     {
         if (f) sb.Append(", ");
         else f = true;
         sb.Append(p.ParameterType.Name);
         sb.Append(' ');
         sb.Append(p.Name);
     }
     sb.Append(")");
     return sb.ToString();
 }
开发者ID:darilek,项目名称:dotvvm,代码行数:28,代码来源:ExceptionSectionFormatter.cs

示例2: ReflectionMethod

		public ReflectionMethod(MethodBase methodBase, ReflectionClass declaringType)
			: base(declaringType, methodBase is ConstructorInfo ? "#ctor" : methodBase.Name)
		{
			if (methodBase is MethodInfo) {
				this.ReturnType = ReflectionReturnType.Create(this, ((MethodInfo)methodBase).ReturnType, false);
			} else if (methodBase is ConstructorInfo) {
				this.ReturnType = DeclaringType.DefaultReturnType;
			}
			
			foreach (ParameterInfo paramInfo in methodBase.GetParameters()) {
				this.Parameters.Add(new ReflectionParameter(paramInfo, this));
			}
			
			if (methodBase.IsGenericMethodDefinition) {
				foreach (Type g in methodBase.GetGenericArguments()) {
					this.TypeParameters.Add(new DefaultTypeParameter(this, g));
				}
				int i = 0;
				foreach (Type g in methodBase.GetGenericArguments()) {
					declaringType.AddConstraintsFromType(this.TypeParameters[i++], g);
				}
			}
			
			if (methodBase.IsStatic) {
				foreach (CustomAttributeData data in CustomAttributeData.GetCustomAttributes(methodBase)) {
					string attributeName = data.Constructor.DeclaringType.FullName;
					if (attributeName == "System.Runtime.CompilerServices.ExtensionAttribute"
					    || attributeName == "Boo.Lang.ExtensionAttribute")
					{
						this.IsExtensionMethod = true;
					}
				}
			}
			ModifierEnum modifiers  = ModifierEnum.None;
			if (methodBase.IsStatic) {
				modifiers |= ModifierEnum.Static;
			}
			if (methodBase.IsPrivate) { // I assume that private is used most and public last (at least should be)
				modifiers |= ModifierEnum.Private;
			} else if (methodBase.IsFamily || methodBase.IsFamilyOrAssembly) {
				modifiers |= ModifierEnum.Protected;
			} else if (methodBase.IsPublic) {
				modifiers |= ModifierEnum.Public;
			} else {
				modifiers |= ModifierEnum.Internal;
			}
			
			if (methodBase.IsVirtual) {
				modifiers |= ModifierEnum.Virtual;
			}
			if (methodBase.IsAbstract) {
				modifiers |= ModifierEnum.Abstract;
			}
			this.Modifiers = modifiers;
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:55,代码来源:ReflectionMethod.cs

示例3: ReflectionMethod

		public ReflectionMethod(MethodBase methodBase, ReflectionClass declaringType)
			: base(declaringType, methodBase is ConstructorInfo ? "#ctor" : methodBase.Name)
		{
			if (methodBase is MethodInfo) {
				MethodInfo m = ((MethodInfo)methodBase);
				this.ReturnType = ReflectionReturnType.Create(this, m.ReturnType, attributeProvider: m.ReturnTypeCustomAttributes);
			} else if (methodBase is ConstructorInfo) {
				this.ReturnType = DeclaringType.DefaultReturnType;
			}
			
			foreach (ParameterInfo paramInfo in methodBase.GetParameters()) {
				this.Parameters.Add(new ReflectionParameter(paramInfo, this));
			}
			
			if (methodBase.IsGenericMethodDefinition) {
				foreach (Type g in methodBase.GetGenericArguments()) {
					this.TypeParameters.Add(new DefaultTypeParameter(this, g));
				}
				int i = 0;
				foreach (Type g in methodBase.GetGenericArguments()) {
					ReflectionClass.AddConstraintsFromType(this.TypeParameters[i++], g);
				}
			}
			
			ModifierEnum modifiers  = ModifierEnum.None;
			if (methodBase.IsStatic) {
				modifiers |= ModifierEnum.Static;
			}
			if (methodBase.IsPrivate) { // I assume that private is used most and public last (at least should be)
				modifiers |= ModifierEnum.Private;
			} else if (methodBase.IsFamily || methodBase.IsFamilyOrAssembly) {
				modifiers |= ModifierEnum.Protected;
			} else if (methodBase.IsPublic) {
				modifiers |= ModifierEnum.Public;
			} else {
				modifiers |= ModifierEnum.Internal;
			}
			
			if (methodBase.IsFinal) {
				modifiers |= ModifierEnum.Sealed;
			} else if (methodBase.IsAbstract) {
				modifiers |= ModifierEnum.Abstract;
			} else if (methodBase.IsVirtual) {
				if ((methodBase.Attributes & MethodAttributes.NewSlot) != 0)
					modifiers |= ModifierEnum.Virtual;
				else
					modifiers |= ModifierEnum.Override;
			}
			
			this.Modifiers = modifiers;
			
			ReflectionClass.AddAttributes(declaringType.ProjectContent, this.Attributes, CustomAttributeData.GetCustomAttributes(methodBase));
			ApplySpecialsFromAttributes(this);
		}
开发者ID:SAD1992,项目名称:justdecompile-plugins,代码行数:54,代码来源:ReflectionMethod.cs

示例4: ModuleScopeTokenResolver

 public ModuleScopeTokenResolver(MethodBase method)
 {
     m_enclosingMethod = method;
     m_module = method.Module;
     m_methodContext = (method is ConstructorInfo) ? null : method.GetGenericArguments();
     m_typeContext = (method.DeclaringType == null) ? null : method.DeclaringType.GetGenericArguments();
 }
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:7,代码来源:ModuleScopeTokenResolver.cs

示例5: GetId

        public static string GetId(MethodBase methodOrConstructor)
        {
            var genericPart = string.Empty;
            if (methodOrConstructor.IsGenericMethod)
            {
                genericPart = string.Format(CultureInfo.InvariantCulture, "``{0}", methodOrConstructor.GetGenericArguments().Length);
            }

            var parametersPart = string.Join(
                ",",
                methodOrConstructor.GetParameters()
                    .Select(x => GetTypeName(x.ParameterType)));
            if (!string.IsNullOrEmpty(parametersPart))
            {
                parametersPart = "(" + parametersPart + ")";
            }

            var conversionReturnTypePart = string.Empty;
            if (methodOrConstructor.IsSpecialName &&
                (methodOrConstructor.Name.Equals("op_Explicit") || methodOrConstructor.Name.Equals("op_Implicit")))
            {
                conversionReturnTypePart = "~" + GetTypeName(((MethodInfo)methodOrConstructor).ReturnType);
            }

            return string.Format(
                CultureInfo.InvariantCulture,
                "M:{0}.{1}{2}{3}{4}",
                GetTypeName(methodOrConstructor.ReflectedType),
                HashEncode(methodOrConstructor.Name),
                genericPart,
                parametersPart,
                conversionReturnTypePart);
        }
开发者ID:anderskaplan,项目名称:NuDoc,代码行数:33,代码来源:SlashdocIdentifierProvider.cs

示例6: MethodBodyReader

		MethodBodyReader (MethodBase method)
		{
			this.method = method;

			this.body = method.GetMethodBody ();
			if (this.body == null)
				throw new ArgumentException ("Method has no body");

			var bytes = body.GetILAsByteArray ();
			if (bytes == null)
				throw new ArgumentException ("Can not get the body of the method");

			if (!(method is ConstructorInfo))
				method_arguments = method.GetGenericArguments ();

			if (method.DeclaringType != null)
				type_arguments = method.DeclaringType.GetGenericArguments ();

            if (!method.IsStatic)
                this_parameter = new ThisParameter(method.DeclaringType);


            this.parameters = method.GetParameters ();
			this.locals = body.LocalVariables;
			this.module = method.Module;
			this.il = new ByteBuffer (bytes);
			this.instructions = new List<Instruction> ((bytes.Length + 1) / 2);
		}
开发者ID:krauthaufen,项目名称:mono.reflection,代码行数:28,代码来源:MethodBodyReader.cs

示例7: AppendMethod

        private void AppendMethod(StringBuilder builder, MethodBase method)
        {
            if (method.DeclaringType != null) {
                AppendType(builder, method.DeclaringType);
                builder.Append(".");
            }
            AppendName(builder, method.Name);
            if (method.IsGenericMethod) {
                builder.Append("[");
                method.GetGenericArguments().ForEach((type, index) => {
                    if (index > 0)
                        builder.Append(",");
                    AppendType(builder, type);
                });
                builder.Append("]");
            }
            builder.Append("(");
            method.GetParameters().ForEach((parameter, index) => {
                if (index > 0)
                    builder.Append(", ");

                builder.Append(parameter.ParameterType.Name)
                       .Append(" ")
                       .Append(parameter.Name);
            });
            builder.Append(")");
        }
开发者ID:KallynGowdy,项目名称:net-feature-tests,代码行数:27,代码来源:ExceptionNormalizer.cs

示例8: MethodSigEquals

		public bool MethodSigEquals(MethodBaseSig sig, MethodBase method) {
			if (sig == null || method == null)
				return false;
			if (sig.HasThis != !method.IsStatic)
				return false;
			if (sig.Generic != method.IsGenericMethod)
				return false;
			if (sig.Generic) {
				if (sig.GenParamCount != method.GetGenericArguments().Length)
					return false;
			}
			if (method.IsMethodSpec())
				method = method.Module.ResolveMethod(method.MetadataToken) ?? method;
			var mps = method.GetParameters();
			if (sig.Params.Count != mps.Length)
				return false;

			var minfo = method as MethodInfo;
			if (minfo != null) {
				if (!Equals(sig.RetType, minfo.ReturnType))
					return false;
			}
			else {
				if (sig.RetType.RemovePinnedAndModifiers().GetElementType() != ElementType.Void)
					return false;
			}

			for (int i = 0; i < mps.Length; i++) {
				if (!Equals(sig.Params[i], mps[i].ParameterType))
					return false;
			}

			return true;
		}
开发者ID:GreenDamTan,项目名称:dnSpy,代码行数:34,代码来源:TypeComparer.cs

示例9: GetGenericArguments

		public static Type[] GetGenericArguments(MethodBase methodBase) {
			try {
				return methodBase.GetGenericArguments();
			}
			catch (NotSupportedException) {
				return new Type[0];
			}
		}
开发者ID:RafaelRMachado,项目名称:de4dot,代码行数:8,代码来源:ResolverUtils.cs

示例10: MethodBaseModuleContext

        public MethodBaseModuleContext(MethodBase method)
        {
            this.module = method.Module;
            this.methodGenericArguments = (method.IsGenericMethod || method.IsGenericMethodDefinition) ? method.GetGenericArguments() : new Type[0];

            var type = method.DeclaringType;
            this.typeGenericArguments = (type != null && (type.IsGenericType || type.IsGenericTypeDefinition)) ? type.GetGenericArguments() : new Type[0];
        }
开发者ID:ashmind,项目名称:expressive,代码行数:8,代码来源:MethodBaseModuleContext.cs

示例11: TokenResolver

 public TokenResolver(ITypeLoader typeLoader, MethodBase method)
 {
     this.typeLoader = typeLoader;
     this.module = method.Module;
     var type = method.DeclaringType;
     if(type != null)
         this.typeArguments = type.GetGenericArguments();
     if(!(method.IsConstructor || method.IsSpecialName) && method.IsGenericMethod)
         this.methodArguments = method.GetGenericArguments();
 }
开发者ID:danaxa,项目名称:Pencil,代码行数:10,代码来源:TokenResolver.cs

示例12: GetMethodFormatStrings

		/// <summary>
		/// Gets the formatting strings representing a method.
		/// </summary>
		/// <param name="method">A <see cref="MethodBase"/>.</param>
		/// <returns></returns>
		public static MethodFormatStrings GetMethodFormatStrings(MethodBase method)
		{
			string typeFormat;
			bool typeIsGeneric;
			string methodFormat;
			bool methodIsGeneric;
			string parameterFormat;

			StringBuilder stringBuilder = new StringBuilder();

			typeFormat = GettypeFormatString(method.DeclaringType);
			typeIsGeneric = method.DeclaringType.IsGenericTypeDefinition;

			// Build the format string for the method name.
			stringBuilder.Length = 0;
			stringBuilder.Append("::");
			stringBuilder.Append(method.Name);
			if (method.IsGenericMethodDefinition)
			{
				methodIsGeneric = true;
				stringBuilder.Append("<");
				for (int i = 0; i < method.GetGenericArguments().Length; i++)
				{
					if (i > 0)
						stringBuilder.Append(", ");
					stringBuilder.AppendFormat("{{{0}}}", i);
				}
				stringBuilder.Append(">");
			}
			else
			{
				methodIsGeneric = false;
			}
			methodFormat = stringBuilder.ToString();

			// Build the format string for parameters.
			stringBuilder.Length = 0;
			ParameterInfo[] parameters = method.GetParameters();
			stringBuilder.Append("(");
			for (int i = 0; i < parameters.Length; i++)
			{
				if (i > 0)
				{
					stringBuilder.Append(", ");
				}
				stringBuilder.Append("{{{");
				stringBuilder.Append(i);
				stringBuilder.Append("}}}");
			}
			stringBuilder.Append(")");

			parameterFormat = stringBuilder.ToString();

			return new MethodFormatStrings(typeFormat, typeIsGeneric, methodFormat, methodIsGeneric, parameterFormat);
		}
开发者ID:smartpcr,项目名称:Instrumentation,代码行数:60,代码来源:Formatter.cs

示例13: Format

        public String Format(
            Object instance,
            MethodBase method,
            Object[] invocationParameters)
        {
            String[] parts = { 
                                 Formatter.FormatString(_typeFormat, method.DeclaringType.GetGenericArguments()),
                                 Formatter.FormatString(_methodFormat, method.GetGenericArguments()),
                                 instance == null ? "" : String.Format("{{{0}}}", instance ),
                                 Formatter.FormatString(_parameterFormat, invocationParameters) };

            return String.Concat(parts);
        }
开发者ID:Molibar,项目名称:Molibar.Framework,代码行数:13,代码来源:MethodFormatStrings.cs

示例14: FormatSignature

        public static StringBuilder FormatSignature(StringBuilder result, MethodBase method, Func<Type, string> nameDispenser) {
            ContractUtils.RequiresNotNull(result, "result");
            ContractUtils.RequiresNotNull(method, "method");
            ContractUtils.RequiresNotNull(nameDispenser, "nameDispenser");

            MethodInfo methodInfo = method as MethodInfo;
            if (methodInfo != null) {
                FormatTypeName(result, methodInfo.ReturnType, nameDispenser);
                result.Append(' ');
            }

            MethodBuilder builder = method as MethodBuilder;
            if (builder != null) {
                result.Append(builder.Signature);
                return result;
            }

            ConstructorBuilder cb = method as ConstructorBuilder;
            if (cb != null) {
                result.Append(cb.Signature);
                return result;
            }

            FormatTypeName(result, method.DeclaringType, nameDispenser);
            result.Append("::");
            result.Append(method.Name);

            if (!method.IsConstructor) {
                FormatTypeArgs(result, method.GetGenericArguments(), nameDispenser);
            }

            result.Append("(");

            if (!method.ContainsGenericParameters) {
                ParameterInfo[] ps = method.GetParameters();
                for (int i = 0; i < ps.Length; i++) {
                    if (i > 0) result.Append(", ");
                    FormatTypeName(result, ps[i].ParameterType, nameDispenser);
                    if (!System.String.IsNullOrEmpty(ps[i].Name)) {
                        result.Append(" ");
                        result.Append(ps[i].Name);
                    }
                }
            } else {
                result.Append("?");
            }

            result.Append(")");
            return result;
        }
开发者ID:BenHall,项目名称:ironruby,代码行数:50,代码来源:ReflectionUtils.cs

示例15: GenerateMethodName

        protected static string GenerateMethodName(MethodBase method)
        {
            var stringBuilder = new StringBuilder();

              stringBuilder.Append(method.Name);

              bool first = true;
              if (method is MethodInfo && method.IsGenericMethod)
              {
            Type[] genericArguments = method.GetGenericArguments();
            stringBuilder.Append("[");
            for (int i = 0; i < genericArguments.Length; i++)
            {
              if (!first)
              {
            stringBuilder.Append(",");
              }
              else
              {
            first = false;
              }
              stringBuilder.Append(genericArguments[i].Name);
            }
            stringBuilder.Append("]");
              }
              stringBuilder.Append("(");
              ParameterInfo[] parameters = method.GetParameters();
              first = true;
              for (int i = 0; i < parameters.Length; ++i)
              {
            if (!first)
            {
              stringBuilder.Append(", ");
            }
            else
            {
              first = false;
            }
            string type = "<UnknownType>";
            if (parameters[i].ParameterType != null)
            {
              type = parameters[i].ParameterType.Name;
            }
            stringBuilder.Append(type + " " + parameters[i].Name);
              }
              stringBuilder.Append(")");

              return stringBuilder.ToString();
        }
开发者ID:MindscapeHQ,项目名称:raygun4net,代码行数:49,代码来源:RaygunErrorMessageBuilderBase.cs


注:本文中的System.Reflection.MethodBase.GetGenericArguments方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。