Ejemplo n.º 1
0
        public Implementations FindImplementations(PropertyRoute route)
        {
            if (route.PropertyRouteType == PropertyRouteType.LiteEntity)
            {
                route = route.Parent;
            }

            Type type = route.RootType;

            if (!Tables.ContainsKey(type))
            {
                return(Implementations.By(route.Type.CleanType()));
            }

            Field field = TryFindField(Table(type), route.Members);
            //if (field == null)
            //    return Implementations.ByAll;

            FieldReference refField = field as FieldReference;

            if (refField != null)
            {
                return(Implementations.By(refField.FieldType.CleanType()));
            }

            FieldImplementedBy ibField = field as FieldImplementedBy;

            if (ibField != null)
            {
                return(Implementations.By(ibField.ImplementationColumns.Keys.ToArray()));
            }

            FieldImplementedByAll ibaField = field as FieldImplementedByAll;

            if (ibaField != null)
            {
                return(Implementations.ByAll);
            }

            Implementations?implementations = CalculateExpressionImplementations(route);

            if (implementations != null)
            {
                return(implementations.Value);
            }

            var ss = Schema.Current.Settings;

            if (route.Follow(r => r.Parent)
                .TakeWhile(t => t.PropertyRouteType != PropertyRouteType.Root)
                .Any(r => ss.FieldAttribute <IgnoreAttribute>(r) != null))
            {
                var ib  = ss.FieldAttribute <ImplementedByAttribute>(route);
                var iba = ss.FieldAttribute <ImplementedByAllAttribute>(route);

                return(Implementations.TryFromAttributes(route.Type.CleanType(), route, ib, iba) ?? Implementations.By());
            }

            throw new InvalidOperationException("Impossible to determine implementations for {0}".FormatWith(route, typeof(IEntity).Name));
        }