Exemplo n.º 1
0
        public void TypeSlimVisitor_Visit_ResultIsSame()
        {
            var visitor   = new TypeSlimVisitor();
            var slimifier = new TypeToTypeSlimConverter();
            var slim      = slimifier.Visit(typeof(List <int[]>));

            Assert.AreSame(slim, visitor.Visit(slim));
        }
Exemplo n.º 2
0
        public void TypeSlim_AnonymousType_ToCSharpString()
        {
            var type = new { a = 42 }.GetType();

            var slimifier = new TypeToTypeSlimConverter();
            var slim      = slimifier.Visit(type);

            Assert.AreEqual("{ int a; }", slim.ToCSharpString());
        }
        public void TypeToTypeSlimConverter_System()
        {
            var ttsc = new TypeToTypeSlimConverter();
            var tstc = new TypeSlimToTypeConverter(DefaultReflectionProvider.Instance);

            foreach (var t in typeof(Uri).Assembly.GetTypes().Where(t => t.Namespace == "System"))
            {
                Roundtrip(ttsc, tstc, t);
            }
        }
        public void TypeSlimToTypeConverter_Resolve_Success()
        {
            var typeToSlim   = new TypeToTypeSlimConverter();
            var visitor      = new TypeSlimToTypeConverter(DefaultReflectionProvider.Instance);
            var longTypeSlim = typeToSlim.Visit(typeof(long));

            visitor.MapType(longTypeSlim, typeof(int));
            var longType = visitor.Visit(longTypeSlim);

            Assert.AreEqual(typeof(int), longType);
            visitor.MapType(longTypeSlim, typeof(int));
        }
Exemplo n.º 5
0
        public void TypeSlim_RecursiveRecordType_ToString()
        {
            var rtc     = new RuntimeCompiler();
            var builder = rtc.GetNewRecordTypeBuilder();

            rtc.DefineRecordType(
                builder,
                new Dictionary <string, Type>
            {
                { "self", builder }
            }.AsEnumerable(),
                true
                );

            var type = builder.CreateType();

            var slimifier = new TypeToTypeSlimConverter();
            var slim      = slimifier.Visit(type);

            Assert.AreEqual("{self : {1}} as {1}", slim.ToString());
        }
        private static void Roundtrip(TypeToTypeSlimConverter ttsc, TypeSlimToTypeConverter tstc, global::System.Type t)
        {
            var slim = ttsc.Visit(t);

            var exp = t.IsGenericTypeDefinition ? TypeSlimKind.GenericDefinition : TypeSlimKind.Simple;

            Assert.AreEqual(exp, slim.Kind);

            var simple = slim as SimpleTypeSlimBase;

            Assert.IsNotNull(simple, t.Name);

            Assert.AreEqual(t.FullName, simple.Name);

            var asm = simple.Assembly;

            Assert.IsNotNull(asm, t.Name);

            Assert.AreEqual(t.Assembly.FullName, asm.Name);

            var res = tstc.Visit(slim);

            Assert.AreSame(t, res);
        }
