Example #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));
        }
Example #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);
                }
Example #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);
                }
Example #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);
                }
Example #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);
                }
Example #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);
                }
Example #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);
                }
Example #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));
            }
Example #9
0
 public static TypeAnnotation FromType <T>(TypeAnnotationConverter <T> converter, T type) where T : class
 {
     throw new NotImplementedException();
 }
Example #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);
 }
Example #11
0
 public abstract bool Apply <T>(TypeAnnotationConverter <T> converter, Stack <KeyValuePair <string, T> > stack) where T : class;