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


C# Reflection.GetParameters方法代码示例

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


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

示例1: GetArguments

        string GetArguments(bcl.MethodBase method)
        {
            var arguments = new List<string>();

            foreach (var arg in method.GetParameters())
            {
                arguments.Add(GetArgument(arg));
            }

            return string.Join(", ", arguments);
        }
开发者ID:niik,项目名称:RxSpy,代码行数:11,代码来源:MethodInfo.cs

示例2: FindMatch

 XmlNode FindMatch (XmlNodeList nodes, SR.MethodInfo methodBase)
 {
     SR.ParameterInfo[] p = methodBase.GetParameters ();
     string s = "";
     foreach (XmlNode node in nodes) {
         XmlNodeList paramList = node.SelectNodes ("Parameters/*");
         s += paramList.Count + " - " + p.Length + "\n";
         if (p.Length == 0 && paramList.Count == 0) return node;
         if (p.Length != paramList.Count) continue;
         bool matched = true;
         for (int i = 0; i < p.Length; i++) {
             if (p[i].ParameterType.ToString () != paramList[i].Attributes["Type"].Value) {
                 matched = false;
             }
         }
         if (matched)
             return node;
     }
     return null;
 }
开发者ID:Kalnor,项目名称:monodevelop,代码行数:20,代码来源:Method.cs

示例3: ImportMethodBase

		MethodReference ImportMethodBase (SR.MethodBase mb, Type retType, ImportContext context)
		{
			if (IsGenericMethod (mb) && !IsGenericMethodDefinition (mb))
				return ImportGenericInstanceMethod ((SR.MethodInfo) mb, context);

			Type originalDecType = mb.DeclaringType;
			Type declaringTypeDef = originalDecType;
			while (IsGenericTypeSpec (declaringTypeDef))
				declaringTypeDef = GetGenericTypeDefinition (declaringTypeDef);

			if (mb.DeclaringType != declaringTypeDef && mb is SR.MethodInfo) {
				int mt = GetMetadataToken (mb as SR.MethodInfo);
				// hack to get the generic method definition from the constructed method
				foreach (SR.MethodInfo mi in declaringTypeDef.GetMethods ()) {
					if (GetMetadataToken (mi) == mt) {
						mb = mi;
						retType = mi.ReturnType;
						break;
					}
				}
			}

			string sig = GetMethodBaseSignature (mb, originalDecType, retType);
			MethodReference meth = (MethodReference) GetMemberReference (sig);
			if (meth != null)
				return meth;

			meth = new MethodReference (
				mb.Name,
				(mb.CallingConvention & SR.CallingConventions.HasThis) > 0,
				(mb.CallingConvention & SR.CallingConventions.ExplicitThis) > 0,
				MethodCallingConvention.Default); // TODO: get the real callconv
			meth.DeclaringType = ImportSystemType (originalDecType, context);

			if (IsGenericMethod (mb))
				foreach (Type genParam in GetGenericArguments (mb as SR.MethodInfo))
					meth.GenericParameters.Add (new GenericParameter (genParam.Name, meth));

			TypeReference contextType = context.GenericContext.Type;
			MethodReference contextMethod = context.GenericContext.Method;

			context.GenericContext.Method = meth;
			context.GenericContext.Type = ImportSystemType (declaringTypeDef, context);

			meth.ReturnType.ReturnType = ImportSystemType (retType, context);

			SR.ParameterInfo [] parameters = mb.GetParameters ();
			for (int i = 0; i < parameters.Length; i++)
				meth.Parameters.Add (new ParameterDefinition (
					ImportSystemType (parameters [i].ParameterType, context)));

			context.GenericContext.Type = contextType;
			context.GenericContext.Method = contextMethod;

			m_module.MemberReferences.Add (meth);
			return meth;
		}
开发者ID:nobled,项目名称:mono,代码行数:57,代码来源:ReflectionHelper.cs

示例4: GetMethodBaseSignature

		static string GetMethodBaseSignature (SR.MethodBase meth, Type declaringType, Type retType)
		{
			StringBuilder sb = new StringBuilder ();
			sb.Append (GetTypeSignature (retType));
			sb.Append (' ');
			sb.Append (GetTypeSignature (declaringType));
			sb.Append ("::");
			sb.Append (meth.Name);
			if (IsGenericMethodSpec (meth)) {
				sb.Append ("<");
				Type [] genArgs = GetGenericArguments (meth as SR.MethodInfo);
				for (int i = 0; i < genArgs.Length; i++) {
					if (i > 0)
						sb.Append (",");
					sb.Append (GetTypeSignature (genArgs [i]));
				}
				sb.Append (">");
			}
			sb.Append ("(");
			SR.ParameterInfo [] parameters = meth.GetParameters ();
			for (int i = 0; i < parameters.Length; i++) {
				if (i > 0)
					sb.Append (",");
				sb.Append (GetTypeSignature (parameters [i].ParameterType));
			}
			sb.Append (")");
			return sb.ToString ();
		}
