本文整理汇总了C#中System.Linq.Expressions.ParameterExpression类的典型用法代码示例。如果您正苦于以下问题:C# ParameterExpression类的具体用法?C# ParameterExpression怎么用?C# ParameterExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParameterExpression类属于System.Linq.Expressions命名空间,在下文中一共展示了ParameterExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateCopyComplexArrayTypeFieldExpression
/// <summary>
/// Creates an expression that copies a coplex array value from the source to the target. The value will be cloned as well using the dictionary to reuse already cloned objects.
/// </summary>
/// <param name="sourceField"></param>
/// <param name="targetField"></param>
/// <param name="type"></param>
/// <param name="objectDictionary"></param>
/// <returns></returns>
internal static Expression CreateCopyComplexArrayTypeFieldExpression(Expression sourceField, Expression targetField, Type type, ParameterExpression objectDictionary) {
return Expression.IfThenElse(
Expression.Call(objectDictionary, _dictionaryContainsKey, sourceField),
Expression.Assign(targetField, Expression.Convert(Expression.Call(objectDictionary, _dictionaryGetItem, sourceField), type)),
Expression.Assign(targetField, Expression.Convert(Expression.Call(Expression.Call(_getTypeClonerMethodInfo, Expression.Call(sourceField, _getTypeMethodInfo)), _invokeMethodInfo, sourceField, objectDictionary), type))
);
}
示例2: CompileBulkImporter
public override Expression CompileBulkImporter(EnumStorage enumStorage, Expression writer, ParameterExpression document, ParameterExpression alias, ParameterExpression serializer)
{
var method = writeMethod.MakeGenericMethod(typeof(string));
var dbType = Expression.Constant(DbType);
return Expression.Call(writer, method, alias, dbType);
}
示例3: ExpressionParser
public ExpressionParser(ParameterExpression[] parameters, string expression, object[] values)
{
if (expression == null)
{
throw new ArgumentNullException("expression");
}
if (keywords == null)
{
keywords = CreateKeywords();
}
this.symbols = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
this.literals = new Dictionary<Expression, string>();
if (parameters != null)
{
this.ProcessParameters(parameters);
}
if (values != null)
{
this.ProcessValues(values);
}
this.text = expression;
this.textLen = this.text.Length;
this.SetTextPos(0);
this.NextToken();
}
示例4: VisitParameter
protected override Expression VisitParameter(ParameterExpression node)
{
if (_expName == null)
_expName = node.Name;
return node.Name == _expName && node.Type == _parameterExpression.Type ? _parameterExpression : node;
}
示例5: CreateCall
private static Expression CreateCall(MethodInfo method, ParameterExpression handler, ParameterExpression context, Type handlerType)
{
if (method.IsGenericMethod)
{
var handlerParameterType = method.GetParameters()[0].ParameterType;
if (handlerParameterType.IsGenericType)
{
var @interface =
handlerType.GetInterfaces().FirstOrDefault(
i =>
i.IsGenericType &&
i.GetGenericTypeDefinition() == handlerParameterType.GetGenericTypeDefinition());
if (@interface != null)
{
method = method.MakeGenericMethod(@interface.GetGenericArguments().Single());
}
}
else
{
// bind handler as generic type?
method = method.MakeGenericMethod(typeof(object));
//Debugger.Break();
}
}
return Expression.Call(method, handler, context);
}
示例6: Resolve
public override Expression Resolve (ParameterExpression inputParameter, Expression expressionToBeResolved, ClauseGenerationContext clauseGenerationContext)
{
ArgumentUtility.CheckNotNull ("inputParameter", inputParameter);
ArgumentUtility.CheckNotNull ("expressionToBeResolved", expressionToBeResolved);
return Source.Resolve (inputParameter, expressionToBeResolved, clauseGenerationContext);
}
示例7: ProjectionBuilder
/// <summary>
/// Initializes a new instance of the <see cref="MongoWhereClauseExpressionTreeVisitor"/> class.
/// </summary>
/// <param name="configuration">The configuration.</param>
private ProjectionBuilder(IMappingStore mappingStore, ParameterExpression documentParameter)
{
this.mappingStore = mappingStore;
this.resultObjectMappingParameter = documentParameter;
this.fields = new Document();
this.memberNames = new Stack<string>();
}
示例8: VisitParameter
protected override Expression VisitParameter(ParameterExpression p)
{
if(p.Type == _elementType)
return new FieldExpression(p, _alias, "*");
return base.VisitParameter(p);
}
示例9: ToLinqExpression
// TODO: to be tested
public override Expression ToLinqExpression( IQueryable queryable, ParameterExpression parameterExpression, string propertyName )
{
if( queryable == null )
throw new ArgumentNullException( "queryable" );
if( parameterExpression == null )
throw new ArgumentNullException( "parameterExpression" );
if( String.IsNullOrEmpty( propertyName ) )
{
if( propertyName == null )
throw new ArgumentNullException( "propertyName" );
throw new ArgumentException( "PropertyName must not be empty.", "propertyName" );
}
string queriedValue = this.Value as string;
if( queriedValue == null )
queriedValue = string.Empty;
else
queriedValue = queriedValue.Remove( queriedValue.IndexOf( '*' ) );
return queryable.CreateEndsWithExpression( parameterExpression, propertyName, queriedValue );
}
示例10: Optimize
/**
* приводит лямбду (x, y, ...) => ... к виду: (x, y, ...) => fn(p, q, ...)
* где fn - оптимизированная лямбда, p, q - предварительно вычисленные выражения
*
* пример:
* Func<int, int, Func<int, int, int, int>, int> fn = (int x, int y, Func<int, int, int, int> Foo) => Foo(F(x), F(y), F(2 * y));
* Func<int, int, int> optimizedLambda = (int x, int y) => fn(1, 2, (int p, int q, int l) => p > q ? p : (p < l ? l : q));
*/
public Expression Optimize(LambdaExpression lambda, string functionName)
{
if (_methodCalls != null)
_methodCalls.Clear();
else
_methodCalls = new Dictionary<string, MethodCall>();
_innerLambdaParams = new List<Expression>();
_functionName = functionName;
// получаем оптимизированную лямбду
Expression fn = BuildInnerLambda(lambda);
// копируем параметры для новой лямбды
ParameterExpression[] parameters = new ParameterExpression[lambda.Parameters.Count];
lambda.Parameters.CopyTo(parameters, 0);
// собираем новую лямбду
Expression optimizedLambda = Expression.Lambda(
Expression.Invoke(fn, _innerLambdaParams),
parameters
);
return optimizedLambda;
}
示例11: CreateQuery
//Func<Type, IEnumerable<object>> fnGetObjects;
#region CreateQuery
/// <summary>
/// called during deserialization.
/// </summary>
/// <param name="elementType"></param>
/// <returns></returns>
public dynamic CreateQuery(Type elementType)
{
dynamic ienumerable = this.fnGetObjects(elementType);
Type enumerableType = ienumerable.GetType();
if (!typeof(IEnumerable<>).MakeGenericType(elementType).IsAssignableFrom(enumerableType))
{
ienumerable = Enumerable.ToArray(LinqHelper.CastToGenericEnumerable(ienumerable, elementType));
//throw new InvalidOperationException(string.Format("Return value Type is {1}. Expected: {0}", typeof(IEnumerable<>).MakeGenericType(elementType), ienumerable.GetType()));
}
IQueryable queryable = Queryable.AsQueryable(ienumerable);
IQueryProvider provider = (IQueryProvider)queryable.Provider;
Type queryType = typeof(Query<>).MakeGenericType(elementType);
ConstructorInfo ctor = queryType.GetConstructors()[2];//Query(IQueryProvider provider, Expression expression)
ParameterExpression[] parameters = new ParameterExpression[]
{
Expression.Parameter(typeof(IQueryProvider)),
Expression.Parameter(typeof(Expression))
};
NewExpression newexpr = Expression.New(ctor, parameters);
LambdaExpression lambda = Expression.Lambda(newexpr, parameters);
var newFn = lambda.Compile();
dynamic query = newFn.DynamicInvoke(new object[] { provider, Expression.Constant(queryable) });
return query;
}
示例12: ExpressionBuilderParameters
public ExpressionBuilderParameters(ParameterExpression[] parameters, IQueryProvider queryProvider, Type elementType, IXmlNamespaceResolver namespaceResolver, bool mayRootPathBeImplied, IOperatorImplementationProvider operatorImplementationProvider, Func<Type, IXmlNamespaceResolver, XPathTypeNavigator> navigatorCreator=null)
{
Debug.Assert(parameters!=null);
if (parameters==null)
throw new ArgumentNullException("parameters");
Debug.Assert(parameters.Length>0);
if (parameters.Length==0)
throw new ArgumentException(
string.Format(
CultureInfo.CurrentCulture,
SR.ArrayShouldHaveElementsException,
1,
parameters.Length
),
"parameters"
);
Debug.Assert(queryProvider!=null);
if (queryProvider==null)
throw new ArgumentNullException("queryProvider");
Debug.Assert(elementType!=null);
if (elementType==null)
throw new ArgumentNullException("elementType");
Parameters=new ReadOnlyCollection<ParameterExpression>(parameters);
ElementType=elementType;
QueryProvider=queryProvider;
NamespaceResolver=namespaceResolver;
MayRootPathBeImplied=mayRootPathBeImplied;
OperatorImplementationProvider=operatorImplementationProvider;
NavigatorCreator=navigatorCreator;
}
示例13: ClosureExpression
public ClosureExpression(Ast.PythonVariable/*!*/ variable, Expression/*!*/ closureCell, ParameterExpression parameter) {
Assert.NotNull(closureCell);
_variable = variable;
_closureCell = closureCell;
_parameter = parameter;
}
示例14: BuildExpression
private static NewExpression BuildExpression(Type type, ParameterExpression container)
{
if (!type.IsGenericTypeDefinition)
{
var constructor = GetConstructorInfo(type);
var parameters = constructor.GetParameters();
// create the arguments for the constructor
var arguments = new List<Expression>();
foreach (var paramInfo in parameters)
{
var p = Expression.Call(container, "Resolve", new Type[] { paramInfo.ParameterType },
new Expression[] { });
arguments.Add(p);
}
// create the new MyClass( ... ) call
return Expression.New(constructor, arguments);
}
else
{
return null;
}
}
示例15: VisitParameter
/// <summary>
/// If the given variable matches _find, return _replaceWith. Otherwise, continue default visitation behavior.
/// </summary>
/// <param name="node">The expression node being visited</param>
/// <returns></returns>
protected override Expression VisitParameter(ParameterExpression node)
{
if (node == _find)
return _replaceWith;
return base.VisitParameter(node);
}