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


C# Reflection.ParameterInfo类代码示例

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


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

示例1: Convert

        /// <summary>
        /// 参数解析
        /// </summary>
        /// <param name="paramters"></param>
        /// <param name="nvs"></param>
        /// <returns></returns>
        public static object[] Convert(ParameterInfo[] paramters, NameValueCollection nvs)
        {
            List<object> args = new List<object>();
            var obj = ConvertJsonObject(nvs);

            foreach (ParameterInfo info in paramters)
            {
                var type = GetElementType(info.ParameterType);

                var property = obj.Properties().SingleOrDefault(p => string.Compare(p.Name, info.Name, true) == 0);
                if (property != null)
                {
                    try
                    {
                        //获取Json值
                        var jsonValue = CoreHelper.ConvertJsonValue(type, property.Value.ToString(Formatting.None));
                        args.Add(jsonValue);
                    }
                    catch (Exception ex)
                    {
                        throw new RESTfulException((int)HttpStatusCode.BadRequest, string.Format("Parameter [{0}] did not match type [{1}].",
                            info.Name, CoreHelper.GetTypeName(type)));
                    }
                }
                else
                {
                    throw new RESTfulException((int)HttpStatusCode.BadRequest, "Parameter [" + info.Name + "] is not found.");
                }
            }

            return args.ToArray();
        }
开发者ID:rajayaseelan,项目名称:mysoftsolution,代码行数:38,代码来源:ParameterHelper.cs

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

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

		protected override void ImplementInvokeMethodOnTarget(AbstractTypeEmitter @class, ParameterInfo[] parameters, MethodEmitter invokeMethodOnTarget, MethodInfo callbackMethod, Reference targetField)
		{
			invokeMethodOnTarget.CodeBuilder.AddStatement(
				new ExpressionStatement(
					new MethodInvocationExpression(SelfReference.Self, InvocationMethods.EnsureValidTarget)));
			base.ImplementInvokeMethodOnTarget(@class, parameters, invokeMethodOnTarget, callbackMethod, targetField);
		}
开发者ID:JulianBirch,项目名称:Castle.Core,代码行数:7,代码来源:InterfaceInvocationTypeGenerator.cs

示例5: GetParameterValue

 public bool GetParameterValue(ParameterInfo paramInfo, int paramLoc, ref Object parameter)
 {
     var ParamName = paramInfo.Name;
     if (!_hashParams.ContainsKey(ParamName)) return false;
     parameter = _hashParams[ParamName];
     return true;
 }
开发者ID:erashid,项目名称:ScheduleTimer,代码行数:7,代码来源:ParameterSetter.cs

示例6: ParameterWrapper

        public ParameterWrapper(ActionBinder binder, ParameterInfo info)
            : this(binder, info.ParameterType)
        {
            _name = SymbolTable.StringToId(info.Name ?? "<unknown>");

            _isParams = info.IsDefined(typeof(ParamArrayAttribute), false);
        }
开发者ID:robertlj,项目名称:IronScheme,代码行数:7,代码来源:ParameterWrapper.cs

示例7: ResolveMethodParameter

        private object ResolveMethodParameter(ParameterInfo methodParameterInfo, IDictionary<string, object> queryParameters, NancyContext context)
        {
            if (IsQueryParameter(methodParameterInfo, queryParameters))
                return GetValueFromQueryParameters(methodParameterInfo, queryParameters);

            return GetValueFromRequestBody(methodParameterInfo, context);
        }
开发者ID:MingLu8,项目名称:Nancy.WebApi,代码行数:7,代码来源:Extractors.cs

示例8: CalculateParamPoints

		public int CalculateParamPoints(SmartDispatcherController controller, ParameterInfo parameterInfo)
		{
			if (String.IsNullOrEmpty(parameterName))
				parameterName = parameterInfo.Name;

			return String.IsNullOrEmpty(controller.Request.Params[parameterName]) ? 0 : 100;
		}
开发者ID:elementar,项目名称:Suprifattus.Util,代码行数:7,代码来源:EncryptedAttribute.cs

示例9: TryInvokeMemberWithNamedParameters

        private bool TryInvokeMemberWithNamedParameters(InvokeMemberBinder binder, object[] args, out object result,
                                                        MethodInfo method, ParameterInfo[] parameters)
        {
            var fixedArgs = new List<object>();
            for (int i = 0; i < parameters.Length; i++)
            {
                if (parameters[i].RawDefaultValue == DBNull.Value)
                {
                    fixedArgs.Add(args[i]);
                }
                else
                {
                    var index = binder.CallInfo.ArgumentNames.IndexOf(parameters[i].Name);
                    if (index > -1)
                    {
                        if (!parameters[i].ParameterType.IsInstanceOfType(args[index]))
                        {
                            result = null;
                            return false;
                        }
                    }
                    else
                    {
                        fixedArgs.Add(parameters[i].RawDefaultValue);
                    }
                }
            }

            result = method.Invoke(_adapter, fixedArgs.ToArray());
            return true;
        }
开发者ID:JorgeGamba,项目名称:Simple.Data,代码行数:31,代码来源:AdapterMethodDynamicInvoker.cs

示例10: NodeInfo

 public NodeInfo(Type type, string name, MemberTypes mtype, ParameterInfo[] parameters)
 {
     this.NodeType = type;
     this.Name = name;
     this.MemberType = mtype;
     this.Parameters = parameters;
 }