开发者ID:nobled,项目名称:mono,代码行数:28,代码来源:ReflectionHelper.cs

示例5: ImportMethod

		public MethodReference ImportMethod (SR.MethodBase method, IGenericContext context, ImportGenericKind import_kind)
		{
			if (IsMethodSpecification (method) || ImportOpenGenericMethod (method, import_kind))
				return ImportMethodSpecification (method, context);

			var declaring_type = ImportType (method.DeclaringType, context);

			if (IsGenericInstance (method.DeclaringType))
				method = method.Module.ResolveMethod (method.MetadataToken);

			var reference = new MethodReference {
				Name = method.Name,
				HasThis = HasCallingConvention (method, SR.CallingConventions.HasThis),
				ExplicitThis = HasCallingConvention (method, SR.CallingConventions.ExplicitThis),
				DeclaringType = ImportType (method.DeclaringType, context, ImportGenericKind.Definition),
			};

			if (HasCallingConvention (method, SR.CallingConventions.VarArgs))
				reference.CallingConvention &= MethodCallingConvention.VarArg;

			if (method.IsGenericMethod)
				ImportGenericParameters (reference, method.GetGenericArguments ());

			var method_info = method as SR.MethodInfo;
			reference.ReturnType = method_info != null
				? ImportType (method_info.ReturnType, context ?? reference)
				: ImportType (typeof (void), null);

			var parameters = method.GetParameters ();
			var reference_parameters = reference.Parameters;

			for (int i = 0; i < parameters.Length; i++)
				reference_parameters.Add (
					new ParameterDefinition (ImportType (parameters [i].ParameterType, context ?? reference)));

			reference.DeclaringType = declaring_type;

			return reference;
		}
开发者ID:jeroldhaas,项目名称:ContinuousTests,代码行数:39,代码来源:Import.cs

示例6: PushAlignedParameterSize

        private static void PushAlignedParameterSize(SysReflection.MethodBase aMethod)
        {
            SysReflection.ParameterInfo[] xParams = aMethod.GetParameters();

            uint xSize;
            new Comment("[ Newobj.PushAlignedParameterSize start count = " + xParams.Length.ToString() + " ]");
            for (int i = 0; i < xParams.Length; i++)
            {
                xSize = SizeOfType(xParams[i].ParameterType);
                new CPUx86.Add { DestinationReg = CPUx86.Registers.ESP, SourceValue = Align(xSize, 4) };
            }
            new Comment("[ Newobj.PushAlignedParameterSize end ]");
        }
开发者ID:Orvid,项目名称:Cosmos,代码行数:13,代码来源:Newobj.cs

示例7: GetServiceMethodRequestSample

        public string GetServiceMethodRequestSample(rfl.MethodInfo mi, string apiType)
        {
            if (mi == null)
                return "No such service method";

            if (mi.GetParameters().Length != 1)
                return "A service request method should have only one parameter";

            Type t = getServiceRequestType(mi.GetParameters()[0].ParameterType);
            object req = Activator.CreateInstance(t);
            req.SetMemberValue("APIKey", "SAMPLE_API_KEY");
            req.SetMemberValue("ResellerId", ConfigurationManager.AppSettings["ResellerId"]);
            object data;
            if (mi.GetParameters()[0].ParameterType == typeof(string))
                data = "";
            else
                data = Activator.CreateInstance(mi.GetParameters()[0].ParameterType);
            req.SetMemberValue("Data", data);

            foreach (rfl.PropertyInfo pi in data.GetType().GetProperties(rfl.BindingFlags.DeclaredOnly | rfl.BindingFlags.Public | rfl.BindingFlags.Instance))
                if (!(pi.PropertyType.IsPrimitive || pi.PropertyType == typeof(string)) && pi.GetSetMethod() != null)
                    pi.SetValue(data, pi.PropertyType.IsArray ? Array.CreateInstance(pi.PropertyType.GetElementType(), 0) : Activator.CreateInstance(pi.PropertyType), null);

            return serialize(req, apiType);
        }
