Пример #1
0
        public IEnumerable <QueryToken> GetAllTokens(QueryToken parent)
        {
            var info = metas.GetOrAdd(parent, qt =>
            {
                Expression <Func <T, V> > lambda = t => ValueSelector.Evaluate(CollectionSelector.Evaluate(t).SingleOrDefaultEx() !);

                Expression e = MetadataVisitor.JustVisit(lambda, MetaExpression.FromToken(qt, typeof(T)));

                var result = new ExtensionRouteInfo();

                if (e is MetaExpression me && me.Meta is CleanMeta cm && cm.PropertyRoutes.Any())
                {
                    var cleanType = me !.Type.CleanType();

                    result.PropertyRoute   = cm.PropertyRoutes.Only();
                    result.Implementations = me.Meta.Implementations;
                    result.Format          = ColumnDescriptionFactory.GetFormat(cm.PropertyRoutes);
                    result.Unit            = ColumnDescriptionFactory.GetUnit(cm.PropertyRoutes);
                }

                return(result);
            });
Пример #2
0
        protected internal virtual ExtensionToken CreateToken(QueryToken parent)
        {
            var info = metas.GetOrAdd(parent, qt =>
            {
                Expression e = MetadataVisitor.JustVisit(Lambda, MetaExpression.FromToken(qt, SourceType));

                MetaExpression me;

                if (this.IsProjection)
                {
                    var mpe = e as MetaProjectorExpression;

                    if (mpe == null)
                    {
                        mpe = MetadataVisitor.AsProjection(e);
                    }

                    me = mpe == null ? null : mpe.Projector as MetaExpression;
                }
                else
                {
                    me = e as MetaExpression;
                }

                CleanMeta cm = me == null ? null : me.Meta as CleanMeta;

                var result = new ExtensionRouteInfo();

                if (cm != null && cm.PropertyRoutes.Any())
                {
                    var cleanType = me.Type.CleanType();

                    result.PropertyRoute   = cm.PropertyRoutes.Only();
                    result.Implementations = me.Meta.Implementations;
                    result.Format          = ColumnDescriptionFactory.GetFormat(cm.PropertyRoutes);
                    result.Unit            = ColumnDescriptionFactory.GetUnit(cm.PropertyRoutes);
                }

                result.IsAllowed = () => (me == null || me.Meta == null) ? null : me.Meta.IsAllowed();

                if (ForcePropertyRoute != null)
                {
                    result.PropertyRoute = ForcePropertyRoute;
                }

                if (ForceImplementations != null)
                {
                    result.Implementations = ForceImplementations;
                }

                if (ForceFormat != null)
                {
                    result.Format = ForceFormat;
                }

                if (ForceUnit != null)
                {
                    result.Unit = ForceUnit;
                }

                if (ForceIsAllowed != null)
                {
                    result.IsAllowed = ForceIsAllowed;
                }

                return(result);
            });

            return(new ExtensionToken(parent, Key, Type, IsProjection, info.Unit, info.Format, info.Implementations, info.IsAllowed(), info.PropertyRoute)
            {
                DisplayName = NiceName()
            });
        }