Beispiel #1
0
        public StringLiteral(IHost host, string value) : base(host)
        {
            base.Name = "string";

            if (IsWrappedInQuotes(value))
            {
                ValueType = ValueType.StringLiteral;
                //strip quotes

                int offset = StartsWith(value, '@') ? 2 : 1;
                value = new string(value.ToArray(), offset, value.Length - (offset + 1));
            }
            else if (value == "this")
            {
                ValueType = ValueType.Local;
            }
            else if (value == "null" || value == "true" || value == "false")
            {
                ValueType = ValueType.Keyword;
            }
            else
            {
                ValueType = ValueType.Property;
            }

            if (ValueType == ValueType.StringLiteral)
            {
                Values = Parse(value);
            }
        }
        public bool GetValue(IDictionary <string, object> documentHost, object model, Parrot.Infrastructure.ValueType valueType, object property, out object value)
        {
            switch (valueType)
            {
            case Parrot.Infrastructure.ValueType.StringLiteral:
            case Parrot.Infrastructure.ValueType.Keyword:
                value = property;
                return(true);

            case Parrot.Infrastructure.ValueType.Local:
                value = model;
                return(true);

            case Parrot.Infrastructure.ValueType.Property:
                if (model == null)
                {
                    throw new NullReferenceException("model");
                }

                var propertyValues = (IDictionary <string, object>)model;
                var result         = model;

                var properties = property.ToString().Split(".".ToCharArray());
                for (int i = 0; i < properties.Length; i++)
                {
                    var name = properties[i];
                    result         = propertyValues[name];
                    propertyValues = result as IDictionary <string, object>;
                }

                value = result;
                return(true);
            }

            value = null;
            return(false);
        }
Beispiel #3
0
        public bool GetValue(IDictionary <string, object> documentHost, object model, Parrot.Infrastructure.ValueType valueType, object property, out object value)
        {
            switch (valueType)
            {
            case Parrot.Infrastructure.ValueType.StringLiteral:
            case Parrot.Infrastructure.ValueType.Keyword:
                value = property;
                return(true);

            case Parrot.Infrastructure.ValueType.Local:
                value = model;
                return(true);

            case Parrot.Infrastructure.ValueType.Property:
                if (model != null && GetModelProperty(model, property, out value))
                {
                    return(true);
                }

                if (documentHost != null && GetModelProperty(documentHost, property, out value))
                {
                    return(true);
                }

                value = null;
                return(false);
            }

            value = model;
            return(false);
        }