本文整理汇总了C#中Expression.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.ToList方法的具体用法?C# Expression.ToList怎么用?C# Expression.ToList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Expression
的用法示例。
在下文中一共展示了Expression.ToList方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildOperatorArgumentsList
private void BuildOperatorArgumentsList(IList<Expression> arguments, IMethod method)
{
if (method != null)
{
var parameters = method.Parameters;
Expression[] result = new Expression[parameters.Count];
string[] names = new string[result.Length];
int i = 0;
foreach (var arg in arguments)
{
if (arg is NamedArgumentExpression)
{
NamedArgumentExpression namedArg = (NamedArgumentExpression)arg;
var namedParam = parameters.First(p => p.Name == namedArg.Name);
var index = parameters.IndexOf(namedParam);
result[index] = namedArg.Expression;
names[index] = namedArg.Name;
}
else
{
if (i >= result.Length)
{
var list = result.ToList();
list.AddRange(new Expression[arguments.Count - i]);
var strList = names.ToList();
strList.AddRange(new string[arguments.Count - i]);
result = list.ToArray();
names = strList.ToArray();
}
result[i] = arg;
names[i] = parameters[i].Name;
}
i++;
}
for (i = 0; i < result.Length; i++)
{
if (result[i] == null)
{
var p = parameters[i];
if (p.Type.Kind == TypeKind.Enum)
{
result[i] = new PrimitiveExpression(Helpers.GetEnumValue(this.Emitter, p.Type, p.ConstantValue));
}
else
{
result[i] = new PrimitiveExpression(p.ConstantValue);
}
names[i] = parameters[i].Name;
}
}
this.ArgumentsExpressions = result;
this.ArgumentsNames = names;
this.NamedExpressions = this.CreateNamedExpressions(names, result);
}
else
{
this.ArgumentsExpressions = arguments.ToArray();
}
}
示例2: BuildArgumentsList
private void BuildArgumentsList(IList<Expression> arguments)
{
Expression paramsArg = null;
string paramArgName = null;
var resolveResult = this.ResolveResult;
if (resolveResult != null)
{
var parameters = resolveResult.Member.Parameters;
var resolvedMethod = resolveResult.Member as IMethod;
var invocationResult = resolveResult as CSharpInvocationResolveResult;
int shift = 0;
if (resolvedMethod != null && invocationResult != null &&
resolvedMethod.IsExtensionMethod && invocationResult.IsExtensionMethodInvocation)
{
shift = 1;
this.ThisName = resolvedMethod.Parameters[0].Name;
this.IsExtensionMethod = true;
}
Expression[] result = new Expression[parameters.Count - shift];
string[] names = new string[result.Length];
int i = 0;
foreach (var arg in arguments)
{
if (arg is NamedArgumentExpression)
{
NamedArgumentExpression namedArg = (NamedArgumentExpression)arg;
var namedParam = parameters.First(p => p.Name == namedArg.Name);
var index = parameters.IndexOf(namedParam);
result[index] = namedArg.Expression;
names[index] = namedArg.Name;
}
else
{
if (paramsArg == null && (parameters.Count > (i + shift)) && parameters[i + shift].IsParams)
{
if (resolvedMethod.DeclaringTypeDefinition == null || !this.Emitter.Validator.IsIgnoreType(resolvedMethod.DeclaringTypeDefinition))
{
paramsArg = arg;
}
paramArgName = parameters[i + shift].Name;
}
if (i >= result.Length)
{
var list = result.ToList();
list.AddRange(new Expression[arguments.Count - i]);
var strList = names.ToList();
strList.AddRange(new string[arguments.Count - i]);
result = list.ToArray();
names = strList.ToArray();
}
result[i] = arg;
names[i] = (i + shift) < parameters.Count ? parameters[i + shift].Name : paramArgName;
}
i++;
}
for (i = 0; i < result.Length; i++)
{
if (result[i] == null)
{
var p = parameters[i + shift];
if (p.Type.Kind == TypeKind.Enum)
{
result[i] = new PrimitiveExpression(Helpers.GetEnumValue(this.Emitter, p.Type, p.ConstantValue));
}
else
{
result[i] = new PrimitiveExpression(p.ConstantValue);
}
names[i] = parameters[i + shift].Name;
}
}
this.ArgumentsExpressions = result;
this.ArgumentsNames = names;
this.ParamsExpression = paramsArg;
this.NamedExpressions = this.CreateNamedExpressions(names, result);
}
else
{
this.ArgumentsExpressions = arguments.ToArray();
}
}