本文整理汇总了C#中System.Linq.Expressions.MemberExpression类的典型用法代码示例。如果您正苦于以下问题:C# MemberExpression类的具体用法?C# MemberExpression怎么用?C# MemberExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemberExpression类属于System.Linq.Expressions命名空间,在下文中一共展示了MemberExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: VisitMemberAccess
protected override Expression VisitMemberAccess(MemberExpression m)
{
string methodName = this.GetMethodName(m.Member.Name);
MethodInfo method = m.Member.ReflectedType.GetMethod(methodName);
this.AddMethod(method);
return base.VisitMemberAccess(m);
}
开发者ID:hhahh2011,项目名称:CH.Cms,代码行数:7,代码来源:DMapperRuleAnalyzer.cs
示例2: VisitMember
/// <summary>
/// Replaces a <see cref="DbQuery" /> or <see cref="DbQuery{T}" /> property with a constant expression
/// for the underlying <see cref="ObjectQuery" />.
/// </summary>
/// <param name="node"> The node to replace. </param>
/// <returns> A new node, which may have had the replacement made. </returns>
protected override Expression VisitMember(MemberExpression node)
{
Check.NotNull(node, "node");
var propInfo = node.Member as PropertyInfo;
var memberExpression = node.Expression as MemberExpression;
if (propInfo != null
&& memberExpression != null
&&
typeof(IQueryable).IsAssignableFrom(propInfo.PropertyType)
&&
typeof(DbContext).IsAssignableFrom(node.Member.DeclaringType))
{
var context = GetContextFromConstantExpression(memberExpression.Expression, memberExpression.Member);
if (context != null)
{
var expression =
CreateObjectQueryConstant(propInfo.GetValue(context, SetAccessBindingFlags, null, null, null));
if (expression != null)
{
return expression;
}
}
}
return base.VisitMember(node);
}
开发者ID:jwanagel,项目名称:jjwtest,代码行数:34,代码来源:DbQueryVisitor.cs
示例3: VisitMember
protected override Expression VisitMember(MemberExpression node)
{
if (node.Expression != null && node.Expression.NodeType == ExpressionType.Parameter)
return VisitFieldSelection(node);
return base.VisitMember(node);
}
开发者ID:jarlrasm,项目名称:ElasticLINQ,代码行数:7,代码来源:MemberProjectionExpressionVisitor.cs
示例4: VisitMember
/// <summary>
/// Visits the member.
/// </summary>
/// <param name="node">The node.</param>
/// <returns></returns>
protected override Expression VisitMember(MemberExpression node)
{
CompiledExpression expression;
// Ensure that all property mappings are registered (the usual way -> on object type)
EnsureTypeInitialized(node.Member.DeclaringType);
// Ensure that all property mappings are registered (when the linq query was built towards an interface)
if (IsBuildOnInterface(node))
{
EnsureTypeInitialized(node.Expression.Type);
}
if ((IsBuildOnInterface(node) && this.map.TryGetValue(node.Member, node.Expression.Type, out expression))
|| this.map.TryGetValue(node.Member, out expression))
{
return this.VisitCompiledExpression(expression, node.Expression);
}
if (typeof(CompiledExpression).IsAssignableFrom(node.Member.DeclaringType))
{
return this.VisitCompiledExpression(expression, node.Expression);
}
return base.VisitMember(node);
}
开发者ID:peschuster,项目名称:PropertyTranslator,代码行数:31,代码来源:PropertyVisitor.cs
示例5: VisitMember
protected override Expression VisitMember(MemberExpression node)
{
var memberExpression = node.Expression as MemberExpression;
if (memberExpression != null)
{
if (!_uniquefList.Contains(memberExpression.ToString()))
{
_uniquefList.Add(memberExpression.ToString());
var expression = _isNull
? Expression.Constant(null, memberExpression.Type)
: (Expression)Expression.Default(memberExpression.Type);
if (CheckNullExpression == null)
{
CheckNullExpression = Expression.Equal(memberExpression, expression);
}
else
{
CheckNullExpression =
Expression.OrElse(Expression.Equal(memberExpression, expression),
CheckNullExpression);
}
}
}
return base.VisitMember(node);
}
开发者ID:shay1e,项目名称:ExpressMapper,代码行数:27,代码来源:NullCheckNestedMemberVisitor.cs
示例6: VisitMemberAccess
protected override QueryNode VisitMemberAccess(MemberExpression expression)
{
if (expression.Expression == null)
return base.VisitMemberAccess(expression);
if (expression.Expression.NodeType == ExpressionType.Constant ||
expression.Expression.NodeType == ExpressionType.Parameter ||
expression.Expression.NodeType == ExpressionType.Convert)
return base.VisitMemberAccess(expression);
if (!(expression.Expression is MemberExpression))
throw new NotSupportedException(string.Format("Unsupported member access. Expression type: {0}. Member name: {1}.", expression.Expression.NodeType, expression.Member.Name));
QueryNode queryNode = VisitMemberAccess((MemberExpression)expression.Expression);
// PATCH: this fixes querying on subproperties of result items (e.g. x=> x.Foo.Bar)
var constant = queryNode as ConstantNode;
if (constant != null) return new ConstantNode(expression.Member.GetValue(constant.Value), expression.Member.GetValueType());
var field = queryNode as FieldNode;
if (field != null)
{
// NOTE: later releases of SC7 change this behavior to include the property name in the field by default (e.g. x=>x.Foo.Bar would map to "foo.bar" in the index)
// there may be some compatibility changes that go here later
return new FieldNode(field.FieldKey, expression.Member.GetValueType()); // return a new FIELD, but set its effective type to the property's so there aren't comparison issues later
}
throw new NotSupportedException(string.Format("Unsupported member access. Expression type: {0}. Member name: {1}. Member Value Type: {2}", expression.Expression.NodeType, expression.Member.Name, queryNode.NodeType));
// END PATCH
}
开发者ID:simonproctor,项目名称:Synthesis,代码行数:32,代码来源:BugFixExpressionParser.cs
示例7: VisitMemberAccess
protected override Expression VisitMemberAccess(MemberExpression m)
{
Expression source = this.Visit(m.Expression);
EntityExpression ex = source as EntityExpression;
IMemberMapping mm = null;
if (ex != null && (mm = ex.Entity.Get(m.Member)) != null && mm.IsRelationship)
{
ProjectionExpression projection = (ProjectionExpression)this.Visit(this.expressionBuilder.GetMemberExpression(source, ex.Entity, m.Member));
if (this.currentFrom != null && mm.IsManyToOne)
{
// convert singleton associations directly to OUTER APPLY
projection = this.expressionBuilder.AddOuterJoinTest(projection);
Expression newFrom = new JoinExpression(JoinType.OuterApply, this.currentFrom, projection.Select, null);
this.currentFrom = newFrom;
return projection.Projector;
}
return projection;
}
else
{
Expression result = QueryBinder.BindMember(source, m.Member);
MemberExpression mex = result as MemberExpression;
if (mex != null && mex.Member == m.Member && mex.Expression == m.Expression)
{
return m;
}
return result;
}
}
开发者ID:jaykizhou,项目名称:elinq,代码行数:30,代码来源:RelationshipBinder.cs
示例8: VisitMemberAccess
protected override Expression VisitMemberAccess(MemberExpression m)
{
Expression source = this.Visit(m.Expression);
DbEntityExpression ex = source as DbEntityExpression;
if (ex != null && this.mapping.IsAssociation(ex.Entity, m.Member))
{
DbProjectionExpression projection = (DbProjectionExpression)this.Visit(this.mapping.CreateMemberExpression(source, ex.Entity, m.Member));
if (this.currentFrom != null && this.mapping.IsSingletonAssociation(ex.Entity, m.Member))
{
// convert singleton associations directly to OUTER APPLY
projection = projection.AddOuterJoinTest();
Expression newFrom = new DbJoinExpression(DbJoinType.OuterApply, this.currentFrom, projection.Select, null);
this.currentFrom = newFrom;
return projection.Projector;
}
return projection;
}
else
{
Expression result = QueryBinder.BindMember(source, m.Member);
MemberExpression mex = result as MemberExpression;
if (mex != null && mex.Member == m.Member && mex.Expression == m.Expression)
{
return m;
}
return result;
}
}
开发者ID:radischevo,项目名称:Radischevo.Wahha,代码行数:29,代码来源:RelationshipBinder.cs
示例9: VisitMemberAccess
protected override Expression VisitMemberAccess(MemberExpression m)
{
if (m.Member.DeclaringType.Namespace.ToLower().CompareTo("artefacts.service") == 0) //.Equals(typeof(Repository)))// && m.Expression == null)
{
object value = null;
object container = null;
if (m.Expression != null)
{
Expression mExp = this.Visit(m.Expression);
if (!(mExp is ConstantExpression))
throw new ApplicationException("m.Expression should be null or a ConstantExpression (after processing with ServerQueryVisitor)");
container = ((ConstantExpression)mExp).Value;
}
switch (m.Member.MemberType)
{
case MemberTypes.Field:
value = ((FieldInfo)m.Member).GetValue(container);
break;
case MemberTypes.Property:
value = ((PropertyInfo)m.Member).GetValue(container, null); // TODO: Need to handle indexer properties? IndexExpression does not derive from MemberExpression
break;
default:
throw new ApplicationException(string.Format("Unknown MemberType in MemberExpression: \"{0}\"", m.Member.MemberType.ToString()));
}
return Expression.Constant(value);
}
return base.VisitMemberAccess(m);
}
开发者ID:jbowwww,项目名称:ArtefactService,代码行数:28,代码来源:ServerQueryVisitor.cs
示例10: GenerateEquals
public static Predicate<object> GenerateEquals(MemberExpression prop, string value, Type type, ParameterExpression objParam)
{
BinaryExpression equalExpresion = null;
if (TypeHelper.IsValueType(type))
{
object equalTypedInput = TypeHelper.ValueConvertor(type, value);
if (equalTypedInput != null)
{
var equalValue = System.Linq.Expressions.Expression.Constant(equalTypedInput, type);
equalExpresion = System.Linq.Expressions.Expression.Equal(prop, equalValue);
}
}
else
{
var toStringExp = System.Linq.Expressions.Expression.Equal(ToLower(ToString(prop)), ExpressionHelper.ToLower(ExpressionHelper.ToString(System.Linq.Expressions.Expression.Constant(value))));
equalExpresion = System.Linq.Expressions.Expression.AndAlso(ExpressionHelper.NotNull(prop), toStringExp);
}
if (equalExpresion != null)
{
Expression<Func<object, bool>> equalfunction = System.Linq.Expressions.Expression.Lambda<Func<object, bool>>(equalExpresion, objParam);
return new Predicate<object>(equalfunction.Compile());
}
else
return null;
}
开发者ID:vahtel65,项目名称:Aspect_loc,代码行数:26,代码来源:ExpressionHelper.cs
示例11: VisitMember
protected override Expression VisitMember(MemberExpression node)
{
var visitor = new MemberExpressionVisitor(this.Context);
visitor.Visit(node);
Column = visitor.Column;
return node;
}
开发者ID:BeanHsiang,项目名称:Greedy,代码行数:7,代码来源:BinaryExpressionVisitor.cs
示例12: VisitMemberAccess
protected override Expression VisitMemberAccess(MemberExpression m) {
if (m.Expression != null && m.Expression.NodeType == ExpressionType.Parameter) {
sb.Append(m.Member.Name.ToLowerInvariant());
return m;
}
throw new NotSupportedException(string.Format("The member '{0}' is not supported", m.Member.Name));
}
开发者ID:idkay0,项目名称:Unity-QuickSheet,代码行数:7,代码来源:WhereTranslator.cs
示例13: VisitMemberAccess
protected override Expression VisitMemberAccess(MemberExpression m)
{
var declaringType = m.Member.DeclaringType;
if (declaringType == typeof (string)) {
switch (m.Member.Name) {
case "Length": {
Write("LENGTH(");
Visit(m.Expression);
Write(")");
return m;
}
}
} else if (declaringType == typeof (DateTime) ||
declaringType == typeof (DateTimeOffset)) {
switch (m.Member.Name) {
case "Day": {
Write("DAY(");
Visit(m.Expression);
Write(")");
return m;
}
case "Year": {
Write("YEAR(");
Visit(m.Expression);
Write(")");
return m;
}
// TODO: Continue with date function
}
} else if (declaringType == typeof (TimeSpan)) {
}
return base.VisitMemberAccess(m);
}
开发者ID:ArsenShnurkov,项目名称:deveeldb,代码行数:35,代码来源:DeveelDbFormatter.cs
示例14: GetCompareExpression
public override BinaryExpression GetCompareExpression(MemberExpression propertyExpression, object userChoice)
{
var selectedValues = (IList<object>) userChoice;
BinaryExpression contains = null;
foreach (object o in selectedValues)
{
if (contains == null)
{
contains = Expression.Equal(
propertyExpression,
Expression.Constant(o)
);
continue;
}
contains = Expression.OrElse(
contains,
Expression.Equal(
propertyExpression,
Expression.Constant(o)
));
}
return contains;
}
开发者ID:rajeshgajra19889,项目名称:faceted-search,代码行数:26,代码来源:MultipleValueMapper.cs
示例15: VisitMemberExpression
protected override Expression VisitMemberExpression(MemberExpression expression)
{
if (!IsMemberOfModel(expression))
{
return base.VisitMemberExpression(expression);
}
if (expression.IsGroupingKeyOf(_groupBy))
{
return _groupBy.KeySelector;
}
var elementSelector = _groupBy.ElementSelector;
if ((elementSelector is MemberExpression) || (elementSelector is QuerySourceReferenceExpression))
{
// If ElementSelector is MemberExpression, just return
return base.VisitMemberExpression(expression);
}
if ((elementSelector is NewExpression || elementSelector.NodeType == ExpressionType.Convert)
&& elementSelector.Type == expression.Expression.Type)
{
//TODO: probably we should check this with a visitor
return Expression.MakeMemberAccess(elementSelector, expression.Member);
}
throw new NotImplementedException();
}
开发者ID:liypeng,项目名称:nhibernate-core,代码行数:29,代码来源:GroupBySelectClauseRewriter.cs
示例16: VisitMemberAccess
/// <summary>
/// 将属性变量转换成T-SQL字段名
/// </summary>
protected override Expression VisitMemberAccess(MemberExpression m)
{
base.VisitMemberAccess(m);
if (_lst.Exists(o => o.Member.Name == m.Member.Name && o.Type == m.Type)) { return m; }
_lst.Add(m);
return m;
}
开发者ID:SaintLoong,项目名称:Farseer.Net,代码行数:10,代码来源:GetMemberVisitor.cs
示例17: VisitMemberAccess
protected override Expression VisitMemberAccess(MemberExpression m) {
if (m.Member.DeclaringType == typeof(string)) {
switch (m.Member.Name) {
case "Length":
sb.Append("LENGTH(");
this.Visit(m.Expression);
sb.Append(")");
return m;
}
} else if (m.Member.DeclaringType == typeof(DateTime) || m.Member.DeclaringType == typeof(DateTimeOffset)) {
switch (m.Member.Name) {
case "Day":
sb.Append("TO_CHAR(");
this.Visit(m.Expression);
sb.Append(", 'DD')");
return m;
case "Month":
sb.Append("TO_CHAR(");
this.Visit(m.Expression);
sb.Append(", 'MM')");
return m;
case "Year":
sb.Append("TO_CHAR(");
this.Visit(m.Expression);
sb.Append(", 'YYYY')");
return m;
case "Hour":
sb.Append("TO_CHAR( ");
this.Visit(m.Expression);
sb.Append(", 'HH24')");
return m;
case "Minute":
sb.Append("TO_CHAR( ");
this.Visit(m.Expression);
sb.Append(", 'MI')");
return m;
case "Second":
sb.Append("TO_CHAR( ");
this.Visit(m.Expression);
sb.Append(", 'SS')");
return m;
case "Millisecond":
sb.Append("TO_CHAR( ");
this.Visit(m.Expression);
sb.Append(", 'FF')");
return m;
case "DayOfWeek":
sb.Append("(TO_CHAR(");
this.Visit(m.Expression);
sb.Append(", 'D') - 1)");
return m;
case "DayOfYear":
sb.Append("(TO_CHAR( ");
this.Visit(m.Expression);
sb.Append(", 'DDD') - 1)");
return m;
}
}
throw new NotSupportedException(string.Format("The member '{0}' is not supported", m.Member.Name));
}
开发者ID:rally25rs,项目名称:SubSonic-3.0,代码行数:60,代码来源:OracleFormatter.cs
示例18: GetFieldName
/// <inheritdoc/>
public string GetFieldName(string prefix, MemberExpression memberExpression)
{
return
memberExpression.Member.DeclaringType == typeof(ElasticFields)
? "_" + memberExpression.Member.Name.ToLowerInvariant()
: wrapped.GetFieldName(prefix, memberExpression);
}
开发者ID:pickypg,项目名称:ElasticLINQ,代码行数:8,代码来源:ElasticFieldsMappingWrapper.cs
示例19: UpdateMemberAccess
protected MemberExpression UpdateMemberAccess(MemberExpression m, Expression expression, MemberInfo member)
{
if (expression != m.Expression || member != m.Member) {
return Expression.MakeMemberAccess(expression, member);
}
return m;
}
开发者ID:kpfaulkner,项目名称:Linq-To-Search,代码行数:7,代码来源:ExpressionVisitor.cs
示例20: AddInclude
private void AddInclude(SimpleType source, MemberExpression memberSelector, LambdaExpression collectionInclude)
{
var members = source.GetAllMembers();
if (members.Count > 0 && memberSelector.GetDepth() > 1)
{
var innermostMember = ExpressionUtil.GetInnermostMemberExpression(memberSelector);
foreach (var kvp in members)
{
if (kvp.Key == innermostMember.Member)
{
AddInclude(kvp.Value, ExpressionUtil.ReplaceInnermostMemberExpressionWithParameter(memberSelector) as MemberExpression, collectionInclude);
return;
}
}
}
else
{
var parameter = ExpressionUtil.GetParameterExpression(memberSelector);
if (collectionInclude != null)
{
source.Includes.Add(IncludeDirectiveUtil.GetIncludeInCollectionDirective(memberSelector, collectionInclude));
}
else
{
source.Includes.Add(IncludeDirectiveUtil.GetIncludeDirective(memberSelector));
}
}
}
开发者ID:jeswin,项目名称:AgileFx,代码行数:28,代码来源:LoadRelated.cs
注:本文中的System.Linq.Expressions.MemberExpression类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论