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


C# MethodBase.GetParametersInternal方法代码示例

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


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

示例1: GetFullNameForStackTrace

		internal void GetFullNameForStackTrace (StringBuilder sb, MethodBase mi)
		{
			ParameterInfo[] p = mi.GetParametersInternal ();
			sb.Append (mi.DeclaringType.ToString ());
			sb.Append (".");
			sb.Append (mi.Name);

			if (mi.IsGenericMethod) {
				Type[] gen_params = mi.GetGenericArguments ();
				sb.Append ("[");
				for (int j = 0; j < gen_params.Length; j++) {
					if (j > 0)
						sb.Append (",");
					sb.Append (gen_params [j].Name);
				}
				sb.Append ("]");
			}

			sb.Append (" (");
			for (int i = 0; i < p.Length; ++i) {
				if (i > 0)
					sb.Append (", ");
				Type pt = p[i].ParameterType;
				if (pt.IsClass && !String.IsNullOrEmpty (pt.Namespace)) {
					sb.Append (pt.Namespace);
					sb.Append (".");
				}
				sb.Append (pt.Name);
				if (p [i].Name != null) {
					sb.Append (" ");
					sb.Append (p [i].Name);
				}
			}
			sb.Append (")");
		}
开发者ID:jack-pappas,项目名称:mono,代码行数:35,代码来源:Exception.cs

示例2: GetFullNameForStackTrace

		// This method is also used with reflection by mono-symbolicate tool.
		// mono-symbolicate tool uses this method to check which method matches
		// the stack frame method signature.
		static void GetFullNameForStackTrace (StringBuilder sb, MethodBase mi)
		{
			var declaringType = mi.DeclaringType;
			if (declaringType.IsGenericType && !declaringType.IsGenericTypeDefinition)
				declaringType = declaringType.GetGenericTypeDefinition ();

			// Get generic definition
			var bindingflags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
			foreach (var m in declaringType.GetMethods (bindingflags)) {
				if (m.MetadataToken == mi.MetadataToken) {
					mi = m;
					break;
				}
			}

			sb.Append (declaringType.ToString ());

			sb.Append (".");
			sb.Append (mi.Name);

			if (mi.IsGenericMethod) {
				Type[] gen_params = mi.GetGenericArguments ();
				sb.Append ("[");
				for (int j = 0; j < gen_params.Length; j++) {
					if (j > 0)
						sb.Append (",");
					sb.Append (gen_params [j].Name);
				}
				sb.Append ("]");
			}

			ParameterInfo[] p = mi.GetParametersInternal ();

			sb.Append (" (");
			for (int i = 0; i < p.Length; ++i) {
				if (i > 0)
					sb.Append (", ");

				Type pt = p[i].ParameterType;
				if (pt.IsGenericType && ! pt.IsGenericTypeDefinition)
					pt = pt.GetGenericTypeDefinition ();

				if (pt.IsClass && !String.IsNullOrEmpty (pt.Namespace)) {
					sb.Append (pt.Namespace);
					sb.Append (".");
				}
				sb.Append (pt.Name);
				if (p [i].Name != null) {
					sb.Append (" ");
					sb.Append (p [i].Name);
				}
			}
			sb.Append (")");
		}
开发者ID:psni,项目名称:mono,代码行数:57,代码来源:StackTrace.cs

示例3: ReorderParameters

			void ReorderParameters (string [] names, ref object [] args, MethodBase selected)
			{
				object [] newArgs = new object [args.Length];
				Array.Copy (args, newArgs, args.Length);
				ParameterInfo [] plist = selected.GetParametersInternal ();
				for (int n = 0; n < names.Length; n++)
					for (int p = 0; p < plist.Length; p++) {
						if (names [n] == plist [p].Name) {
							newArgs [p] = args [n];
							break;
						}
					}
				Array.Copy (newArgs, args, args.Length);
			}
开发者ID:salloo,项目名称:mono,代码行数:14,代码来源:Binder.cs

示例4: GetBetterMethod

			MethodBase GetBetterMethod (MethodBase m1, MethodBase m2, Type [] types)
			{
				ParameterInfo [] pl1 = m1.GetParametersInternal ();
				ParameterInfo [] pl2 = m2.GetParametersInternal ();
				int prev = 0;
				for (int i = 0; i < pl1.Length; i++) {
					int cmp = CompareCloserType (pl1 [i].ParameterType, pl2 [i].ParameterType);
					if (cmp != 0 && prev != 0 && prev != cmp)
						throw new AmbiguousMatchException ();
					if (cmp != 0)
						prev = cmp;
				}
				if (prev != 0)
					return prev > 0 ? m2 : m1;

				Type dt1 = m1.DeclaringType;
				Type dt2 = m2.DeclaringType;
				if (dt1 != dt2) {
					if (dt1.IsSubclassOf(dt2))
						return m1;
					if (dt2.IsSubclassOf(dt1))
						return m2;
				}

				bool va1 = (m1.CallingConvention & CallingConventions.VarArgs) != 0;
				bool va2 = (m2.CallingConvention & CallingConventions.VarArgs) != 0;
				if (va1 && !va2)
					return m2;
				if (va2 && !va1)
					return m1;

				throw new AmbiguousMatchException ();
			}
开发者ID:salloo,项目名称:mono,代码行数:33,代码来源:Binder.cs

示例5: AdjustArguments

			// probably belongs in ReorderArgumentArray
			static void AdjustArguments (MethodBase selected, ref object [] args)
			{
				var parameters = selected.GetParametersInternal ();
				var parameters_length = parameters.Length;
				if (parameters_length == 0)
					return;

				var last_parameter = parameters [parameters.Length - 1];
				Type last_parameter_type = last_parameter.ParameterType;
				if (!Attribute.IsDefined (last_parameter, typeof (ParamArrayAttribute)))
					return;

				var args_length = args.Length;
				var param_args_count = args_length + 1 - parameters_length;
				var first_vararg_index = args_length - param_args_count;
				if (first_vararg_index < args_length) {
					var first_vararg = args [first_vararg_index];
					if (first_vararg != null && first_vararg.GetType () == last_parameter_type)
						return;
				}
				
				var params_args = Array.CreateInstance (last_parameter_type.GetElementType (), param_args_count);
				for (int i = 0; i < param_args_count; i++)
					params_args.SetValue (args [first_vararg_index + i], i);

				var adjusted = new object [parameters_length];
				Array.Copy (args, adjusted, parameters_length - 1);
				
				adjusted [adjusted.Length - 1] = params_args;
				args = adjusted;
			}
开发者ID:salloo,项目名称:mono,代码行数:32,代码来源:Binder.cs


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