Issue #42 resolved

Aliased Properties Not Supported With $filter

David Ogden
created an issue

The MemberNameResolver allows properties aliased through DataMember, XmlElement, and XmlAttribute attributes are resolved, but is currently only used in $select.

I wanted to be able to use aliased properties when using $filter. I have created a fork here and modified:

  • IMemeberNameResolver.cs
  • MemberNameResolver.cs
  • FilterExpressionParser.cs
  • ParameterParser.cs

There is a new method defined in IMemeberNameResolver:

PropertyInfo ResolveName(Type type, string name);

This is called from FilterExpressionFactory (Note the standard property resolution is still allowed to try first):

var property = parentType
.GetPublicProperties()
.FirstOrDefault(x => x.Name == name) 
?? _nameResolver.ResolveName(typeof(T), name);

The default implementation of MemberNameResolver populates:

ConcurrentDictionary<Type, ConcurrentDictionary<string, PropertyInfo>> ReverseLookup

based on the type and the DataMember, XmlElement, and XmlAttibute attributes in that type (if any). An aliased string (if any) is then returned:

        public PropertyInfo ResolveName(Type type, string name)
        {
            var typeDictionary = ReverseLookup.GetOrAdd(type, CreateReverseLookupForType);
            PropertyInfo propertyInfo;
            typeDictionary.TryGetValue(name, out propertyInfo);
            return propertyInfo;
        }

Feedback is appreciated. Thanks!

Comments (4)

  1. Jacob Reimers repo owner

    I am working on a similar design. However it should not only include properties, but also fields, as fields can be DataMembers. The parser (server side) is workning, but on the client it is a little more complex because it also has to support projections. Having a transparent aliasing for anonymous types is not as simple as it sounds :-)

  2. Log in to comment