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


C# MethodInfo.GetParameters方法代码示例

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


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

示例1: GetInterceptedMethod

        private static MethodInfo GetInterceptedMethod(MethodInfo interceptionMethod)
        {
            var parameterTypes = from parameter in interceptionMethod.GetParameters()
                                 select parameter.ParameterType;

            return interceptionMethod.DeclaringType.GetMethod(interceptionMethod.GetMethodNameWithoutTilde(), parameterTypes.ToArray());
        }
开发者ID:handcraftsman,项目名称:BlackBoxRecorder,代码行数:7,代码来源:DependencyPlayback.cs

示例2: MethodInvocationValidator

 /// <summary>
 /// Creates a new <see cref="MethodInvocationValidator"/> instance.
 /// </summary>
 /// <param name="method">Method to be validated</param>
 /// <param name="parameterValues">List of arguments those are used to call the <paramref name="method"/>.</param>
 public MethodInvocationValidator(MethodInfo method, object[] parameterValues)
 {
     _method = method;
     _parameterValues = parameterValues;
     _parameters = method.GetParameters();
     _validationErrors = new List<ValidationResult>();
 }
开发者ID:lizhi5753186,项目名称:BDF,代码行数:12,代码来源:MethodInvocationValidator.cs

示例3: DefineMethod

        public static MethodBuilder DefineMethod(this TypeBuilder typeBuilder, MethodInfo method, MethodAttributes? attributes = null, ParameterInfo[] parameters = null)
        {
            Type[] parametersTypes = null;
            MethodBuilder methodBuilder = null;

            parameters = parameters ?? method.GetParameters();
            parametersTypes = parameters.ToArray(parameter => parameter.ParameterType);
            attributes = attributes ?? method.Attributes & ~MethodAttributes.Abstract;
            methodBuilder = typeBuilder.DefineMethod(method.Name, attributes.Value, method.ReturnType, parametersTypes);

            parameters.ForEach(1, (parameter, i) => {
                var parameterBuilder = methodBuilder.DefineParameter(i, parameter.Attributes, parameter.Name);

                if (parameter.IsDefined<ParamArrayAttribute>()) {
                    parameterBuilder.SetCustomAttribute<ParamArrayAttribute>();
                }
                else if (parameter.IsOut) {
                    parameterBuilder.SetCustomAttribute<OutAttribute>();
                }
                else if (parameter.IsOptional) {
                    parameterBuilder.SetCustomAttribute<OptionalAttribute>()
                                    .SetConstant(parameter.DefaultValue);
                }
            });

            return methodBuilder;
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:27,代码来源:ReflectionUtils.cs

示例4: SqlCallProcedureInfo

 public SqlCallProcedureInfo(MethodInfo method, ISerializationTypeInfoProvider typeInfoProvider)
 {
     if (method == null) {
         throw new ArgumentNullException("method");
     }
     if (typeInfoProvider == null) {
         throw new ArgumentNullException("typeInfoProvider");
     }
     SqlProcAttribute procedure = GetSqlProcAttribute(method);
     schemaName = procedure.SchemaName;
     name = procedure.Name;
     timeout = procedure.Timeout;
     deserializeReturnNullOnEmptyReader = procedure.DeserializeReturnNullOnEmptyReader;
     deserializeRowLimit = procedure.DeserializeRowLimit;
     deserializeCallConstructor = procedure.DeserializeCallConstructor;
     SortedDictionary<int, SqlCallParameterInfo> sortedParams = new SortedDictionary<int, SqlCallParameterInfo>();
     outArgCount = 0;
     foreach (ParameterInfo parameterInfo in method.GetParameters()) {
         if ((parameterInfo.GetCustomAttributes(typeof(SqlNameTableAttribute), true).Length > 0) || (typeof(XmlNameTable).IsAssignableFrom(parameterInfo.ParameterType))) {
             if (xmlNameTableParameter == null) {
                 xmlNameTableParameter = parameterInfo;
             }
         } else {
             SqlCallParameterInfo sqlParameterInfo = new SqlCallParameterInfo(parameterInfo, typeInfoProvider, ref outArgCount);
             sortedParams.Add(parameterInfo.Position, sqlParameterInfo);
         }
     }
     parameters = sortedParams.Select(p => p.Value).ToArray();
     returnTypeInfo = typeInfoProvider.GetSerializationTypeInfo(method.ReturnType);
     if ((procedure.UseReturnValue != SqlReturnValue.Auto) || (method.ReturnType != typeof(void))) {
         useReturnValue = (procedure.UseReturnValue == SqlReturnValue.ReturnValue) || ((procedure.UseReturnValue == SqlReturnValue.Auto) && (typeInfoProvider.TypeMappingProvider.GetMapping(method.ReturnType).DbType == SqlDbType.Int));
     }
 }
开发者ID:avonwyss,项目名称:bsn-modulestore,代码行数:33,代码来源:SqlCallProcedureInfo.cs

示例5: GenerateRegexForURL

 internal static string GenerateRegexForURL(ModelListMethod mlm, MethodInfo mi)
 {
     Logger.Debug("Generating regular expression for model list method at path " + mlm.Path);
     string ret = "^(GET\t";
     if (mlm.Host == "*")
         ret += ".+";
     else
         ret+=mlm.Host;
     if (mi.GetParameters().Length > 0)
     {
         ParameterInfo[] pars = mi.GetParameters();
         string[] regexs = new string[pars.Length];
         for (int x = 0; x < pars.Length; x++)
         {
             Logger.Trace("Adding parameter " + pars[x].Name+"["+pars[x].ParameterType.FullName+"]");
             regexs[x] = _GetRegexStringForParameter(pars[x]);
         }
         string path = string.Format((mlm.Path+(mlm.Paged ? (mlm.Path.Contains("?") ? "&" : "?")+"PageStartIndex={"+(regexs.Length-3).ToString()+"}&PageSize={"+(regexs.Length-2).ToString()+"}" : "")).Replace("?","\\?"), regexs);
         ret += (path.StartsWith("/") ? path : "/" + path).TrimEnd('/');
     }
     else
         ret += (mlm.Path.StartsWith("/") ? mlm.Path : "/" + mlm.Path).Replace("?", "\\?").TrimEnd('/');
     Logger.Trace("Regular expression constructed: " + ret + ")$");
     return ret+")$";
 }
开发者ID:marquismark,项目名称:backbone-dotnet,代码行数:25,代码来源:URLUtility.cs

示例6: InvokeDirect

        public static object InvokeDirect(MethodInfo method, object instance, params object[] parameters) {
            if (method == null)
                throw new ArgumentNullException("method");
            if (!method.IsStatic && instance == null)
                throw new ArgumentException("Non-static method requires a non-null instance.");
            if (method.IsStatic && instance != null)
                throw new ArgumentException("Static method requires a null instance.");
            if (method.IsGenericMethodDefinition)
                throw new ArgumentException("Cannot invoke generic method definitions. Concretise the generic type first by supplying generic type parameters.");
            if (method.GetParameters().Length != parameters.Length)
                throw new ArgumentException(string.Format("Parameter count mismatch: {0} parameters given; {1} parameters expected.", parameters.Length, method.GetParameters().Length));

            // Create a dynamic assembly for the two types we need
            createAssembly();

            // Generate a string that identifies the method "signature" (the parameter types and return type, not the method name).
            // Different methods which have the same "signature" according to this criterion can re-use the same generated code.
            var sig = string.Join(" : ", method.GetParameters().Select(p => p.ParameterType.FullName).Concat(new[] { method.ReturnType.FullName }).ToArray());

            if (!invokers.ContainsKey(sig)) {
                // Create a delegate type compatible with the method signature
                var delegateType = createDelegateType(method, sig);

                // Create a class that implements IInvokeDirect
                var classType = createClassType(method, sig, delegateType);

                // Instantiate the new class and remember the instance for additional future calls
                invokers[sig] = (IInvokeDirect) Activator.CreateInstance(classType);
            }

            // Invoke the interface method, passing it the necessary information to call the right target method.
            return invokers[sig].DoInvoke(instance, parameters, method);
        }
开发者ID:sajagi,项目名称:Freya.Cab,代码行数:33,代码来源:DirectInvoker.cs

示例7: Build

		public void Build(MethodInfo methodInfo)
		{
			_name = methodInfo.Name;
			_declaringType = methodInfo.DeclaringType.FullName;
			_fullName = methodInfo.DeclaringType.FullName + "." + methodInfo.Name;
			ArrayList parameters = new ArrayList();
			if( methodInfo.GetParameters() != null && methodInfo.GetParameters().Length > 0 )
			{
				foreach(ParameterInfo parameterInfo in methodInfo.GetParameters())
				{
					ParameterDescriptor parameterDescriptor = new ParameterDescriptor();
					parameterDescriptor.Build(parameterInfo);
					parameters.Add(parameterDescriptor);
				}
			}
			_returnValue = new ParameterTypeDescriptor();
			_returnValue.Build(methodInfo.ReturnType);
			_parameters = parameters.ToArray(typeof(ParameterDescriptor)) as ParameterDescriptor[];

			object[] attrs = methodInfo.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
			if( attrs.Length > 0 )
			{
				System.ComponentModel.DescriptionAttribute descriptionAttribute = attrs[0] as System.ComponentModel.DescriptionAttribute;
				_description = descriptionAttribute.Description;
			}
		}
开发者ID:apakian,项目名称:fluorinefx,代码行数:26,代码来源:MethodDescriptor.cs

示例8: IsValidFiller

 private bool IsValidFiller(MethodInfo info)
 {
     return    info.GetParameters().Count() == 2
            && info.GetParameters()[0].ParameterType == typeof (Guid?)
            && info.GetParameters()[1].ParameterType == typeof(string)
            && info.ReturnType == typeof (object);
 }
开发者ID:kayanme,项目名称:Dataspace,代码行数:7,代码来源:PropertiesProvider.cs

示例9: DynamicMethodHandle

        //public DynamicMethodHandle( MethodInfo info, params object[] parameters )
        /// <summary>
        /// Initializes a new instance of the <see cref="DynamicMethodHandle"/> class.
        /// </summary>
        /// <param name="info">MethodInfo</param>
        public DynamicMethodHandle( MethodInfo info )
        {
            if (info == null)
            {
                this.dynamicMethod = null;
            }
            else
            {
                this.methodName = info.Name;
                ParameterInfo[] infoParams = info.GetParameters();
                //object[] inParams = null;
                //if (parameters == null)
                //{
                //    inParams = new object[] { null };

                //}
                //else
                //{
                //    inParams = parameters;
                //}
                int pCount = infoParams.Length;
                if (pCount > 0 &&
                   ((pCount == 1 && infoParams[0].ParameterType.IsArray) ||
                   (infoParams[pCount - 1].GetCustomAttributes(typeof(ParamArrayAttribute), true).Length > 0)))
                {
                    this.hasFinalArrayParam = true;
                    this.methodParamsLength = pCount;
                    this.finalArrayElementType = infoParams[pCount - 1].ParameterType;
                }
                this.dynamicMethod = DynamicMethodHandlerFactory.CreateMethod(info);
            }

            this.parameterInfoList = info.GetParameters();
        }
开发者ID:helldog7,项目名称:Rance,代码行数:39,代码来源:DynamicMethodHandle.cs

示例10: GenerateInvocation

        /// <summary>
        /// Creates a <see cref="MethodBuilder"/> and implements a default wrapper.
        /// </summary>
        /// <param name="owner">The type that will own this method.</param>
        /// <param name="interfaceType">Type of interface implemented by the <paramref name="owner"/>.</param>
        /// <param name="overrideMethod">Method to override.</param>
        /// <param name="fieldBuilders">Fields specified by the <see paramref="owner"/>.</param>
        /// <returns>MethodBuilder with an already implemented wrapper.</returns>
        public MethodBuilder GenerateInvocation(TypeBuilder owner, Type interfaceType, MethodInfo overrideMethod, IEnumerable<FieldBuilder> fieldBuilders)
        {
            var result = owner.DefineMethod
                    (
                        overrideMethod.Name,
                        MethodAttributes.Private | MethodAttributes.Virtual | MethodAttributes.Final |
                        MethodAttributes.HideBySig | MethodAttributes.NewSlot,
                        overrideMethod.ReturnType,
                        overrideMethod.GetParameters().OrderBy(p => p.Position).Select(t => t.ParameterType).ToArray()
                    );

            result.SetImplementationFlags(MethodImplAttributes.AggressiveInlining);

            var generator = result.GetILGenerator();
            var fieldName = LibraryInterfaceMapper.GetFieldNameForMethodInfo(overrideMethod);
            var field = fieldBuilders.First(f => f.Name == fieldName);
            var parameters = overrideMethod.GetParameters();
            OnInvokeBegin(owner, interfaceType, generator, overrideMethod);
            generator.Emit(OpCodes.Ldarg_0); //  this
            generator.Emit(OpCodes.Ldfld, field); // MethodNameProc _glMethodName. Initialized by constructor.
            foreach (var item in parameters.Where(p => !p.IsRetval).Select((p, i) => new { Type = p, Index = i }))
            {
                generator.Emit(OpCodes.Ldarg, item.Index + 1);
            }

            generator.EmitCall(OpCodes.Callvirt, field.FieldType.GetMethod("Invoke"), null);

            OnInvokeEnd(owner, interfaceType, generator, overrideMethod);

            generator.Emit(OpCodes.Ret);

            owner.DefineMethodOverride(result, overrideMethod);

            return result;
        }
开发者ID:GeirGrusom,项目名称:PlatformInvoker,代码行数:43,代码来源:DefaultMethodCallWrapper.cs

示例11: GetClientMethodCode

        public string GetClientMethodCode(MethodInfo method, string url)
        {
            var model = new ClientMethodModel();

            var parameterInfos = method.GetParameters();
            var inputParameters = parameterInfos.Select(p => string.Format("{0}: {1}", p.Name, TypeMapper.GetTypeScriptType(p.ParameterType)))
                    .ToList();

            model.Traditional = parameterInfos.Any(p => p.ParameterType.IsArray);

            var returnType = method.ReturnType;
            if (returnType.Name != "Void")
            {
                var onSucces = "callback: (data: " + TypeMapper.GetTypeScriptType(returnType) + ") => any";
                inputParameters.Add(onSucces);
                model.OnSucces = "callback";
            }

            //hacky
            var isPost = method.GetCustomAttributes(typeof(HttpPostAttribute), true).Any() || returnType.IsJsonResult() || returnType == typeof(JsonResult);
            model.AjaxMethod = isPost ? "POST" : "";

            var allParameters = string.Join(", ", inputParameters);
            model.Signature = method.Name + "(" + allParameters + ")";

            model.Url = url;
            var inputJsonTuples = method.GetParameters().Select(p => string.Format("{0}: {0}", p.Name));
            model.Data = "{ " + string.Join(", ", inputJsonTuples) + " }";

            var template = GetTemplate("ClientMethod");

            return RemoveEmptyLines(Razor.Parse(template, model));//.Split("\r\n".ToCharArray(),StringSplitOptions.RemoveEmptyEntries);
        }
开发者ID:SimonMeskens,项目名称:Weld,代码行数:33,代码来源:RazorTemplateEngine.cs

示例12: AllArgumentsEquals

        private bool AllArgumentsEquals(MethodInfo method1, MethodInfo method2)
        {
            if (method1.GetParameters().Length != method2.GetParameters().Length)
            {
                return false;
            }

            foreach (var argument in method1.GetParameters()
                .Zip(
                    method2.GetParameters(),
                    (method1Parameter, method2Parameter) =>
                        new
                        {
                            Method1Parameter = method1Parameter,
                            Method2Parameter = method2Parameter
                        }))
            {
                if (!object.Equals(argument.Method1Parameter.ParameterType, argument.Method2Parameter.ParameterType) ||
                    !string.Equals(argument.Method1Parameter.Name, argument.Method2Parameter.Name))
                {
                    return false;
                }
            }

            return true;
        }
开发者ID:huoxudong125,项目名称:FakeItEasy,代码行数:26,代码来源:FacadedTestBase.cs

示例13: GenerateRule

        public static DecompositionRule GenerateRule(MethodInfo method)
        {
            DecompositionAttribute decomposition =
              (DecompositionAttribute)Attribute.GetCustomAttribute(method, typeof(DecompositionAttribute), false);

            if (decomposition == null)
            {
                return null;
            }

            if (method.ReturnType == typeof(void))
            {
                throw new InvalidOperationException("Decomposition rule must return object.");
            }

            if (method.GetParameters().Count() != 1)
            {
                throw new InvalidOperationException("Wrong parameters number in decomposition function. Decomposition is performed on a single module.");
            }

            return new DecompositionRule()
            {
                MethodInfo = method,
                Type = method.GetParameters()[0].ParameterType
            };
        }
开发者ID:Jaimerh,项目名称:lsystems-csharp-lib,代码行数:26,代码来源:DecompositionRule.cs

示例14: GetRouteAttributes

        public override IEnumerable<IRouteAttribute> GetRouteAttributes(MethodInfo actionMethod)
        {
            // Logic from ApiControllerActionSelector

            if (actionMethod.IsSpecialName)
            {
                // not a normal method, e.g. a constructor or an event
                yield break;
            }

            if (actionMethod.GetBaseDefinition().SafeGet(x => x.DeclaringType).IsAssignableFrom(typeof(ApiController)))
            {
                // is a method on Object, IHttpController, ApiController
                yield break;
            }

            foreach (var c in Conventions)
            {
                if (actionMethod.Name.StartsWith(c.HttpMethod.Method, StringComparison.OrdinalIgnoreCase))
                {
                    var requiresId = !string.IsNullOrEmpty(c.Url);

                    if (!_alreadyUsed.Contains(c))
                    {
                        // Check first parameter, if it requires ID
                        if (!requiresId || (actionMethod.GetParameters().Length > 0 && actionMethod.GetParameters()[0].Name.Equals("id", StringComparison.OrdinalIgnoreCase)))
                        {
                            yield return BuildRouteAttribute(c);

                            _alreadyUsed.Add(c);
                        }
                    }
                }
            }
        }
开发者ID:Cefa68000,项目名称:AttributeRouting,代码行数:35,代码来源:DefaultHttpRouteConventionAttribute.cs

示例15: MessageListMethodAdapter

 public MessageListMethodAdapter(object obj, MethodInfo method)
 {
     AssertUtils.ArgumentNotNull(obj, "'obj' must not be null");
     AssertUtils.ArgumentNotNull(method, "'method' must not be null");
     AssertUtils.IsTrue(method.GetParameters().Length == 1 && method.GetParameters()[0].ParameterType.Equals(typeof(IList<IMessage>)),
             "Method must accept exactly one parameter, and it must be a List.");
     _method = method;
     _invoker = new DefaultMethodInvoker(obj, _method);
 }
开发者ID:rlxrlxrlx,项目名称:spring-net-integration,代码行数:9,代码来源:MessageListMethodAdapter.cs


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