本文整理汇总了C#中System.Reflection.MethodBase.GetParametersCached方法的典型用法代码示例。如果您正苦于以下问题:C# MethodBase.GetParametersCached方法的具体用法?C# MethodBase.GetParametersCached怎么用?C# MethodBase.GetParametersCached使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodBase
的用法示例。
在下文中一共展示了MethodBase.GetParametersCached方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Bind
public static ParameterAssignment Bind(MethodBase method, string parameter, Expression expression)
{
// NB: This overload is needed for the compiler to emit factory calls;
// we can't emit a `ldtoken` instruction to obtain a ParameterInfo.
ContractUtils.RequiresNotNull(method, nameof(method));
ContractUtils.RequiresNotNull(parameter, nameof(parameter));
var parameterInfo = default(ParameterInfo);
foreach (var candidate in method.GetParametersCached())
{
if (candidate.Name == parameter)
{
parameterInfo = candidate;
break;
}
}
if (parameterInfo == null)
{
throw Error.ParameterNotDefinedForMethod(parameter, method.Name);
}
return Bind(parameterInfo, expression);
}
示例2: IsCompatible
private static bool IsCompatible(MethodBase m, Expression[] args)
{
ParameterInfo[] parms = m.GetParametersCached();
if (parms.Length != args.Length)
return false;
for (int i = 0; i < args.Length; i++)
{
Expression arg = args[i];
ContractUtils.RequiresNotNull(arg, "argument");
Type argType = arg.Type;
Type pType = parms[i].ParameterType;
if (pType.IsByRef)
{
pType = pType.GetElementType();
}
if (!TypeUtils.AreReferenceAssignable(pType, argType) &&
!(TypeUtils.IsSameOrSubclass(typeof(LambdaExpression), pType) && pType.IsAssignableFrom(arg.GetType())))
{
return false;
}
}
return true;
}
示例3: EmitArguments
/// <summary>
/// Emits arguments to a call, and returns an array of write-backs that
/// should happen after the call. For emitting dynamic expressions, we
/// need to skip the first parameter of the method (the call site).
/// </summary>
private List<WriteBack> EmitArguments(MethodBase method, IArgumentProvider args, int skipParameters)
{
ParameterInfo[] pis = method.GetParametersCached();
Debug.Assert(args.ArgumentCount + skipParameters == pis.Length);
var writeBacks = new List<WriteBack>();
for (int i = skipParameters, n = pis.Length; i < n; i++)
{
ParameterInfo parameter = pis[i];
Expression argument = args.GetArgument(i - skipParameters);
Type type = parameter.ParameterType;
if (type.IsByRef)
{
type = type.GetElementType();
WriteBack wb = EmitAddressWriteBack(argument, type);
if (wb != null)
{
writeBacks.Add(wb);
}
}
else
{
EmitExpression(argument);
}
}
return writeBacks;
}
示例4: GetParametersForValidation
private static ParameterInfo[] GetParametersForValidation(MethodBase method, ExpressionType nodeKind) {
ParameterInfo[] pis = method.GetParametersCached();
if (nodeKind == ExpressionType.Dynamic) {
pis = pis.RemoveFirst(); // ignore CallSite argument
}
return pis;
}
示例5: MarkRefArgs
/// <summary>
/// Marks child expressions representing arguments bound to parameters of
/// the specified <paramref name="method"/> as ByRef values if needed.
/// </summary>
/// <param name="method">
/// The method containing the parameters bound to the arguments held by
/// child expressions tracked by this rewriter.
/// </param>
/// <param name="startIndex">
/// The index of the child expression representing the first argument. This
/// value is typically 0 for static methods and 1 for instance methods.
/// </param>
internal void MarkRefArgs(MethodBase method, int startIndex)
{
var parameters = method.GetParametersCached();
for (int i = 0, n = parameters.Length; i < n; i++)
{
if (parameters[i].ParameterType.IsByRef)
{
MarkRef(startIndex + i);
}
}
}
示例6: GetParameterBindings
public static ReadOnlyCollection<ParameterAssignment> GetParameterBindings(MethodBase method, IEnumerable<Expression> expressions)
{
return GetParameterBindings(method.GetParametersCached(), expressions);
}
示例7: ValidateParameterBindings
public static void ValidateParameterBindings(MethodBase method, ReadOnlyCollection<ParameterAssignment> argList, bool extensionMethod = false)
{
ValidateParameterBindings(method, method.GetParametersCached(), argList, extensionMethod);
}