/// <summary> /// Serializes an MemberExpression to a string /// </summary> /// <param name="m">Expression to serialize</param> /// <returns>MemberExpression</returns> internal override Expression VisitMemberAccess(MemberExpression m) { if (m.Member is FieldInfo) { throw new NotSupportedException(Strings.ALinq_CantReferToPublicField(m.Member.Name)); } Expression e = this.Visit(m.Expression); // if this is a Nullable<T> instance, don't write out /Value since not supported by server if (m.Member.Name == "Value" && m.Member.DeclaringType.IsGenericType() && m.Member.DeclaringType.GetGenericTypeDefinition() == typeof(Nullable <>)) { return(m); } // if this is a GetValueAsync().Result call in async scenario, don't write out /Result MethodCallExpression methodCallExpression = m.Expression as MethodCallExpression; if (methodCallExpression != null && methodCallExpression.Method.Name == "GetValueAsync" && m.Member.Name == "Result") { return(m); } if (!this.IsImplicitInputReference(e) || writingFunctionsInQuery) { this.builder.Append(UriHelper.FORWARDSLASH); } this.builder.Append(ClientTypeUtil.GetServerDefinedName(m.Member)); return(m); }
/// <summary> /// Serializes an MemberExpression to a string /// </summary> /// <param name="m">Expression to serialize</param> /// <returns>MemberExpression</returns> internal override Expression VisitMemberAccess(MemberExpression m) { if (m.Member is FieldInfo) { throw new NotSupportedException(Strings.ALinq_CantReferToPublicField(m.Member.Name)); } Expression e = this.Visit(m.Expression); // if this is a Nullable<T> instance, don't write out /Value since not supported by server if (m.Member.Name == "Value" && m.Member.DeclaringType.IsGenericType() && m.Member.DeclaringType.GetGenericTypeDefinition() == typeof(Nullable <>)) { return(m); } if (!this.IsImplicitInputReference(e)) { this.builder.Append(UriHelper.FORWARDSLASH); } this.builder.Append(ClientTypeUtil.GetServerDefinedName(m.Member)); return(m); }
/// <summary> /// Serializes an MemberExpression to a string /// </summary> /// <param name="m">Expression to serialize</param> /// <returns>MemberExpression</returns> internal override Expression VisitMemberAccess(MemberExpression m) { if (m.Member is FieldInfo) { throw new NotSupportedException(Strings.ALinq_CantReferToPublicField(m.Member.Name)); } Expression e = this.Visit(m.Expression); // if this is a Nullable<T> instance, don't write out /Value since not supported by server if (m.Member.Name == "Value" && m.Member.DeclaringType.IsGenericType() && m.Member.DeclaringType.GetGenericTypeDefinition() == typeof(Nullable <>)) { return(m); } // if this is a GetValueAsync().Result call in async scenario, don't write out /Result MethodCallExpression methodCallExpression = m.Expression as MethodCallExpression; if (methodCallExpression != null && methodCallExpression.Method.Name == "GetValueAsync" && m.Member.Name == "Result") { return(m); } if (!this.IsImplicitInputReference(e) || writingFunctionsInQuery) { this.builder.Append(UriHelper.FORWARDSLASH); } // If the member is collection with count property, it will be parsed as $count segment var parentType = m.Member.DeclaringType; Type collectionType = ClientTypeUtil.GetImplementationType(parentType, typeof(ICollection <>)); if (!PrimitiveType.IsKnownNullableType(parentType) && collectionType != null && m.Member.Name.Equals(ReflectionUtil.COUNTPROPNAME, StringComparison.Ordinal)) { this.builder.Append(UriHelper.DOLLARSIGN).Append(UriHelper.COUNT); } else { this.builder.Append(ClientTypeUtil.GetServerDefinedName(m.Member)); } return(m); }