开发者ID:nguyenhuuhuy,项目名称:mygeneration,代码行数:7,代码来源:AutoCompleteHelper.cs

示例11: ExtractParameter

        private static ParameterAnnotationInfo ExtractParameter(Expression expression, ParameterInfo parameter)
        {
            var methodCallExpression = AssertCallOnSpecialClass(expression);

            var methodName = methodCallExpression.Method.Name;
            switch (methodName)
            {
                case nameof(Annotations.FormatString):
                    return new ParameterAnnotationInfo(parameter.Name, isFormatString: true, isNotNull: true);

                case nameof(Annotations.NullableFormatString):
                    return new ParameterAnnotationInfo(parameter.Name, isFormatString: true, canBeNull: true);

                case nameof(Annotations.Some):
                    return new ParameterAnnotationInfo(parameter.Name);

                case nameof(Annotations.NotNull):
                    return new ParameterAnnotationInfo(parameter.Name, isNotNull: true);

                case nameof(Annotations.CanBeNull):
                    return new ParameterAnnotationInfo(parameter.Name, canBeNull: true);

                default:
                    throw new ArgumentException($"Expression '{expression}' call an unsupported method : {methodName}. {usageInfo}",
                        nameof(expression));
            }
        }
开发者ID:gitter-badger,项目名称:ExternalAnnotationsGenerator,代码行数:27,代码来源:ExpressionParser.cs

示例12: BindModel

        /// <summary>
        /// 生成模型
        /// </summary>
        /// <param name="request">请求数据</param>
        /// <param name="parameter">参数</param>       
        /// <returns></returns>
        public object BindModel(HttpRequest request, ParameterInfo parameter)
        {
            var name = parameter.Name;
            var targetType = parameter.ParameterType;

            if (targetType.IsClass == true && targetType.IsArray == false && targetType != typeof(string))
            {
                return ConvertToClass(request, parameter);
            }

            // 转换为数组
            var values = request.GetValues(name);
            if (targetType.IsArray == true)
            {
                return Converter.Cast(values, targetType);
            }

            // 转换为简单类型 保留参数默认值
            var value = values.FirstOrDefault();
            if (value == null && parameter.DefaultValue != DBNull.Value)
            {
                return parameter.DefaultValue;
            }
            return Converter.Cast(value, targetType);
        }
开发者ID:JackWangCUMT,项目名称:NetworkSocket,代码行数:31,代码来源:DefaultModelBinder.cs

示例13: ExtractParameterFromDictionary

        internal static object ExtractParameterFromDictionary(ParameterInfo parameterInfo, IDictionary<string, object> parameters, MethodInfo methodInfo)
        {
            object value;

            if (!parameters.TryGetValue(parameterInfo.Name, out value))
            {
                // the key should always be present, even if the parameter value is null
                string message = String.Format(CultureInfo.CurrentCulture, MvcResources.ReflectedActionDescriptor_ParameterNotInDictionary,
                                               parameterInfo.Name, parameterInfo.ParameterType, methodInfo, methodInfo.DeclaringType);
                throw new ArgumentException(message, "parameters");
            }

            if (value == null && !TypeHelpers.TypeAllowsNullValue(parameterInfo.ParameterType))
            {
                // tried to pass a null value for a non-nullable parameter type
                string message = String.Format(CultureInfo.CurrentCulture, MvcResources.ReflectedActionDescriptor_ParameterCannotBeNull,
                                               parameterInfo.Name, parameterInfo.ParameterType, methodInfo, methodInfo.DeclaringType);
                throw new ArgumentException(message, "parameters");
            }

            if (value != null && !parameterInfo.ParameterType.IsInstanceOfType(value))
            {
                // value was supplied but is not of the proper type
                string message = String.Format(CultureInfo.CurrentCulture, MvcResources.ReflectedActionDescriptor_ParameterValueHasWrongType,
                                               parameterInfo.Name, methodInfo, methodInfo.DeclaringType, value.GetType(), parameterInfo.ParameterType);
                throw new ArgumentException(message, "parameters");
            }

            return value;
        }
开发者ID:marojeri,项目名称:aspnetwebstack,代码行数:30,代码来源:ActionDescriptor.cs

示例14: ProcedureParameter

 public ProcedureParameter(ParameterInfo info)
 {
     Type = info.ParameterType;
     Name = info.Name;
     bool hasDefaultValue = info.IsOptional && (info.Attributes & ParameterAttributes.HasDefault) == ParameterAttributes.HasDefault;
     DefaultValue = hasDefaultValue ? info.DefaultValue : DBNull.Value;
 }
开发者ID:602p,项目名称:krpc,代码行数:7,代码来源:ProcedureParameter.cs

示例15: Bind

        public object Bind(IDictionary<string, string> parameters, ParameterInfo parameterInfo)
        {
            if (parameters.ContainsKey(parameterInfo.Name) && !string.IsNullOrEmpty(parameters[parameterInfo.Name]))
                return new UUID(StringToByteArray(parameters[parameterInfo.Name]));

            return null;
        }
开发者ID:CHAOS-Community,项目名称:Portal,代码行数:7,代码来源:UUIDParameterBinding.cs


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