Exemplo n.º 7
0
        public void ExpressionSlim_Update_Tests()
        {
            var boolSlim = new TypeToTypeSlimConverter().Visit(typeof(bool));
            var intExpr1 = ExpressionSlim.Parameter(SlimType);
            var intExpr2 = ExpressionSlim.Parameter(SlimType);
            var intExpr3 = ExpressionSlim.Parameter(SlimType);
            var boolExpr1 = ExpressionSlim.Parameter(boolSlim);
            var boolExpr2 = ExpressionSlim.Parameter(boolSlim);
            var prop = SlimType.GetProperty("Foo", propertyType: null, EmptyReadOnlyCollection <TypeSlim> .Instance, canWrite: true);
            var elementInits = new ElementInitSlim[] { new ElementInitSlim(addMethod: null, arguments: null) }.ToReadOnly();
            var method = SlimType.GetSimpleMethod("Foo", EmptyReadOnlyCollection <TypeSlim> .Instance, returnType: null);

            var b = ExpressionSlim.Add(intExpr1, intExpr2);

            Assert.AreNotSame(b, b.Update(intExpr1, conversion: null, intExpr3));
            Assert.AreNotSame(b, b.Update(intExpr3, conversion: null, intExpr2));

            var c = ExpressionSlim.Condition(boolExpr1, intExpr1, intExpr2);

            Assert.AreNotSame(c, c.Update(boolExpr2, intExpr1, intExpr2));
            Assert.AreNotSame(c, c.Update(boolExpr1, intExpr2, intExpr3));
            Assert.AreNotSame(c, c.Update(boolExpr1, intExpr1, intExpr3));

            var i = ExpressionSlim.MakeIndex(intExpr1, prop, new ExpressionSlim[] { intExpr2 }.ToReadOnly());

            Assert.AreNotSame(i, i.Update(intExpr2, new ExpressionSlim[] { intExpr2 }.ToReadOnly()));
            Assert.AreNotSame(i, i.Update(intExpr1, new ExpressionSlim[] { intExpr3 }.ToReadOnly()));

            var inv = ExpressionSlim.Invoke(intExpr1, new[] { intExpr2 });

            Assert.AreNotSame(inv, inv.Update(intExpr2, new ExpressionSlim[] { intExpr2 }.ToReadOnly()));
            Assert.AreNotSame(inv, inv.Update(intExpr1, new ExpressionSlim[] { intExpr3 }.ToReadOnly()));

            var l = ExpressionSlim.Lambda(intExpr1);

            Assert.AreNotSame(l, l.Update(intExpr2, EmptyReadOnlyCollection <ParameterExpressionSlim> .Instance));
            Assert.AreNotSame(l, l.Update(intExpr1, new ParameterExpressionSlim[] { ExpressionSlim.Parameter(SlimType) }.ToReadOnly()));

            var li = ExpressionSlim.ListInit(ExpressionSlim.New(SlimType));

            Assert.AreNotSame(li, li.Update(ExpressionSlim.New(boolSlim), elementInits));
            Assert.AreNotSame(li, li.Update(ExpressionSlim.New(SlimType), elementInits));

            var ma = ExpressionSlim.Bind(prop, intExpr1);

            Assert.AreNotSame(ma, ma.Update(intExpr2));

            var macc = ExpressionSlim.MakeMemberAccess(instance: null, prop);

            Assert.AreNotSame(macc, macc.Update(intExpr1));

            var ml = ExpressionSlim.ListBind(prop);

            Assert.AreNotSame(ml, ml.Update(elementInits));

            var mm = ExpressionSlim.MemberBind(prop);

            Assert.AreNotSame(mm, mm.Update(new MemberBindingSlim[] { ExpressionSlim.Bind(prop, intExpr1) }.ToReadOnly()));

            var m = ExpressionSlim.Call(method);

            Assert.AreNotSame(m, m.Update(intExpr1, new ExpressionSlim[] { intExpr2 }.ToReadOnly()));
            Assert.AreNotSame(m, m.Update(@object: null, new ExpressionSlim[] { intExpr2 }.ToReadOnly()));

            var na = ExpressionSlim.NewArrayInit(SlimType);

            Assert.AreNotSame(na, na.Update(new ExpressionSlim[] { intExpr1 }.ToReadOnly()));

            var nb = ExpressionSlim.NewArrayBounds(SlimType, intExpr1);

            Assert.AreNotSame(nb, nb.Update(new ExpressionSlim[] { intExpr2 }.ToReadOnly()));

            var ctor = SlimType.GetConstructor(new TypeSlim[] { SlimType }.ToReadOnly());
            var n    = ExpressionSlim.New(ctor, ExpressionSlim.Parameter(SlimType));

            Assert.AreNotSame(n, n.Update(new ExpressionSlim[] { ExpressionSlim.Default(SlimType) }.ToReadOnly()));

            var t = ExpressionSlim.TypeIs(intExpr1, SlimType);

            Assert.AreNotSame(t, t.Update(intExpr2));

            var u = ExpressionSlim.Not(boolExpr1);

            Assert.AreNotSame(u, u.Update(boolExpr2));
        }