public ExpectedData(Type type) { Namespace = type.Namespace; FullName = type.FullName; GenericArguments = type.GetGenericArguments().Select(arg => new ExpectedData(arg)).ToArray(); AssemblyQualifiedName = type.AssemblyQualifiedName; AssemblyName = type.Assembly.FullName; IsArray = type.IsArray; IsPointer = type.IsPointer; IsReference = type.IsByRef; List <TypeSpecifier> typeSpecifiers = new List <TypeSpecifier>(); while (true) { if (type.IsArray) { typeSpecifiers.Add(TypeSpecifier.Array(type.GetArrayRank())); } else if (type.IsPointer) { typeSpecifiers.Add(TypeSpecifier.Pointer); } else if (type.IsByRef) { typeSpecifiers.Add(TypeSpecifier.Reference); } else { break; } type = type.GetElementType(); } Name = type.Name; NamespaceTypeName = type.Namespace + "." + type.Name; TypeSpecifiers = typeSpecifiers.AsEnumerable().Reverse().ToArray(); }
public static IEnumerable <object[]> GetTestData() { yield return(new object[] { "String", new ExpectedData { Name = "String", Namespace = null, NamespaceTypeName = "String", FullName = "String", GenericArguments = new ExpectedData[0], AssemblyQualifiedName = "String", AssemblyName = null, IsArray = false, IsPointer = false, IsReference = false, TypeSpecifiers = new TypeSpecifier[] { } } }); yield return(new object[] { "System.String", new ExpectedData { Name = "String", Namespace = "System", NamespaceTypeName = "System.String", FullName = "System.String", GenericArguments = new ExpectedData[0], AssemblyQualifiedName = "System.String", AssemblyName = null, IsArray = false, IsPointer = false, IsReference = false, TypeSpecifiers = new TypeSpecifier[] { } } }); yield return(new object[] { "First.Second.TypeName+Nested1+Nested2", new ExpectedData { Name = "Nested2", Namespace = "First.Second", NamespaceTypeName = "First.Second.TypeName+Nested1+Nested2", FullName = "First.Second.TypeName+Nested1+Nested2", GenericArguments = new ExpectedData[0], AssemblyQualifiedName = "First.Second.TypeName+Nested1+Nested2", AssemblyName = null, IsArray = false, IsPointer = false, IsReference = false, TypeSpecifiers = new TypeSpecifier[] { } } }); // FullName of Dictionary<int, List<string>> yield return(new object[] { "System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]", new ExpectedData { Name = "Dictionary`2", Namespace = "System.Collections.Generic", NamespaceTypeName = "System.Collections.Generic.Dictionary`2", FullName = "System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]", GenericArguments = new ExpectedData[] { SystemInt, ListOfString }, AssemblyQualifiedName = "System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]", AssemblyName = null, IsArray = false, IsPointer = false, IsReference = false, TypeSpecifiers = new TypeSpecifier[] { } } }); // AssemblyQualifiedName of Dictionary<int, List<string>> yield return(new object[] { "System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", new ExpectedData { Name = "Dictionary`2", Namespace = "System.Collections.Generic", NamespaceTypeName = "System.Collections.Generic.Dictionary`2", FullName = "System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]", GenericArguments = new ExpectedData[] { SystemInt, ListOfString }, AssemblyQualifiedName = "System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", AssemblyName = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", IsArray = false, IsPointer = false, IsReference = false, TypeSpecifiers = new TypeSpecifier[] { } } }); yield return(new object[] { "System.Int32[][,][,,]", new ExpectedData { Name = "Int32", Namespace = "System", NamespaceTypeName = "System.Int32", FullName = "System.Int32[][,][,,]", GenericArguments = new ExpectedData[0], AssemblyQualifiedName = "System.Int32[][,][,,]", AssemblyName = null, IsArray = true, IsPointer = false, IsReference = false, TypeSpecifiers = new TypeSpecifier[] { TypeSpecifier.Array(1), TypeSpecifier.Array(2), TypeSpecifier.Array(3) } } }); // AssemblyQualifiedName of List<int[][,,]>[] yield return(new object[] { "System.Collections.Generic.List`1[[System.Int32[,,][], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]][], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", new ExpectedData { Name = "List`1", Namespace = "System.Collections.Generic", NamespaceTypeName = "System.Collections.Generic.List`1", FullName = "System.Collections.Generic.List`1[[System.Int32[,,][], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]][]", GenericArguments = new ExpectedData[] { SystemStackedArray }, AssemblyQualifiedName = "System.Collections.Generic.List`1[[System.Int32[,,][], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]][], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", AssemblyName = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", IsArray = true, IsPointer = false, IsReference = false, TypeSpecifiers = new TypeSpecifier[] { TypeSpecifier.Array(1) } } }); yield return(new object[] { "System.Int32[,]*[*]*&, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", new ExpectedData { Name = "Int32", Namespace = "System", NamespaceTypeName = "System.Int32", FullName = "System.Int32[,]*[]*&", GenericArguments = new ExpectedData[0], AssemblyQualifiedName = "System.Int32[,]*[]*&, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", AssemblyName = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", IsArray = false, IsPointer = false, IsReference = true, TypeSpecifiers = new TypeSpecifier[] { TypeSpecifier.Array(2), TypeSpecifier.Pointer, TypeSpecifier.Array(1), TypeSpecifier.Pointer, TypeSpecifier.Reference } } }); }