Esempio n. 1
0
        public virtual void Parse(string str)
        {
            var input = FinTsParser.UnescapeInput(str);

            var body = input.Substring(0, input.Length - 1);

            Parse(body.Split('\''));
        }
Esempio n. 2
0
        protected void Parse(string[] segments)
        {
            PropertyMetadata meta = null;

            for (int i = 0; i < segments.Length; i++)
            {
                meta = i < metadata.Length
                    ? metadata[i]
                    : meta;

                var segment = segments[i];

                if (!(meta?.IsCollection ?? true))
                {
                    if (string.IsNullOrEmpty(segment))
                    {
                        meta.Property.SetValue(this, null);
                    }
                    else
                    {
                        var element = FinTsParser.Parse(meta.Property.PropertyType, segment, meta.Attribute.Parameters);
                        meta.Property.SetValue(this, element);
                    }
                }
                else
                {
                    var elementType = meta.Property.PropertyType.GenericTypeArguments[0];

                    var element = FinTsParser.Parse(elementType, segment, meta.Attribute.Parameters);

                    var collection = meta.Property.GetValue(this);
                    if (collection == null)
                    {
                        var collectionType = typeof(List <>).MakeGenericType(elementType);
                        collection = Activator.CreateInstance(collectionType);
                        meta.Property.SetValue(this, collection);
                    }

                    var addMethod = collection.GetType().GetMethod("Add");

                    addMethod.Invoke(collection, new[] { element });
                }
            }
        }