开发者ID:fizikci,项目名称:Cinar,代码行数:25,代码来源:ApiJson.ashx.cs

示例8: GetServiceMethodDescription

        public string GetServiceMethodDescription(rfl.MethodInfo mi)
        {
            DescriptionAttribute desc = mi.GetAttribute<DescriptionAttribute>();

            string description = "<table><tr><td colspan=\"2\"><i>" + (desc == null ? "No description." : desc.Description) + "</i></td></tr>";
            description += "<tr><td colspan=\"2\">&nbsp;</td></tr>";

            foreach (rfl.PropertyInfo pi in mi.GetParameters()[0].ParameterType.GetProperties())
            {
                DescriptionAttribute desc2 = pi.GetAttribute<DescriptionAttribute>();
                description += string.Format("<tr><td><b>{0}</b></td><td>{1}</td></tr>", pi.Name, (desc2 == null ? "" : desc2.Description));
            }

            description += "</table>";

            return description;
        }
开发者ID:fizikci,项目名称:Cinar,代码行数:17,代码来源:ApiJson.ashx.cs

示例9: FindMatchingMethodByName

        private SR.MethodBase FindMatchingMethodByName(Type targetType, SR.MethodInfo injectionMethod, string methodName)
        {
            var pars = injectionMethod.GetParameters();
            var genArgs = injectionMethod.GetGenericArguments();

            // Handle generic parameters
            Func<Type, Type> rMapper = (injParamType) =>
            {
                var mappedType = TryMapTypeToTargetAssemblyType(targetType.Assembly, injParamType);
                return mappedType != null ? mappedType : injParamType;
            };

            foreach (var m in targetType.GetMethodsAndCtors(BINDING_FLAGS))
            {
                if (m.Name != methodName)
                    continue;

                var mParams = m.GetParameters();
                if (mParams.Length != pars.Length)
                    continue;

                if (!mParams.Zip(pars, (p1, p2) => new { P1 = p1, P2 = p2 }).All(a => a.P1.ParameterMatches(a.P2, rMapper)))
                    continue;

                if (!m.IsConstructor)
                {
                    var mGenArgs = m.GetGenericArguments();
                    if (mGenArgs.Length != genArgs.Length)
                        continue;
                }

                return m;
            }

            return null;
        }
开发者ID:MarkusSintonen,项目名称:MNetInjector,代码行数:36,代码来源:Injector.cs

示例10: GetParameters

		List<TypeSig> GetParameters(SR.MethodBase delMethod) {
			var pms = new List<TypeSig>();
			foreach (var param in delMethod.GetParameters())
				pms.Add(importer.ImportAsTypeSig(param.ParameterType));
			return pms;
		}
开发者ID:KitoHo,项目名称:Reflexil,代码行数:6,代码来源:DynamicMethodBodyReader.cs

示例11: MethodMatches

        public static bool MethodMatches(this MethodReference method, SR.MethodBase matches)
        {
            if (method.Name != matches.Name)
                return false;

            if (matches is SR.MethodInfo)
            {
                if (!method.ReturnType.TypeMatches(((SR.MethodInfo)matches).ReturnType))
                    return false;
            }

            var m1Params = method.Parameters;
            var m2Params = matches.GetParameters();

            if (m1Params.Count != m2Params.Length)
                return false;

            for (var i = 0; i < m1Params.Count; i++)
            {
                if (!m1Params[i].ParameterMatches(m2Params[i]))
                    return false;
            }

            if (!matches.IsConstructor)
            {
                var m1GenericArgs = method.Resolve().GenericParameters;
                var m2GenericArgs = matches.GetGenericArguments();

                if (m1GenericArgs.Count != m2GenericArgs.Length) // No need to check types or constraints, no overloading for these in C#
                    return false;
            }

            return true;
        }
开发者ID:MarkusSintonen,项目名称:MNetInjector,代码行数:34,代码来源:Extensions.cs

