本文整理汇总了C#中System.Reflection.ParameterInfo.Where方法的典型用法代码示例。如果您正苦于以下问题:C# ParameterInfo.Where方法的具体用法?C# ParameterInfo.Where怎么用?C# ParameterInfo.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.ParameterInfo
的用法示例。
在下文中一共展示了ParameterInfo.Where方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckIfParametersEquals
private static bool CheckIfParametersEquals(ParameterInfo[] parameters, params Type[] targets)
{
if (parameters.Length != targets.Length)
return false;
return !parameters.Where((each, index) => each.ParameterType != targets[index]).Any();
}
示例2: IsMatch
private static bool IsMatch(ParameterInfo[] parameters, Type[] parameterTypes)
{
if (parameterTypes == null)
parameterTypes = EmptyTypes;
if (parameters.Length != parameterTypes.Length)
return false;
return !parameters.Where((t, i) => t.ParameterType != parameterTypes[i]).Any();
}
示例3: CollectArguments
/// <summary>
/// Collect the arguments from given parameter types.
/// </summary>
/// <param name="dependencyResolver">The depenency resolver.</param>
/// <param name="parameters">The parameters.</param>
/// <param name="resolutionContext">The resolution context.</param>
/// <returns>The collected arguments.</returns>
public object[] CollectArguments(Func<Type, object> dependencyResolver, ParameterInfo[] parameters, ResolutionContext resolutionContext)
{
var finalArguments = new List<object>();
var dependencyParameters =
parameters.Where(
p =>
resolutionContext.RegistrationContainer.HasRegistration(p.ParameterType)
||
resolutionContext.RegistrationContainer.IsSupportedByRegistrationSource(p.ParameterType));
Func<object, ParameterInfo, bool> argumentSelector = (argument, parameter) => parameter.ParameterType.IsInstanceOfType(argument);
var runtimeArguments = resolutionContext.RuntimeArguments;
var arguments = resolutionContext.Arguments;
// Priority from heighest: Runtime arguments -> named / anonymous, Arguments -> named / anonymous / depdendency parameters.
foreach (ParameterInfo parameter in parameters)
{
ParameterInfo localParameter = parameter;
if (runtimeArguments.NamedArguments != null && runtimeArguments.NamedArguments.ContainsKey(parameter.Name))
{
finalArguments.Add(runtimeArguments.NamedArguments[parameter.Name]);
continue;
}
if (runtimeArguments.AnonymousArguments != null && runtimeArguments.AnonymousArguments.Any(argument => argumentSelector(argument, localParameter)))
{
finalArguments.Add(runtimeArguments.AnonymousArguments.FirstOrDefault(argument => argumentSelector(argument, localParameter)));
continue;
}
if (arguments.NamedArguments != null && arguments.NamedArguments.ContainsKey(parameter.Name))
{
finalArguments.Add(arguments.NamedArguments[parameter.Name]);
continue;
}
if (arguments.AnonymousArguments != null && arguments.AnonymousArguments.Any(argument => argumentSelector(argument, localParameter)))
{
finalArguments.Add(arguments.AnonymousArguments.FirstOrDefault(argument => argumentSelector(argument, localParameter)));
continue;
}
if (dependencyParameters.Contains(parameter))
{
finalArguments.Add(dependencyResolver(parameter.ParameterType));
continue;
}
}
return finalArguments.ToArray();
}
示例4: WriteAttributeForEach
//===========================================================================================
private void WriteAttributeForEach(IndentedTextWriter writer, ParameterInfo[] allParameters)
{
ParameterInfo[] parameters = allParameters.Where(p => _GraphicsMagickNET.GetXsdAttributeType(p) != null).ToArray();
if (parameters.Length == 0)
return;
parameters = parameters.OrderBy(p => p.Name).ToArray();
writer.WriteLine("for each(XmlAttribute^ attribute in element->Attributes)");
WriteStartColon(writer);
if (parameters.DistinctBy(p => _GraphicsMagickNET.GetCppTypeName(p)).Count() == 1)
{
writer.Write("arguments[attribute->Name] = _Variables->GetValue<");
writer.Write(_GraphicsMagickNET.GetCppTypeName(parameters[0]));
writer.WriteLine(">(attribute);");
}
else
{
for (int i = 0; i < parameters.Length; i++)
{
string xsdName = _GraphicsMagickNET.GetXsdName(parameters[i]);
if (i > 0)
writer.Write("else ");
writer.Write("if (attribute->Name == \"");
writer.Write(xsdName);
writer.WriteLine("\")");
writer.Indent++;
writer.Write("arguments[\"");
writer.Write(xsdName);
writer.Write("\"] = ");
WriteGetAttributeValue(writer, _GraphicsMagickNET.GetCppTypeName(parameters[i]), xsdName);
writer.Indent--;
}
}
WriteEndColon(writer);
}
示例5: WriteAttributeForEach
private void WriteAttributeForEach(ParameterInfo[] allParameters)
{
ParameterInfo[] parameters = allParameters.Where(p => MagickScriptTypes.GetXsdAttributeType(p) != null).ToArray();
if (parameters.Length == 0)
return;
parameters = parameters.OrderBy(p => p.Name).ToArray();
WriteLine("foreach (XmlAttribute attribute in element.Attributes)");
WriteStartColon();
if (parameters.DistinctBy(p => GetName(p)).Count() == 1)
{
Write("arguments[attribute.Name] = Variables.GetValue<");
Write(GetName(parameters[0]));
WriteLine(">(attribute);");
}
else
{
for (int i = 0; i < parameters.Length; i++)
{
string xsdName = MagickScriptTypes.GetXsdName(parameters[i]);
if (i > 0)
Write("else ");
Write("if (attribute.Name == \"");
Write(xsdName);
WriteLine("\")");
Indent++;
Write("arguments[\"");
Write(xsdName);
Write("\"] = ");
WriteGetAttributeValue(GetName(parameters[i]));
Indent--;
}
}
WriteEndColon();
}
示例6: EmitOutputParameters
/// <summary>
/// Copies fields from the temporary output parameters structure to the output parameters object specified by the caller.
/// </summary>
/// <param name="parameters">The list of parameters.</param>
/// <param name="parameterWrapper">The local variable for the temporary object.</param>
/// <param name="mIL">The ILGenerator to use.</param>
private static void EmitOutputParameters(ParameterInfo[] parameters, LocalBuilder parameterWrapper, ILGenerator mIL)
{
foreach (var outputParameter in parameters.Where(p => p.IsOut))
{
mIL.Emit(OpCodes.Ldarg, outputParameter.Position + 1);
mIL.Emit(OpCodes.Ldloc, parameterWrapper.LocalIndex);
var fields = parameterWrapper.LocalType.GetFields();
mIL.Emit(OpCodes.Ldfld, fields[outputParameter.Position]);
mIL.Emit(OpCodes.Stobj, outputParameter.ParameterType.GetElementType());
}
}
示例7: ParametersMatch
private static bool ParametersMatch(ParameterInfo[] methodParameters, object[] parameters)
{
return methodParameters.Length == parameters.Length
&& !methodParameters.Where((mp, i) => !mp.ParameterType.IsInstanceOfType(parameters[i])).Any();
}
示例8: WriteElementForEach
//===========================================================================================
private void WriteElementForEach(IndentedTextWriter writer, ParameterInfo[] allParameters)
{
ParameterInfo[] parameters = allParameters.Where(p => _GraphicsMagickNET.GetXsdAttributeType(p) == null).ToArray();
if (parameters.Length == 0)
return;
writer.WriteLine("for each(XmlElement^ elem in element->SelectNodes(\"*\"))");
WriteStartColon(writer);
if (parameters.DistinctBy(p => _GraphicsMagickNET.GetCppTypeName(p)).Count() == 1)
{
writer.Write("arguments[elem->Name] = ");
WriteCreateMethod(writer, _GraphicsMagickNET.GetCppTypeName(parameters[0]));
writer.WriteLine("(elem);");
}
else
{
for (int i = 0; i < parameters.Length; i++)
{
string xsdName = _GraphicsMagickNET.GetXsdName(parameters[i]);
if (i > 0)
writer.Write("else ");
writer.Write("if (elem->Name == \"");
writer.Write(xsdName);
writer.WriteLine("\")");
writer.Indent++;
writer.Write("arguments[\"");
writer.Write(xsdName);
writer.Write("\"] = ");
WriteCreateMethod(writer, _GraphicsMagickNET.GetCppTypeName(parameters[i]));
writer.WriteLine("(elem);");
writer.Indent--;
}
}
WriteEndColon(writer);
}
示例9: WriteElementForEach
private void WriteElementForEach(ParameterInfo[] allParameters)
{
ParameterInfo[] parameters = allParameters.Where(p => MagickScriptTypes.GetXsdAttributeType(p) == null).ToArray();
if (parameters.Length == 0)
return;
WriteLine("foreach (XmlElement elem in element.SelectNodes(\"*\"))");
WriteStartColon();
if (parameters.DistinctBy(p => GetName(p)).Count() == 1)
{
Write("arguments[elem.Name] = ");
WriteCreateMethod(GetName(parameters[0]));
WriteLine("(elem);");
}
else
{
for (int i = 0; i < parameters.Length; i++)
{
string xsdName = MagickScriptTypes.GetXsdName(parameters[i]);
if (i > 0)
Write("else ");
Write("if (elem.Name == \"");
Write(xsdName);
WriteLine("\")");
Indent++;
Write("arguments[\"");
Write(xsdName);
Write("\"] = ");
WriteCreateMethod(GetName(parameters[i]));
WriteLine("(elem);");
Indent--;
}
}
WriteEndColon();
}
示例10: PrepareParams
protected override ParameterInfo[] PrepareParams(ParameterInfo[] parameters)
{
return parameters.Where(p => p.ParameterType != typeof(System.Web.Mvc.FormCollection) && !p.ParameterType.IsSubclassOf(typeof(System.Web.Mvc.FormCollection))).ToArray();
}