本文整理汇总了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();
}
示例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));
}
}
示例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;
}
示例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);
}
示例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;
}
示例6: ParameterWrapper
public ParameterWrapper(ActionBinder binder, ParameterInfo info)
: this(binder, info.ParameterType)
{
_name = SymbolTable.StringToId(info.Name ?? "<unknown>");
_isParams = info.IsDefined(typeof(ParamArrayAttribute), false);
}
示例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);
}
示例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;
}
示例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;
}
示例10: NodeInfo
public NodeInfo(Type type, string name, MemberTypes mtype, ParameterInfo[] parameters)
{
this.NodeType = type;
this.Name = name;
this.MemberType = mtype;
this.Parameters = parameters;
}
示例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));
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}