本文整理汇总了C#中System.Reflection.ParameterInfo.Select方法的典型用法代码示例。如果您正苦于以下问题:C# ParameterInfo.Select方法的具体用法?C# ParameterInfo.Select怎么用?C# ParameterInfo.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.ParameterInfo
的用法示例。
在下文中一共展示了ParameterInfo.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildParameters
//public string TypeName
//{
// get { return TypeUtils.ToDisplayString(Parameter.ParameterType, true); }
//}
public static ParameterDom[] BuildParameters(ParameterInfo[] piAr, XElement parentDoc)
{
if(piAr==null || piAr.Length==0)
return new ParameterDom[0];
if(parentDoc==null)
return piAr.Select(_ => new ParameterDom(_)).ToArray();
var pd = new ParameterDictionary(parentDoc, "param");
return piAr
.Select( _ => new ParameterDom(_){DocInfo = pd[_.Name]})
.ToArray();
}
示例2: AddMethod
private void AddMethod(MethodInfo info, CodeTypeDeclaration target)
{
var method = new CodeMemberMethod
{
Attributes = MemberAttributes.Public,
Name = info.Name,
ReturnType = new CodeTypeReference(info.ReturnType),
};
var allParameters = info.GetParameters().ToArray();
var parameters = new ParameterInfo[0];
if (allParameters.Length > 1)
parameters = allParameters.Skip(1).ToArray();
method.Parameters.AddRange(
parameters.Select(p => new CodeParameterDeclarationExpression(p.ParameterType, p.Name)).ToArray());
//Invoke
var statement = new CodeMethodReturnStatement();
string parms = GetInvokeParametersString(parameters);
statement.Expression = new CodeSnippetExpression(string.Format("Invoke(d => d.{0}({1}))", info.Name, parms));
method.Statements.Add(statement);
target.Members.Add(method);
}
示例3: CreateConstructorParamtersInstances
internal static object[] CreateConstructorParamtersInstances(this IoC ioc, ParameterInfo[] src)
{
return src
.Select(pi => pi.IocParameterIsArray()
? ioc.GetParameterAsArray(pi.GetIocRealType())
: ioc.GetObject(pi.ParameterType)).ToArray();
}
示例4: ConstructorHasAllMethodArgs
private bool ConstructorHasAllMethodArgs(ParameterInfo[] methodArgs, ParameterInfo[] constructorParams)
{
var consArgTypes = constructorParams.Select(a => a.ParameterType).ToList();
var methodArgTypes = methodArgs.Select(a => a.ParameterType).ToList();
return !consArgTypes.Except(methodArgTypes).Any() &&
!methodArgTypes.Except(consArgTypes).Any();
}
示例5: ValidateParameters
private void ValidateParameters(ParameterInfo[] parameters, object[] parameterValues)
{
if (parameters.Length == parameterValues.Length && ParameterTypesMatch(parameters, parameterValues)) return;
var expectedShape = CreateShape(parameters.Select(x => x.ParameterType));
var actualShape = CreateShape(parameterValues.Select((x, index) => x == null ? parameters[index].ParameterType : x.GetType()));
throw new InvalidParadigmExemplarException(string.Format("Invalid paradigm exemplar: expected it to have a shape of {0}, but it had a shape of {1}", expectedShape, actualShape));
}
示例6: GetParameterValues
private static object[] GetParameterValues(TestContext context, ParameterInfo[] parameters)
{
Func<ParameterInfo, int, object> selectFunc =
(parameter, index) =>
{
context.WriteLine("{0} = {1}", parameter.Name, context.DataRow[index]);
return context.DataRow[index];
};
return parameters.Select(selectFunc).ToArray();
}
示例7: CreateParameterExpressions
private static Expression[] CreateParameterExpressions(ParameterInfo[] methodParams, ParameterExpression argsParameter)
{
return methodParams.Select(
(parameter, index) =>
Expression.Convert(
Expression.ArrayIndex(argsParameter, Expression.Constant(index)),
parameter.ParameterType
)
).ToArray();
}
示例8: CreateTypeName
private static string CreateTypeName(string delegateName, ParameterInfo[] parameters)
{
var builder = new StringBuilder();
builder.Append(delegateName);
builder.Append("<");
builder.Append(String.Join(",", parameters.Select(c => c.Name).ToArray()));
builder.Append(">");
return builder.ToString();
}
示例9: GetCallMethodAsyncFuncInternal
private static Delegate GetCallMethodAsyncFuncInternal(Type serviceType, Type argumentType, ParameterInfo[] arguments, MethodInfo method, bool hasReturn)
{
if (arguments.Length > 0 && argumentType == null)
throw new ArgumentException("parameterType can not be null when paras.Length > 0");
var serviceArgument = Expression.Parameter(typeof(object), "service");
var actionArgument = Expression.Parameter(typeof(object), "argument");
var asyncCallbackArgument = Expression.Parameter(typeof(AsyncCallback), "callback");
var stateArgument = Expression.Parameter(typeof(object), "state");
var convertService = Expression.Convert(serviceArgument, serviceType);
var convertArgument = argumentType == null ? null : Expression.Convert(actionArgument, argumentType);
MethodCallExpression call;
if (arguments.Length > 1)
{
if (convertArgument == null)
throw new ArgumentException("argumentType can't be null when arguments.Length > 1");
var callArgs = arguments
.Select(it => (Expression)Expression.Property(convertArgument, it.Name))
.ToList();
callArgs.Add(asyncCallbackArgument);
callArgs.Add(stateArgument);
call = Expression.Call(convertService, method, callArgs);
}
else if (arguments.Length == 1)
{
call = Expression.Call(convertService, method, new Expression[] { convertArgument, asyncCallbackArgument, stateArgument });
}
else
{
call = Expression.Call(convertService, method, new Expression[] { asyncCallbackArgument, stateArgument });
}
var methodArgs = new[] { serviceArgument, actionArgument, asyncCallbackArgument, stateArgument };
LambdaExpression methodLam;
if (hasReturn)
{
var convertCall = Expression.Convert(call, typeof(IAsyncResult));
methodLam = Expression.Lambda(convertCall, methodArgs);
}
else
{
methodLam = Expression.Lambda(call, methodArgs);
}
var methodFunc = methodLam.Compile();
return methodFunc;
}
示例10: HasParameterSignature
/// <summary>
/// Compares the signature of the method with the given parameter types and returns true if
/// all method parameters have the same order and type. Parameter names are not considered.
/// </summary>
/// <returns>True if the supplied parameter type array matches the method parameters array, false otherwise.</returns>
public static bool HasParameterSignature(this MethodBase method, ParameterInfo[] parameters)
{
return method.GetParameters().Select(p => p.ParameterType).SequenceEqual(parameters.Select(p => p.ParameterType));
}
示例11: GetParameterData
private object[] GetParameterData(ParameterInfo[] parameters, Fixture fixture)
{
return parameters
.Select(p => new SpecimenContext(fixture).Resolve(p))
.ToArray();
}
示例12: FormatParameters
private static string FormatParameters(ParameterInfo[] parameters)
{
return string.Join(",", parameters.Select(x => x.ParameterType.Name));
}
示例13: SetSignature
private void SetSignature(Type returnType, ParameterInfo returnParameter, Type[] parameters,
ParameterInfo[] baseMethodParameters)
{
builder.SetSignature(
returnType,
#if FEATURE_EMIT_CUSTOMMODIFIERS
returnParameter.GetRequiredCustomModifiers(),
returnParameter.GetOptionalCustomModifiers(),
#else
null,
null,
#endif
parameters,
#if FEATURE_EMIT_CUSTOMMODIFIERS
baseMethodParameters.Select(x => x.GetRequiredCustomModifiers()).ToArray(),
baseMethodParameters.Select(x => x.GetOptionalCustomModifiers()).ToArray()
#else
null,
null
#endif
);
}
示例14: IdentifierImpl
public IdentifierImpl(string className, string methodName, ParameterInfo[] parameters)
: this(className, methodName, parameters.Select(p => p.Name).ToArray(), ToParameterStringArray(parameters.Select(p => p.ParameterType).ToArray()), false) {}
示例15: BuildParameterList
private List<Parameter> BuildParameterList(ParameterInfo[] parameters, bool checkForExtensionMethods)
{
if (parameters == null || parameters.Length == 0)
return null;
return parameters.Select(a => new Parameter
{
Name = a.Name,
TypeName = GetReadableTypeName(a.ParameterType),
ParameterFlags = GetParameterFlags(a, checkForExtensionMethods)
}).ToList();
}