Exemple #1
0
        static string TestArrayArg(INamedTypeSymbol x)
        {
            var nfo = ClassInfo.FromSymbol(x);

            if (nfo.Name != "DecorationWithArrayType")
            {
                return(getText(nfo));
            }

            Debug.Assert(nfo.Attributes.Count() == 1);

            var attr = nfo.Attributes.First();

            Debug.Assert(attr.PassedArguments.Count() == 1);
            Debug.Assert(attr.PassedArguments.First().GetType() == typeof(object[]));

            Debug.Assert((attr.PassedArguments.First() as object[]).SequenceEqual(new[] { "one", "two" }));

            return(getText(nfo));

            string getText(ClassInfo i)
            {
                return($"// Attribute array argument test. Class name: {i.Name}.");
            }
        }
Exemple #2
0
        public static void ClassType(INamedTypeSymbol symbol)
        {
            var nfo = ClassInfo.FromSymbol(symbol);

            Test.Assert(nfo.TypeInfo.AsClass() != null, "Type should be convertable to class.");
            Test.Assert(nfo.TypeInfo.Kind == CodeGeneration.CSharp.TypeInfo.TypeKind.Class, "Type kind should be 'Class'");
            Test.Assert(nfo.DataTypeInfo != null, "DataTypeInfo must not be null.");
            Test.Assert(nfo.DataTypeInfo.TypeInfo.Name == "ClassType", "Class name was wrongly detected.");
        }
Exemple #3
0
        static string TestSymbol(INamedTypeSymbol x)
        {
            var nfo = ClassInfo.FromSymbol(x);

            var members = string.Join(", ", nfo.Fields.Select(y => y.Name));

            return($"namespace {nfo.Namespace} {{" +
                   $"partial class {x.Name} {{ string test; }}" +
                   $"}}");
        }
Exemple #4
0
        public static void GenericInterfaceImplementation(INamedTypeSymbol symbol)
        {
            var nfo = ClassInfo.FromSymbol(symbol);

            var mtd = nfo.Methods.Single();

            Test.Assert(
                mtd.ReturnType.Name == "T",
                "Wrong type name of generic type argument");
        }
Exemple #5
0
        public static void ClosedGenericField(INamedTypeSymbol symbol)
        {
            var nfo = ClassInfo.FromSymbol(symbol);

            var fld = nfo.Fields.Single();

            Test.Assert(
                fld.Type.FullName == "System.Collections.Generic.List<System.Int32>",
                "Wrong closed generic field type.");
        }
Exemple #6
0
        public static void ParamsAttributeDecoration(INamedTypeSymbol symbol)
        {
            var nfo = ClassInfo.FromSymbol(symbol);

            Test.Assert(nfo.Attributes.Count() == 2, "Wrong number of attributes on a class.");

            var attr = nfo.Attributes.Single(x => x.Type.Name == "ArrayArgAttribute");

            Test.Assert(attr.PassedArguments.Count() == 1, "Wrong number of params arguments in an attribute.");
            Test.Assert(attr.PassedArguments.First().GetType() == typeof(object[]), "Wrong type of attribute parameter.");

            Test.Assert((attr.PassedArguments.First() as object[]).SequenceEqual(new[] { "one", "two" }), "Attribute params argument has wrong values.");
        }
Exemple #7
0
        static string TestProperties(INamedTypeSymbol x)
        {
            var nfo = ClassInfo.FromSymbol(x);

            var expressionProp = nfo.Properties.Single(p => p.Name == "Str");
            var auto1          = nfo.Properties.Single(p => p.Name == "Auto1");
            var auto2          = nfo.Properties.Single(p => p.Name == "Auto2");

            Debug.Assert(expressionProp.IsAutoProperty == false);
            Debug.Assert(auto1.IsAutoProperty == true);
            Debug.Assert(auto2.IsAutoProperty == true);

            return($"namespace {nfo.Namespace} {{" +
                   $"partial class {x.Name} {{ string test; }}" +
                   $"}}");
        }
Exemple #8
0
        public static void OpenGenericField(INamedTypeSymbol symbol)
        {
            var nfo = ClassInfo.FromSymbol(symbol);

            var fld = nfo.Fields.Single();

            Test.Assert(
                fld.Type.Name == "T",
                $"Wrong generic type argument name.\r\n" +
                $"Expected: T\r\n" +
                $"Got: {fld.Type.Name}");

            Test.Assert(
                fld.Type.FullName == "Aikixd.CodeGeneration.Test.CSharp.Target.Standard.OpenGenericField.T",
                $"Wrong generic type argument name. \r\n" +
                $"Expected: Aikixd.CodeGeneration.Test.CSharp.Target.Standard.OpenGenericField.T\r\n" +
                $"Got: {fld.Type.FullName}");
        }
Exemple #9
0
        static string TestType(Compilation c, INamedTypeSymbol x)
        {
            var nfo  = ClassInfo.FromSymbol(x);
            var cNfo = CompilationInfo.FromCompilation(c);

            var attr = nfo.Attributes.First();

            Debug.Assert(
                ((CodeGeneration.CSharp.TypeInfo.TypeInfo)attr.PassedArguments[0]).FullName ==
                "System.IEquatable<Aikixd.CodeGeneration.Test.CSharp.Target.Standard.DecorationWithType>");

            var eqNfo = ((CodeGeneration.CSharp.TypeInfo.TypeInfo)attr.PassedArguments[0]).AsInterface();

            return(getText(nfo));

            string getText(ClassInfo i)
            {
                return($"// Attribute array argument test. Class name: {i.Name}. TypeArg: {((CodeGeneration.CSharp.TypeInfo.TypeInfo)attr.PassedArguments[0]).FullName}");
            }
        }
Exemple #10
0
        static string TestSerialized(INamedTypeSymbol x)
        {
            var nfo = ClassInfo.FromSymbol(x);

            if (nfo.Name != "DecorationWithSerializable")
            {
                return(getText(nfo));
            }

            var attr = nfo.Attributes.First();

            Debug.Assert(attr.Type.Name == "SerializableAttribute");

            return(getText(nfo));

            string getText(ClassInfo i)
            {
                return($"// Serialized test. Class name: {i.FullName}.");
            }
        }
Exemple #11
0
        static string TestRecursive(INamedTypeSymbol x)
        {
            var nfo = ClassInfo.FromSymbol(x);

            if (nfo.Name != "DecorationWithRecursive")
            {
                return(getText(nfo));
            }

            Debug.Assert(nfo.Attributes.Single().Type.Name == nameof(RecursiveAttribute));
            Debug.Assert(nfo.Fields.Single().Type.AsClass().Attributes.Single().Type.Name == nameof(RecursiveAttribute));

            return(getText(nfo));

            string getText(ClassInfo i)
            {
                return($"namespace {i.Namespace} {{" +
                       $"partial class {i.Name} {{ string test; }}" +
                       $"}}");
            }
        }