示例#1
0
        public object GetValue(object model, ValueType valueType, object property)
        {
            switch (valueType)
            {
            case Parrot.Infrastructure.ValueType.StringLiteral:
            case Parrot.Infrastructure.ValueType.Keyword:
                return(property);

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

            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>;
                }

                return(result);
            }

            throw new InvalidOperationException("ValueType");
        }
        public object GetValue(object model, ValueType valueType, object property)
        {
            switch (valueType)
            {
                case Parrot.Infrastructure.ValueType.StringLiteral:
                case Parrot.Infrastructure.ValueType.Keyword:
                    return property;
                case Parrot.Infrastructure.ValueType.Local:
                    return model;
                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>;
                    }

                    return result;
            }

            throw new InvalidOperationException("ValueType");
        }
示例#3
0
        public StringLiteral(string value, StatementTail tail) : base("string", tail)
        {
            if (IsWrappedInQuotes(value))
            {
                ValueType = ValueType.StringLiteral;
                //strip quotes

                const int quoteOffset = 1;
                value = new string(value.ToArray(), quoteOffset, value.Length - (quoteOffset + 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 object GetValue(object model, Parrot.Infrastructure.ValueType valueType, object property)
        {
            switch (valueType)
            {
            case Parrot.Infrastructure.ValueType.StringLiteral:
            case Parrot.Infrastructure.ValueType.Keyword:
                return(property);

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

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

                return(GetModelProperty(model, property));
            }

            throw new InvalidOperationException("ValueType");
        }