本文整理汇总了C#中System.Reflection.ParameterInfo.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# ParameterInfo.FirstOrDefault方法的具体用法?C# ParameterInfo.FirstOrDefault怎么用?C# ParameterInfo.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.ParameterInfo
的用法示例。
在下文中一共展示了ParameterInfo.FirstOrDefault方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitSpecialParameter
/// <summary>
/// Attempts to emit the code to push a special parameter by looking it up in the interface parameters.
/// If the parameter is defined, this emits a Ldarg operation.
/// </summary>
/// <param name="il">The ILGenerator to use.</param>
/// <param name="parameterName">The name of the special parameter.</param>
/// <param name="interfaceParameters">The parameters on the interface method.</param>
/// <param name="executeParameters">The parameters on the execute method.</param>
/// <returns>True if a parameter was emitted.</returns>
private static bool EmitSpecialParameter(ILGenerator il, string parameterName, ParameterInfo[] interfaceParameters, ParameterInfo[] executeParameters)
{
// attempt to find the parameter on the interface method
var interfaceParameter = interfaceParameters.FirstOrDefault(p => String.Compare(p.Name, parameterName, StringComparison.OrdinalIgnoreCase) == 0);
if (interfaceParameter == null)
return false;
// attempt to find the parameter on the execute method
var executeParameter = executeParameters.FirstOrDefault(p => String.Compare(p.Name, parameterName, StringComparison.OrdinalIgnoreCase) == 0);
if (executeParameter == null)
return false;
// the types must match
if (interfaceParameter.ParameterType != executeParameter.ParameterType)
throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Special Parameter {0} must have type {1}", parameterName, executeParameter.ParameterType.FullName));
// the parameter list is 0-based, but 0 is the this pointer, so we add one
il.Emit(OpCodes.Ldarg, (int)interfaceParameter.Position + 1);
return true;
}