本文整理汇总了C#中System.Linq.Expressions.Expression.Select方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.Select方法的具体用法?C# Expression.Select怎么用?C# Expression.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq.Expressions.Expression
的用法示例。
在下文中一共展示了Expression.Select方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CallFunction
static Expression CallFunction(string name, Expression[] parameters)
{
var methodInfo = typeof (Math).GetMethod(name, parameters.Select(e => e.Type).ToArray());
if (methodInfo == null)
throw new ParseException(string.Format("Function '{0}({1})' does not exist.", name,
string.Join(",", parameters.Select(e => e.Type.Name))));
return Expression.Call(methodInfo, parameters);
}
示例2: createCallSiteInvokeTarget
/// <summary>
/// Creates a call site.
/// </summary>
/// <param name="createBinderMethodName">
/// The name of the method
/// </param>
/// <param name="instance"></param>
/// <param name="targetArgExprs"></param>
/// <remarks>
/// <ul>
/// <li>
/// Determines if a delegate has been created in _assemblyGenerator yet that matches the
/// operation and signature of the call site to be created.
/// </li>
/// <li>
/// Uses existing delegate or defines a new delegate if one was not identified.
/// </li>
/// <li>
/// Creates a field in the dynamic type for storing the call site
/// </li>
/// <li>
/// Emits code to check if the field has been initialized with a binder yet, and if not initializes it
/// using the HappyLanguageContext method identified by createBinderMethodName, passing the arguments
/// identified by createBinderMethodArgExprs.
/// </li>
/// <li>
/// Emits code to invoke the callsite's target.
/// </li>
/// </ul>
/// </remarks>
/// <returns></returns>
Expression createCallSiteInvokeTarget(string createBinderMethodName, Expression[] createBinderMethodArgExprs, Expression[] targetArgExprs)
{
var argTypes = new List<Type> { typeof(CallSite) };
argTypes.AddRange(targetArgExprs.Select(a => a.Type));
Type delegateType = getDelegateType(createBinderMethodName, typeof(object), argTypes.ToArray());
Expression callSiteExpr = makeCallSiteField(delegateType);
MethodInfo createBinderMethodInfo = typeof(HappyLanguageContext).GetMethod(createBinderMethodName, BindingFlags.Public | BindingFlags.Instance);
DebugAssert.IsNotNull(createBinderMethodInfo, "'{0}' is not a valid member of HappyLanguageContext");
var expectedArgumentTypes = createBinderMethodInfo.GetParameters().Select(a => a.ParameterType).ToArray();
#if DEBUG
DebugAssert.AreEqual(expectedArgumentTypes.Length, createBinderMethodArgExprs.Length,
"Incorrect number of expressions supplied as create binder method arugments for HappyLanguageContext.{0} " +
"Expected {1} got {2}", createBinderMethodName, expectedArgumentTypes.Length, createBinderMethodArgExprs.Length);
for(int i = 0; i < expectedArgumentTypes.Length; ++i)
{
if (!createBinderMethodArgExprs[i].Type.IsAssignableFrom(expectedArgumentTypes[i]))
DebugAssert.Fail("Argument {0} ( of type {1}) in call to HappyLanguageContext.{2} was not asssignable from {3}",
i + 1, createBinderMethodArgExprs[i].Type.FullName, createBinderMethodName, expectedArgumentTypes[i].FullName);
}
#endif
Expression initCallSiteExpr = getInitCallSiteExpr(callSiteExpr, createBinderMethodInfo, createBinderMethodArgExprs);
List<Expression> finalArgs = new List<Expression> { callSiteExpr};
finalArgs.AddRange(targetArgExprs);
Expression callTargetExpr = Expression.Invoke(Expression.Field(callSiteExpr, "Target"), finalArgs);
return Expression.Block(initCallSiteExpr, callTargetExpr);
}
示例3: MergeTest
public void MergeTest()
{
var expressions = new Expression<Func<Test, Test>>[]
{
t => new Test {A = t.A},
t => new Test {B = t.B},
t => new Test {C = t.C},
t => new Test {D = t.D},
};
var oneParamExpressions = expressions.Select(x => Expression.Lambda<Func<Test, Test>>(x.Body, expressions[0].Parameters[0])).ToList();
ParameterExpression pe;
_parameterRebinder.Setup(x => x.ReplaceParametersByFirst(expressions)).Returns(oneParamExpressions.Select(x => x.Body)).Verifiable();
var result = Create().Merge<Test>(expressions, out pe);
Assert.AreEqual(ExpressionType.MemberInit, result.NodeType);
var mie = result as MemberInitExpression;
var ci = mie.NewExpression.Constructor;
Assert.AreEqual(ci, typeof (Test).GetConstructors()[0]);
Assert.AreEqual(4, mie.Bindings.Count);
Assert.AreEqual(1, mie.Bindings.Count(b => b.Member == typeof (Test).GetProperty("A")));
Assert.AreEqual(1, mie.Bindings.Count(b => b.Member == typeof (Test).GetProperty("B")));
Assert.AreEqual(1, mie.Bindings.Count(b => b.Member == typeof (Test).GetProperty("C")));
Assert.AreEqual(1, mie.Bindings.Count(b => b.Member == typeof (Test).GetProperty("D")));
}
示例4: MergeUndefinedExpressionTest
public void MergeUndefinedExpressionTest()
{
ParameterExpression pe;
var expressions = new Expression<Func<Test, int>>[]
{
t => 1
};
_parameterRebinder.Setup(x => x.ReplaceParametersByFirst(expressions)).Returns(expressions.Select(x => x.Body)).Verifiable();
Create().Merge<Test>(expressions, out pe);
}
示例5: MethodCall
static Expression MethodCall(string name, Expression[] parameters)
{
var methodInfo = (parameters != null) ? typeof(Order).GetMethod(name, parameters.Select(e => e.Type).ToArray())
: typeof(Order).GetMethod(name);
if (methodInfo == null)
{
throw new ParseException(string.Format("Function '{0}({1})' does not exist.",
name,
string.Join(", ", parameters.Select(e => e.Type.Name))));
}
return Expression.Call(Expression.Parameter(typeof(Order), "order"), methodInfo, parameters);
}
示例6: Gather
public static ReferencedRelatedObjectPropertyGathererResults Gather(DataAccessModel model, Expression[] expressions, ParameterExpression sourceParameterExpression, bool forProjection)
{
var gatherer = new ReferencedRelatedObjectPropertyGatherer(model, sourceParameterExpression, forProjection);
var reducedExpressions = expressions.Select(gatherer.Visit).ToArray();
return new ReferencedRelatedObjectPropertyGathererResults
{
ReducedExpressions = reducedExpressions,
ReferencedRelatedObjectByPath = gatherer.results,
RootExpressionsByPath = gatherer.rootExpressionsByPath,
IncludedPropertyInfoByExpression = gatherer
.includedPropertyInfos
.GroupBy(c => c.RootExpression)
.ToDictionary(c => c.Key, c => c.ToList())
};
}
示例7: CreateBodyExpression
private static Expression CreateBodyExpression(
MethodInfo delegateMethod, DelegateCallInterceptedEventRaiser eventRaiser, Expression[] parameterExpressions)
{
var parameterExpressionsCastToObject =
parameterExpressions.Select(x => Expression.Convert(x, typeof(object))).Cast<Expression>().ToArray();
Expression body = Expression.Call(
Expression.Constant(eventRaiser),
DelegateCallInterceptedEventRaiser.RaiseMethod,
new Expression[] { Expression.NewArrayInit(typeof(object), parameterExpressionsCastToObject) });
if (!delegateMethod.ReturnType.Equals(typeof(void)))
{
body = Expression.Convert(body, delegateMethod.ReturnType);
}
return body;
}
示例8: AllPublicMethodsCheckIfPageHasBeenInitialized
public void AllPublicMethodsCheckIfPageHasBeenInitialized()
{
var publicMethodCallExpressions = new Expression<Action<BasePage>>[]
{
x => x.ExecuteScript("return 1;"),
x => x.ExecuteAsyncScript("return 2;"),
x => x.FindElement(By.Id("start")),
x => x.FindElements(By.ClassName("end"))
};
var page = new SimplePageForTest();
var methods = typeof(BasePage).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
.Where(x => !x.IsSpecialName);
var coveredMethods = publicMethodCallExpressions.Select(x => x.Body).Cast<MethodCallExpression>().Select(x => x.Method.Name);
var uncoveredMethods = methods.Where(x => !coveredMethods.Contains(x.Name)).Select(x => x.Name).ToArray();
Assert.IsEmpty(uncoveredMethods, "'{0}' methods does not covered. Please add expressions to test them.", string.Join(", ", uncoveredMethods));
foreach (var publicMethodCallExpression in publicMethodCallExpressions)
{
Assert.Throws<PageInitializationException>(() => publicMethodCallExpression.Compile()(page));
}
}
示例9: SeekFunction
internal static Function SeekFunction(string name, Expression[] arguments, bool seekInsideObservable = false)
{
var qualifiedName = string.Format("{0}({1})", name, arguments.Count());
// TODO: Handle missing function events
var function = ExpressionsHelper.functions.Where(f => f.FunctionName.Equals(qualifiedName)
&& arguments.Select(a =>
{
var type = a.Type.GetFirstObservableGenericType();
if (type == null || seekInsideObservable == false)
{
return a.Type;
}
return type;
})
.SequenceEqual(f.Parameters
.Select(p => p.Type))).FirstOrDefault();
return function;
}
示例10: CreateTupleSelector
private static Expression CreateTupleSelector(
Expression body,
Expression[] memberSelectors)
{
Type[] memberTypes = memberSelectors.Select(e => e.Type).ToArray();
Type tupleType = TupleTypeHelper.CreateTupleType(memberTypes);
var helper = new TupleKeyInfoHelper(tupleType);
body = helper.CreateKeyFactoryExpression(memberSelectors);
return body;
}
示例11: GetArgTypesString
private static string GetArgTypesString(Expression[] arguments) {
StringBuilder argTypesStr = new StringBuilder();
var isFirst = true;
argTypesStr.Append("(");
foreach (var t in arguments.Select(arg => arg.Type)) {
if (!isFirst) {
argTypesStr.Append(", ");
}
argTypesStr.Append(t.Name);
isFirst = false;
}
argTypesStr.Append(")");
return argTypesStr.ToString();
}
示例12: VisitExpressions
private Variable[] VisitExpressions(Expression[] expressions)
{
return expressions.Select(Visit).ToArray();
//this.Out(open);
//if (expressions != null)
//{
// bool flag = true;
// foreach (T local in expressions)
// {
// if (flag)
// {
// flag = false;
// }
// else
// {
// this.Out(", ");
// }
// this.Visit(local);
// }
//}
//this.Out(close);
}