Exemplo n.º 1
0
            /// <summary>
            /// Invoked via reflection.
            /// </summary>
            /// <param name="mappings"></param>
            public DataTypeRelativeRouteToPredicateMapper(PropertyUrlMapping[] mappings)
            {
                _mappings = mappings;

                var keyProperties = typeof(TDataType).GetKeyProperties();

                if (keyProperties.Count == 1)
                {
                    var keyProperty          = keyProperties[0];
                    var keyValueProviderType =
                        typeof(IRelativeRouteValueProvider <>).MakeGenericType(keyProperty.PropertyType);

                    int pathSegmentsToIgnore = 0;
                    for (int i = 0; i < _mappings.Length; i++)
                    {
                        var propertyMapping = _mappings[i];
                        if (propertyMapping.Property == keyProperty &&
                            keyValueProviderType.IsInstanceOfType(propertyMapping.Mapper))
                        {
                            _keyMapping = propertyMapping;
                            _keyFieldUrlSegmentOffset = pathSegmentsToIgnore;
                        }

                        pathSegmentsToIgnore += propertyMapping.Mapper.PathSegmentsCount;
                    }
                }
            }
Exemplo n.º 2
0
            private IData TryDataByKeyProperty(PropertyUrlMapping propertyMapping, RelativeRoute keyRoutePart)
            {
                var method = StaticReflection.GetGenericMethodInfo(() => TryDataByKeyProperty <Guid>(null, null));

                var genericMethod = method.MakeGenericMethod(propertyMapping.Property.PropertyType);

                return(genericMethod.Invoke(this, new object[] { propertyMapping, keyRoutePart }) as TDataType);
            }
Exemplo n.º 3
0
            private TDataType TryDataByKeyProperty <TKeyType>(PropertyUrlMapping propertyMapping, RelativeRoute keyRoutePart)
            {
                var valueProvider = propertyMapping.Mapper as IRelativeRouteValueProvider <TKeyType>;

                if (valueProvider == null)
                {
                    return(null);
                }

                TKeyType key;

                if (!valueProvider.TryGetValue(keyRoutePart, out key))
                {
                    return(null);
                }

                return(DataFacade.TryGetDataByUniqueKey(typeof(TDataType), key) as TDataType);
            }