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


C# MethodBase.GetParameters方法代码示例

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


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

示例1: RestrictPropertySetterToSpecificType

 /// <summary>
 /// The criteria to restrict an attribute to a specific type at compile time
 /// </summary>
 /// <param name="methodBase"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public static bool RestrictPropertySetterToSpecificType(MethodBase methodBase, Type type)
 {
     if (methodBase.GetParameters() == null)
     {
         return false;
     }
     if (methodBase.GetParameters().Length != 1)
     {
         return false;
     }
     return methodBase.GetParameters()[0].ParameterType == type;
 }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:18,代码来源:CompileTimeValidateScenario.cs

示例2: RestrictPropertySetterToSpecificImplementation

        /// <summary>
        /// The criteria to restrict an attribute to a specific interfaceType at compile time
        /// </summary>
        /// <param name="methodBase"></param>
        /// <param name="interfaceType"></param>
        /// <returns></returns>
        public static bool RestrictPropertySetterToSpecificImplementation(MethodBase methodBase, Type interfaceType)
        {
            if (methodBase.GetParameters() == null)
            {
                return false;
            }
            if (methodBase.GetParameters().Length != 1)
            {
                return false;
            }

            Type type = methodBase.GetParameters()[0].ParameterType;
            string interfaceFullName = interfaceType.FullName;
            return type.GetInterface(interfaceFullName) != null;
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:21,代码来源:CompileTimeValidateScenario.cs

示例3: GenerateMethodCaption

 private string GenerateMethodCaption(MethodBase mb)
 {
     StringBuilder builder = new StringBuilder(0x100);
     if (!this.IsConstructor)
     {
         builder.Append(mb.Name);
     }
     else
     {
         builder.Append(mb.DeclaringType.Name);
     }
     builder.Append('(');
     ParameterInfo[] parameters = mb.GetParameters();
     if (parameters != null)
     {
         int length = parameters.Length;
         for (int i = 0; i < length; i++)
         {
             if (i != 0)
             {
                 builder.Append(", ");
             }
             builder.Append(parameters[i].ParameterType.Name);
         }
     }
     builder.Append(')');
     return builder.ToString();
 }
开发者ID:ikvm,项目名称:webmatrix,代码行数:28,代码来源:MethodItem.cs

示例4: IsStatic

		//===========================================================================================
		private bool IsStatic(MethodBase method)
		{
			if (method == null)
				return false;

			return method.GetParameters().Length == 0;
		}
开发者ID:dlemstra,项目名称:GraphicsMagick.NET,代码行数:8,代码来源:ExecuteCodeGenerator.cs

示例5: CheckOptionalParametersAltNamesAreNotDuplicated

 private void CheckOptionalParametersAltNamesAreNotDuplicated(MethodBase method)
 {
     var parameterNames = new List<string>();
     foreach (ParameterInfo parameter in method.GetParameters())
     {
         if (_metadata.IsRequired(parameter))
         {
             parameterNames.Add(parameter.Name.ToLower());
         }
         else
         {
             if (parameterNames.Contains(parameter.Name.ToLower()))
             {
                 throw new NConsolerException(
                     "Found duplicated parameter name \"{0}\" in method \"{1}\". Please check alt names for optional parameters",
                     parameter.Name, method.Name);
             }
             parameterNames.Add(parameter.Name.ToLower());
             var optional = _metadata.GetOptional(parameter);
             foreach (string altName in optional.AltNames)
             {
                 if (parameterNames.Contains(altName.ToLower()))
                 {
                     throw new NConsolerException(
                         "Found duplicated parameter name \"{0}\" in method \"{1}\". Please check alt names for optional parameters",
                         altName, method.Name);
                 }
                 parameterNames.Add(altName.ToLower());
             }
         }
     }
 }
开发者ID:nuxleus,项目名称:nconsoler,代码行数:32,代码来源:MetadataValidator.cs

示例6: Rate

        /// <summary>
        /// Scores the given constructor based on the number of dependencies we can fill.
        /// </summary>
        static int Rate(MethodBase constructor, TypeTracker typeTracker)
        {
            // Preserve the default behaviour of preferring explicitly marked constructors.
            if (constructor.IsDefined(typeof(InjectionConstructorAttribute), false))
                return int.MaxValue;

            var score = 0;

            foreach (var parameter in constructor.GetParameters())
            {
                if(parameter.IsOut || parameter.IsRetval)
                    return -1;

                if (typeTracker.HasDependency(parameter.ParameterType))
                {
                    score++;
                }
                else
                {
                    // We don't know how to fill this parameter so try a different constructor
                    return -1;
                }
            }

            return score;
        }
开发者ID:rokite,项目名称:openrasta-stable,代码行数:29,代码来源:ConstructorSelectorPolicy.cs

示例7: 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

示例8: CanProcess

 protected static bool CanProcess(MethodBase method, EntityDomain domain, object domainId)
 {
     ParameterInfo[] parameters = method.GetParameters();
     if (method.IsStatic) return parameters.Length == 0 || domain != null;
     return (parameters.Length == 0 && domainId != null)
            || (domain != null && domainId != null);
 }
开发者ID:timbooker,项目名称:dotObjects,代码行数:7,代码来源:EntityProcess.cs

示例9: 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

示例10: GetMethodArguments

 private static object[] GetMethodArguments(MethodBase method)
 {
     return (
         from parameter in method.GetParameters()
         let parameterType = parameter.ParameterType
         select GetInstance(parameterType)).ToArray();
 }
开发者ID:dineshkummarc,项目名称:Session--6--DI---IoC-Containers,代码行数:7,代码来源:ServiceLocatorPageHandlerFactory.cs

示例11: GenerateMethod

 private static string GenerateMethod(MethodBase method, AjaxMethodAttribute attribute, string url)
 {
     // FORMAT:
     // 1. Async:
     // <MethodName>:function(<Parameters: pi>,sc,ec) {var p={<Parameters: pi:pi>};MkAJAX.callAsync(<URL>,<RequestType>,p,sc,ec);}
     // 2. Blocking:
     // <MethodName>:function(<Parameters: pi>) {var p={<Parameters: pi:pi>};return MkAJAX.callBlock(<URL>,<RequestType>,p);}
     ParameterInfo[] methodParams = method.GetParameters();
     string name = attribute.Name ?? method.Name;
     bool isAsync = attribute.ExecutionType == ExecutionType.Async;
     return string.Format("{0}{1}:function({2}{3}){{var p={{{4}}};{5}(\"{6}/{7}\",{8},p{9}{3});}}",
         /*0*/Environment.NewLine,
         /*1*/attribute.UseJavaScriptNamingConvention ? FirstCharacterToLower(name) : name,
         /*2*/string.Format("{0}{1}", string.Join(",", Array.ConvertAll(methodParams, p => p.Name)),
             methodParams.Length > 0 && isAsync ? "," : string.Empty),
         /*3*/isAsync ? "cb" : string.Empty,
         /*4*/methodParams.Length > 0
             ? string.Join(",", Array.ConvertAll(methodParams, p => string.Format("{0}:{0}", p.Name)))
             : string.Empty,
         /*5*/isAsync ? "MkAjax.callAsync" : "return MkAjax.callBlock",
         /*6*/url,
         /*7*/method.Name,
         /*8*/attribute.RequestType == RequestType.Post ? "true" : "false", // false for now mean GET
         /*9*/isAsync ? "," : string.Empty);
 }
开发者ID:KostovMartin,项目名称:mKWays,代码行数:25,代码来源:MethodsGenerator.cs

示例12: DataBindParameters

        private static object[] DataBindParameters(Controller controller, MethodBase action)
        {
            ParameterInfo[] param = action.GetParameters();
            object[] args = new object[param.Length];
            foreach (ParameterInfo info in param)
            {
                string name = info.Name;
                Type type = info.ParameterType;

                if (controller.PropertyBag[name] != null)
                {
                    //                    Console.WriteLine("type:"+type);
                    //                    Console.WriteLine("Base:" + controller.PropertyBag[name].GetType().BaseType + " :" + controller.PropertyBag[name].GetType().BaseType.Equals(type));
                    //                    Console.WriteLine("getType:" + controller.PropertyBag[name].GetType() + " :" + controller.PropertyBag[name].GetType().Equals(type));
                    //                    Console.WriteLine("issubclass:"+controller.PropertyBag[name].GetType().IsSubclassOf(type));

                    if (controller.PropertyBag[name].GetType().BaseType.Equals(type) ||
                        controller.PropertyBag[name].GetType().Equals(type) ||
                        controller.PropertyBag[name].GetType().IsSubclassOf(type))
                    {
                        //info.RawDefaultValue = 
                        args[info.Position] = controller.PropertyBag[name];
                    }
                }
            }
            return args;
        }
开发者ID:CraigCary,项目名称:roduino,代码行数:27,代码来源:ActionInvoker.cs

示例13: UnwrapArgs

        protected object[] UnwrapArgs(MethodBase m, object[] args)
        {
            ParameterInfo[] paramInfos = m.GetParameters();

            if (args != null && args.Length > paramInfos.Length)
                throw new ArgumentException(String.Format("Too many js arguments passed to plugin method {0};  expected {1} got {2}", m.Name, paramInfos.Length, args.Length));

            object[] newArgs = new object[paramInfos.Length];
            int k = 0;
            for (int i = 0; i < paramInfos.Length; i++)
            {
                ParameterInfo paramInfo = paramInfos[i];
                object argValue;
                if (k < args.Length && TryConvertArg(paramInfo, args[k], out argValue)) // If args[k] matches
                {
                    newArgs[i] = argValue;
                    k++;
                    continue;
                }

                if (TryGetOptionalArg(paramInfo, out argValue))
                {
                    newArgs[i] = argValue;
                }
                else
                {
                    throw new MissingMemberException();
                }
            }
            return newArgs;
        }
开发者ID:nodekit-io,项目名称:nodekit-windows,代码行数:31,代码来源:NKScriptInvocation.cs

示例14: CreateRefParameterExpressions

        internal static Expression[] CreateRefParameterExpressions(MethodBase method, Expression argumentsParameter)
        {
            // http://stackoverflow.com/questions/3146317/create-expression-to-invoke-method-with-out-parameter
            // for reference parameters need to call MakeByRefType() somehow???
            //return method.GetParameters().Select((parameter, index) =>
            //  ).ToArray();

            ParameterInfo[] parameters = method.GetParameters();
            Expression[] toReturn = new Expression[parameters.Count()];

            for (int i=0;i<parameters.Length; i++)
            {
                ParameterInfo pi = parameters[i];
                if (pi.ParameterType.IsByRef)
                {
                    // doesn't work somehow I need to affect the argumentsParemter expression else I get a not in scope exception!
                    toReturn[i] = Expression.Convert(Expression.ArrayIndex(argumentsParameter, Expression.Constant(i)), pi.ParameterType.GetElementType());
                }
                else
                {
                    toReturn[i] = Expression.Convert(Expression.ArrayIndex(argumentsParameter, Expression.Constant(i)), pi.ParameterType);
                }
            }

            return toReturn;
        }
开发者ID:paulkrwebs,项目名称:FastInvoke,代码行数:26,代码来源:FastInvokeUtilities.cs

示例15: GetStackSizeToReservate

        public static uint GetStackSizeToReservate(MethodBase aMethod)
        {

            var xMethodInfo = aMethod as SysReflection.MethodInfo;
            uint xReturnSize = 0;
            if (xMethodInfo != null)
            {
                xReturnSize = SizeOfType(xMethodInfo.ReturnType);
            }
            if (xReturnSize == 0)
            {
                return 0;
            }

            // todo: implement exception support
            int xExtraStackSize = (int)Align(xReturnSize, 4);
            var xParameters = aMethod.GetParameters();
            foreach (var xItem in xParameters)
            {
                xExtraStackSize -= (int)Align(SizeOfType(xItem.ParameterType), 4);
            }
            if (!xMethodInfo.IsStatic)
            {
                xExtraStackSize -= GetNativePointerSize(xMethodInfo);
            }
            if (xExtraStackSize > 0)
            {
                return (uint)xExtraStackSize;
            }
            return 0;
        }
开发者ID:Orvid,项目名称:Cosmos,代码行数:31,代码来源:Call.cs


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