示例12: Method

 public Method (Class declaringType, SR.MethodInfo tinfo)
 {
     this.declaringType = declaringType;
 
     ModifierEnum mod = (ModifierEnum)0;
     if (tinfo.IsPrivate)
         mod |= ModifierEnum.Private;
     if (tinfo.IsAssembly)
         mod |= ModifierEnum.Internal;
     if (tinfo.IsFamily)
         mod |= ModifierEnum.Protected;
     if (tinfo.IsPublic)
         mod |= ModifierEnum.Public;
     if (tinfo.IsAbstract)
         mod |= ModifierEnum.Abstract;
     if (tinfo.IsFinal)
         mod |= ModifierEnum.Sealed;
     if (tinfo.IsStatic)
         mod |= ModifierEnum.Static;
     if (tinfo.IsVirtual)
         mod |= ModifierEnum.Virtual;
         
     modifiers = mod;
     
     this.FullyQualifiedName = tinfo.Name;
     
     if (tinfo.Name == "op_Addition") this.FullyQualifiedName = "@+";
     else if (tinfo.Name == "op_Subtraction") this.FullyQualifiedName = "@-";
     else if (tinfo.Name == "op_Multiply") this.FullyQualifiedName = "@*";
     else if (tinfo.Name == "op_Division") this.FullyQualifiedName = "@/";
     else if (tinfo.Name == "op_Modulus") this.FullyQualifiedName = "@%";
     else if (tinfo.Name == "op_ExclusiveOr") this.FullyQualifiedName = "@^";
     else if (tinfo.Name == "op_BitwiseAnd") this.FullyQualifiedName = "@&";
     else if (tinfo.Name == "op_BitwiseOr") this.FullyQualifiedName = "@|";
     else if (tinfo.Name == "op_LogicalAnd") this.FullyQualifiedName = "@&&";
     else if (tinfo.Name == "op_LogicalOr") this.FullyQualifiedName = "@||";
     else if (tinfo.Name == "op_Assign") this.FullyQualifiedName = "@=";
     else if (tinfo.Name == "op_LeftShift") this.FullyQualifiedName = "@<<";
     else if (tinfo.Name == "op_RightShift") this.FullyQualifiedName = "@>>";
     else if (tinfo.Name == "op_Equality") this.FullyQualifiedName = "@==";
     else if (tinfo.Name == "op_GreaterThan") this.FullyQualifiedName = "@>";
     else if (tinfo.Name == "op_LessThan") this.FullyQualifiedName = "@<";
     else if (tinfo.Name == "op_Inequality") this.FullyQualifiedName = "@!=";
     else if (tinfo.Name == "op_GreaterThanOrEqual") this.FullyQualifiedName = "@>=";
     else if (tinfo.Name == "op_LessThanOrEqual") this.FullyQualifiedName = "@<=";
     else if (tinfo.Name == "op_MultiplicationAssignment") this.FullyQualifiedName = "@*=";
     else if (tinfo.Name == "op_SubtractionAssignment") this.FullyQualifiedName = "@-=";
     else if (tinfo.Name == "op_ExclusiveOrAssignment") this.FullyQualifiedName = "@^=";
     else if (tinfo.Name == "op_LeftShiftAssignment") this.FullyQualifiedName = "@<<=";
     else if (tinfo.Name == "op_ModulusAssignment") this.FullyQualifiedName = "@%=";
     else if (tinfo.Name == "op_AdditionAssignment") this.FullyQualifiedName = "@+=";
     else if (tinfo.Name == "op_BitwiseAndAssignment") this.FullyQualifiedName = "@&=";
     else if (tinfo.Name == "op_BitwiseOrAssignment") this.FullyQualifiedName = "@|=";
     else if (tinfo.Name == "op_Comma") this.FullyQualifiedName = "@,";
     else if (tinfo.Name == "op_DivisionAssignment") this.FullyQualifiedName = "@/=";
     else if (tinfo.Name == "op_Implicit") this.FullyQualifiedName = "@:";
     else if (tinfo.Name == "op_Explicit") this.FullyQualifiedName = "@:>";
     else if (tinfo.Name == "op_UnaryPlus") this.FullyQualifiedName = "@+";
     else if (tinfo.Name == "op_UnaryNegation") this.FullyQualifiedName = "@-";
     else if (tinfo.Name == "op_Decrement") this.FullyQualifiedName = "@--";
     else if (tinfo.Name == "op_Increment") this.FullyQualifiedName = "@++";
     else if (tinfo.Name == "op_OnesComplement") this.FullyQualifiedName = "@~";
     else if (tinfo.Name == "op_LogicalNot") this.FullyQualifiedName = "@!";        
     
     returnType = new ReturnType(tinfo.ReturnType);
     this.region = Class.GetRegion();
     this.bodyRegion = Class.GetRegion();
     this._member = null;
     
     LoadXml (declaringType, tinfo);
         
     // Add parameters
     foreach (SR.ParameterInfo pinfo in tinfo.GetParameters())
         parameters.Add(new Parameter(this, pinfo, node));
 }
开发者ID:Kalnor,项目名称:monodevelop,代码行数:75,代码来源:Method.cs


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