Exemple #1
0
        protected override IExpression GetMvcLiteral(ITreeNode element, out ICSharpArgumentsOwner expression, out string anonymousPropertyName)
        {
            expression            = null;
            anonymousPropertyName = null;

            var csharpExpression = element as ICSharpExpression;

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

            if (CSharpArgumentNavigator.GetByValue(csharpExpression) == null && CSharpArgumentNavigator.GetByValue(
                    AnonymousObjectCreationExpressionNavigator.GetByAnonymousInitializer(
                        AnonymousObjectInitializerNavigator.GetByMemberInitializer(
                            AnonymousMemberDeclarationNavigator.GetByExpression(csharpExpression)))) == null)
            {
                return(null);
            }

            if (!csharpExpression.ConstantValue.IsString())
            {
                return(null);
            }

            return(NancyUtil.GetMvcLiteral(csharpExpression, out expression, out anonymousPropertyName));
        }
Exemple #2
0
        public IReference[] GetReferences(ITreeNode element, IReference[] oldReferences)
        {
            if (oldReferences != null && oldReferences.Any() && oldReferences.All(reference =>
            {
                if (reference is IMvcReference && reference.GetTreeNode() == element)
                {
                    return(((IMvcReference)reference).IsInternalValid);
                }

                return(false);
            }))
            {
                return(oldReferences);
            }
            var expression1 = element as TExpression;

            if (expression1 != null && HasImplicitReference(expression1, GetAllMvcNames(expression1)))
            {
                return(GetImplicitReferences(expression1).ToArray());
            }
            TExpression argumentExpression;
            string      anonymousPropertyName;
            IExpression mvcLiteral = GetMvcLiteral(element, out argumentExpression, out anonymousPropertyName);

            if (mvcLiteral == null)
            {
                return(EmptyArray <IReference> .Instance);
            }
            IParameter parameter = mvcLiteral.GetContainingNode <IArgument>().IfNotNull(d => d.MatchingParameter).IfNotNull(p => p.Element);

            if (parameter == null)
            {
                return(EmptyArray <IReference> .Instance);
            }
            var jt = parameter.GetMvcKinds().FirstOrDefault(_ => StringComparer.OrdinalIgnoreCase.Equals(_.B, anonymousPropertyName));

            if (jt == null)
            {
                return(EmptyArray <IReference> .Instance);
            }
            switch (jt.A)
            {
            case MvcKind.Area:
                return(new IReference[]
                {
                    GetMvcAreaReference(mvcLiteral)
                });

            case MvcKind.Controller:
                return(new IReference[]
                {
                    GetMvcControllerReference(mvcLiteral, argumentExpression)
                });

            case MvcKind.Action:
                return(new IReference[]
                {
                    GetMvcActionReference(mvcLiteral, argumentExpression)
                });

            case MvcKind.View:
            case MvcKind.PartialView:
            case MvcKind.Master:
            case MvcKind.DisplayTemplate:
            case MvcKind.EditorTemplate:
                var list = NancyUtil.GetModules(argumentExpression)
                           .DefaultIfEmpty(JetTuple.Of((string)null, (string)null, MvcUtil.DeterminationKind.Explicit, (ICollection <IClass>)null)).ToList();
                return(new IReference[] { GetMvcViewReference(mvcLiteral, list, jt.A, new Version()) });

            default:
                return(EmptyArray <IReference> .Instance);
            }
        }