Ejemplo n.º 1
0
        /// <summary>
        /// Converts this type annotation
        /// </summary>
        public T GetValue <T>(TypeAnnotationConverter <T> converter) where T : class
        {
            var walker = new Walker(ParseSubExpression);

            Expression.Walk(walker);
            return(walker.GetResult(converter));
        }
Ejemplo n.º 2
0
                public override bool Apply <T>(TypeAnnotationConverter <T> converter, Stack <KeyValuePair <string, T> > stack)
                {
                    var items = new List <T>();

                    if (!stack.Any())
                    {
                        return(false);
                    }
                    var t = stack.Pop();

                    while (t.Key != nameof(StartListOp))
                    {
                        items.Add(t.Value);
                        if (!stack.Any())
                        {
                            return(false);
                        }
                        t = stack.Pop();
                    }
                    items.Reverse();
                    t = new KeyValuePair <string, T>(null, converter.MakeList(items));
                    if (t.Value == null)
                    {
                        return(false);
                    }
                    stack.Push(t);
                    return(true);
                }
Ejemplo n.º 3
0
                public override bool Apply <T>(TypeAnnotationConverter <T> converter, Stack <KeyValuePair <string, T> > stack)
                {
                    if (stack.Count < 2)
                    {
                        return(false);
                    }
                    var args = stack.Pop();

                    if (args.Key != null)
                    {
                        return(false);
                    }
                    var baseType = stack.Pop();

                    if (baseType.Key != null)
                    {
                        return(false);
                    }
                    var t = converter.MakeGeneric(baseType.Value, converter.GetUnionTypes(args.Value) ?? new[] { args.Value });

                    if (t == null)
                    {
                        return(false);
                    }
                    stack.Push(new KeyValuePair <string, T>(null, t));
                    return(true);
                }
Ejemplo n.º 4
0
                public override bool Apply <T>(TypeAnnotationConverter <T> converter, Stack <KeyValuePair <string, T> > stack)
                {
                    var t = converter.LookupName(Name) ?? converter.MakeNameType(Name);

                    if (t == null)
                    {
                        return(false);
                    }
                    stack.Push(new KeyValuePair <string, T>(null, t));
                    return(true);
                }
Ejemplo n.º 5
0
                public override bool Apply <T>(TypeAnnotationConverter <T> converter, Stack <KeyValuePair <string, T> > stack)
                {
                    if (!stack.Any())
                    {
                        return(false);
                    }
                    var t = stack.Pop();

                    t = new KeyValuePair <string, T>(null, converter.MakeOptional(t.Value));
                    if (t.Value == null)
                    {
                        return(false);
                    }
                    stack.Push(t);
                    return(true);
                }
Ejemplo n.º 6
0
                public override bool Apply <T>(TypeAnnotationConverter <T> converter, Stack <KeyValuePair <string, T> > stack)
                {
                    if (!stack.Any())
                    {
                        return(false);
                    }
                    var t = stack.Pop();

                    t = new KeyValuePair <string, T>(t.Key == null ? null : $"{t.Key}.{Member}", converter.GetTypeMember(t.Value, Member));
                    if (t.Value == null)
                    {
                        return(false);
                    }
                    stack.Push(t);
                    return(true);
                }
Ejemplo n.º 7
0
                public override bool Apply <T>(TypeAnnotationConverter <T> converter, Stack <KeyValuePair <string, T> > stack)
                {
                    var items = new List <T>();

                    if (!stack.Any())
                    {
                        return(false);
                    }
                    var t = stack.Pop();

                    if (t.Value == null)
                    {
                        return(false);
                    }
                    if (_multipleArgs)
                    {
                        while (t.Key != nameof(StartUnionOp))
                        {
                            items.Add(t.Value);
                            if (!stack.Any())
                            {
                                return(false);
                            }
                            t = stack.Pop();
                        }
                        items.Reverse();
                    }
                    else if (t.Key != nameof(StartUnionOp))
                    {
                        items.Add(t.Value);
                    }
                    var baseType = stack.Pop();

                    if (baseType.Key != null)
                    {
                        return(false);
                    }
                    t = new KeyValuePair <string, T>(null, converter.MakeGeneric(baseType.Value, items));
                    if (t.Value == null)
                    {
                        return(false);
                    }
                    stack.Push(t);
                    return(true);
                }
Ejemplo n.º 8
0
            public T GetResult <T>(TypeAnnotationConverter <T> converter) where T : class
            {
                var stack = new Stack <KeyValuePair <string, T> >();

                foreach (var op in _ops)
                {
                    if (!op.Apply(converter, stack))
                    {
                        return(default(T));
                    }
                }

                if (stack.Count == 1)
                {
                    return(converter.Finalize(stack.Pop().Value));
                }
                return(default(T));
            }
Ejemplo n.º 9
0
 public static TypeAnnotation FromType <T>(TypeAnnotationConverter <T> converter, T type) where T : class
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 10
0
 public override bool Apply <T>(TypeAnnotationConverter <T> converter, Stack <KeyValuePair <string, T> > stack)
 {
     stack.Push(new KeyValuePair <string, T>(nameof(StartListOp), null));
     return(true);
 }
Ejemplo n.º 11
0
 public abstract bool Apply <T>(TypeAnnotationConverter <T> converter, Stack <KeyValuePair <string, T> > stack) where T : class;