/// <summary> /// Checks the type. /// </summary> private static void CheckType(Type type) { var name = type.AssemblyQualifiedName; Assert.IsNotNull(name); var res = TypeNameParser.Parse(name); Assert.AreEqual(type.Name, res.GetName() + res.GetArray()); if (res.Generics == null) { Assert.AreEqual(type.FullName, res.GetNameWithNamespace() + res.GetArray()); } Assert.AreEqual(type.FullName.Length + 2, res.AssemblyStart); }
public void TypeWithAssemblyNameWithPublicKey() { const string ns = "MyNamespace"; const string name = "MyType"; var assemblyRef = new AssemblyReference( "MyAssembly", new Version(1, 2, 3, 4), false, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }); var expected = new TypeReference(assemblyRef, ns, name).ToTypeSignature(); var actual = TypeNameParser.Parse(_module, $"{ns}.{name}, {assemblyRef.FullName}"); Assert.Equal(expected, actual, _comparer); }
public void MultipleGeneric() { var parsedTypeName = TypeNameParser.Parse("a<b|c,d|e>"); Assert.Equal("a", parsedTypeName.TypeName); Assert.Null(parsedTypeName.Assembly); var parameters = parsedTypeName.GenericParameters; Assert.NotNull(parameters); Assert.NotEmpty(parameters); Assert.Equal(2, parameters.Count); Assert.Equal("b", parameters[0].Assembly); Assert.Equal("c", parameters[0].TypeName); Assert.Null(parameters[0].GenericParameters); Assert.Equal("d", parameters[1].Assembly); Assert.Equal("e", parameters[1].TypeName); Assert.Null(parameters[1].GenericParameters); }
public void CustomArray() { var expectedType = "A[]"; var a = TypeNameParser.Parse(expectedType); Assert.AreEqual(expectedType, a.ToString()); expectedType = typeof(MyGClass <int>[]).FullName; a = TypeNameParser.Parse(expectedType); Assert.AreEqual(expectedType, a.ToString()); expectedType = typeof(MyGClass <int[]>[]).FullName; a = TypeNameParser.Parse(expectedType); Assert.AreEqual(expectedType, a.ToString()); expectedType = "MyGClass`1[[System.Int32[]]][]"; a = TypeNameParser.Parse(expectedType); Assert.AreEqual(expectedType, a.ToString()); }
public void TwoLevelsDeep() { var parsedTypeName = TypeNameParser.Parse("a<b|c<d|e>>"); Assert.Equal("a", parsedTypeName.TypeName); Assert.Null(parsedTypeName.Assembly); var parameters = parsedTypeName.GenericParameters; Assert.NotNull(parameters); Assert.NotEmpty(parameters); Assert.Equal(1, parameters.Count); Assert.Equal("b", parameters[0].Assembly); Assert.Equal("c", parameters[0].TypeName); Assert.NotNull(parameters[0].GenericParameters); Assert.NotEmpty(parameters[0].GenericParameters); Assert.Equal(1, parameters[0].GenericParameters.Count); Assert.Equal("d", parameters[0].GenericParameters[0].Assembly); Assert.Equal("e", parameters[0].GenericParameters[0].TypeName); Assert.Null(parameters[0].GenericParameters[0].GenericParameters); }
/// <summary> /// Gets the assembly from remote nodes. /// </summary> /// <param name="typeName">Assembly-qualified type name.</param> /// <param name="ignite">Ignite.</param> /// <param name="originNodeId">Originating node identifier.</param> /// <returns> /// Resulting type or null. /// </returns> public static Type LoadAssemblyAndGetType(string typeName, IIgniteInternal ignite, Guid originNodeId) { Debug.Assert(!string.IsNullOrEmpty(typeName)); var parsedName = TypeNameParser.Parse(typeName); var assemblyName = parsedName.GetAssemblyName(); Debug.Assert(assemblyName != null); var asm = GetAssembly(ignite, assemblyName, originNodeId); if (asm == null) { return(null); } // Assembly.GetType does not work for assembly-qualified names. Full name is required without assembly. return(asm.GetType(parsedName.GetFullName(), false)); }
public void TestSimpleTypes() { // One letter. var res = TypeNameParser.Parse("x"); Assert.AreEqual("x", res.GetNameWithNamespace()); Assert.AreEqual("x", res.GetName()); Assert.AreEqual(0, res.NameStart); Assert.AreEqual(0, res.NameEnd); Assert.AreEqual(0, res.FullNameEnd); Assert.AreEqual(-1, res.AssemblyStart); Assert.AreEqual(-1, res.AssemblyEnd); Assert.IsNull(res.Generics); // Without assembly. res = TypeNameParser.Parse("System.Int"); Assert.AreEqual(7, res.NameStart); Assert.AreEqual(9, res.NameEnd); Assert.AreEqual(9, res.FullNameEnd); Assert.IsNull(res.Generics); Assert.AreEqual(-1, res.AssemblyStart); // With assembly. res = TypeNameParser.Parse("System.Int, myasm, Ver=1"); Assert.AreEqual(7, res.NameStart); Assert.AreEqual(9, res.NameEnd); Assert.AreEqual(9, res.FullNameEnd); Assert.IsNull(res.Generics); Assert.AreEqual(12, res.AssemblyStart); // Real types. CheckType(GetType()); CheckType(typeof(string)); CheckType(typeof(IDictionary)); // Nested types. CheckType(typeof(Nested)); CheckType(typeof(Nested.Nested2)); }
public void ParsesComplicatedType() { var inner = TypeNameParser.Parse("Ns1.Class<T1,T2.T3>.Inner"); Assert.AreEqual("Inner", inner.Surname); var clas = inner.ContainingType.Value; Assert.AreEqual(0, inner.GenericArguments.Count); Assert.AreEqual("Class", clas.Surname); var ns1 = clas.ContainingType.Value; Assert.AreEqual("Ns1", ns1.Surname); Assert.False(ns1.ContainingType.HasValue); var t1 = clas.GenericArguments.Get(0); Assert.AreEqual("T1", t1.Surname); var t3 = clas.GenericArguments.Get(1); Assert.AreEqual("T3", t3.Surname); Assert.AreEqual("T2", t3.ContainingType.Value.Surname); }
/// <summary> /// Reads a single security attribute from the provided input blob stream. /// </summary> /// <param name="parentModule">The module that the security attribute resides in.</param> /// <param name="reader">The input blob stream.</param> /// <returns>The security attribute.</returns> public static SecurityAttribute FromReader(ModuleDefinition parentModule, IBinaryStreamReader reader) { var type = TypeNameParser.Parse(parentModule, reader.ReadSerString()); var result = new SecurityAttribute(type); if (!reader.TryReadCompressedUInt32(out uint size)) { return(result); } if (!reader.TryReadCompressedUInt32(out uint namedArgumentCount)) { return(result); } for (int i = 0; i < namedArgumentCount; i++) { var argument = CustomAttributeNamedArgument.FromReader(parentModule, reader); result.NamedArguments.Add(argument); } return(result); }
internal static TypeSignature ReadFieldOrPropType(ModuleDefinition parentModule, IBinaryStreamReader reader) { var elementType = (ElementType)reader.ReadByte(); switch (elementType) { case ElementType.Boxed: return(parentModule.CorLibTypeFactory.Object); case ElementType.SzArray: return(new SzArrayTypeSignature(ReadFieldOrPropType(parentModule, reader))); case ElementType.Enum: return(TypeNameParser.Parse(parentModule, reader.ReadSerString())); case ElementType.Type: return(new TypeDefOrRefSignature(new TypeReference(parentModule, parentModule.CorLibTypeFactory.CorLibScope, "System", "Type"))); default: return(parentModule.CorLibTypeFactory.FromElementType(elementType)); } }
/// <summary> /// Reads a single safe array marshal descriptor from the provided input stream. /// </summary> /// <param name="parentModule">The module defining the descriptor.</param> /// <param name="reader">The input stream.</param> /// <returns>The descriptor.</returns> public new static SafeArrayMarshalDescriptor FromReader(ModuleDefinition parentModule, IBinaryStreamReader reader) { if (!reader.TryReadCompressedUInt32(out uint type)) { return(new SafeArrayMarshalDescriptor(SafeArrayVariantType.NotSet)); } var variantType = (SafeArrayVariantType)type & SafeArrayVariantType.TypeMask; var flags = (SafeArrayTypeFlags)type & ~SafeArrayTypeFlags.Mask; var result = new SafeArrayMarshalDescriptor(variantType, flags); if (reader.CanRead(1)) { string typeName = reader.ReadSerString(); if (typeName != null) { result.UserDefinedSubType = TypeNameParser.Parse(parentModule, typeName); } } return(result); }
public override object NullSafeGet(IDataReader rs, string[] names, object owner) { var typename = TypeNameParser.Parse((string)NHibernateUtil.String.Get(rs, names[0]))); return Type.GetType(typename.Type + ", " + new AssemblyName(typename.Assembly).Name); }
public void ParseInvalidEscape() { Assert.Throws <ArgumentException>(() => TypeNameParser.Parse("\\")); }
private static object ReadValue(ModuleDefinition parentModule, TypeSignature valueType, IBinaryStreamReader reader) { switch (valueType.ElementType) { case ElementType.Boolean: return(reader.ReadByte() == 1); case ElementType.Char: return((char)reader.ReadUInt16()); case ElementType.R4: return(reader.ReadSingle()); case ElementType.R8: return(reader.ReadDouble()); case ElementType.I1: return(reader.ReadSByte()); case ElementType.I2: return(reader.ReadInt16()); case ElementType.I4: return(reader.ReadInt32()); case ElementType.I8: return(reader.ReadInt64()); case ElementType.U1: return(reader.ReadByte()); case ElementType.U2: return(reader.ReadUInt16()); case ElementType.U4: return(reader.ReadUInt32()); case ElementType.U8: return(reader.ReadUInt64()); case ElementType.String: return(reader.ReadSerString()); case ElementType.Object: return(ReadValue(parentModule, TypeSignature.ReadFieldOrPropType(parentModule, reader), reader)); case ElementType.Class: case ElementType.Enum: case ElementType.ValueType: var enumTypeDef = parentModule.MetadataResolver.ResolveType(valueType); if (enumTypeDef != null && enumTypeDef.IsEnum) { return(ReadValue(parentModule, enumTypeDef.GetEnumUnderlyingType(), reader)); } break; } if (valueType.IsTypeOf("System", "Type")) { return(TypeNameParser.Parse(parentModule, reader.ReadSerString())); } throw new NotSupportedException($"Unsupported element type {valueType.ElementType}."); }
/// <summary> /// Configure NHibernate.Validator using the specified <see cref="INHVConfiguration"/>. /// </summary> /// <param name="config">The <see cref="INHVConfiguration"/> that is the configuration reader to configure NHibernate.Validator.</param> /// <param name="mappingLoader">The <see cref="XmlMappingLoader"/> instance.</param> /// <remarks> /// Calling Configure(INHVConfiguration) will overwrite the values set in app.config or web.config /// </remarks> public virtual void Configure(INHVConfiguration config, IMappingLoader mappingLoader) { if (config == null) { throw new ValidatorConfigurationException("Could not configure NHibernate.Validator.", new ArgumentNullException("config")); } Clear(); applyToDDL = PropertiesHelper.GetBoolean(Environment.ApplyToDDL, config.Properties, true); autoRegisterListeners = PropertiesHelper.GetBoolean(Environment.AutoregisterListeners, config.Properties, true); defaultMode = CfgXmlHelper.ValidatorModeConvertFrom(PropertiesHelper.GetString(Environment.ValidatorMode, config.Properties, string.Empty)); interpolator = GetImplementation <IMessageInterpolator>( PropertiesHelper.GetString(Environment.MessageInterpolatorClass, config.Properties, string.Empty), "message interpolator"); if (Environment.ConstraintValidatorFactory == null) { constraintValidatorFactory = GetImplementation <IConstraintValidatorFactory>( PropertiesHelper.GetString(Environment.ConstraintValidatorFactoryClass, config.Properties, string.Empty), "Constraint Validator Factory") ?? new DefaultConstraintValidatorFactory(); } else { constraintValidatorFactory = Environment.ConstraintValidatorFactory; } var inspectorsTypes = new HashSet <System.Type>(config.EntityTypeInspectors) { typeof(DefaultEntityTypeInspector) }; if (inspectorsTypes.Count > 1) { var inspectors = config.EntityTypeInspectors.Select(typeInspector => Instatiate <IEntityTypeInspector>(typeInspector)).ToArray(); entityTypeInspector = new MultiEntityTypeInspector(inspectors); } else { entityTypeInspector = new DefaultEntityTypeInspector(); } ResourceManager customResourceManager = null; var customResourceManagerBaseName = PropertiesHelper.GetString(Environment.CustomResourceManager, config.Properties, null); if (!string.IsNullOrEmpty(customResourceManagerBaseName)) { var resourceAndAssembly = TypeNameParser.Parse(customResourceManagerBaseName); try { var assembly = Assembly.Load(resourceAndAssembly.Assembly); customResourceManager = new ResourceManager(resourceAndAssembly.Type, assembly); } catch (Exception e) { throw new ValidatorConfigurationException("Could not configure NHibernate.Validator (custom resource manager).", e); } } factory = new StateFullClassValidatorFactory(constraintValidatorFactory, customResourceManager, null, interpolator, defaultMode, entityTypeInspector); // UpLoad Mappings if (mappingLoader == null) { // Configured or Default loader (XmlMappingLoader) mappingLoader = GetImplementation <IMappingLoader>( PropertiesHelper.GetString(Environment.MappingLoaderClass, config.Properties, string.Empty), "mapping loader") ?? new XmlMappingLoader(); } mappingLoader.LoadMappings(config.Mappings); Initialize(mappingLoader); }
public void EmptyTypeName(string typeName) { var exception = Assert.Throws <WeavingException>(() => TypeNameParser.Parse(typeName)); Assert.Equal("Expected a name, got <end of type>", exception.Message); }
public void UnrecognizedEscapeSequence() { var exception = Assert.Throws <WeavingException>(() => TypeNameParser.Parse("\\a")); Assert.Equal("Unrecognized escape sequence '\\a'", exception.Message); }
public void UnbalancedTypeSpec_AssemblyName() { var exception = Assert.Throws <WeavingException>(() => TypeNameParser.Parse("a<b")); Assert.Equal("Expected assembly name separator, got <end of type>", exception.Message); }
public void ParseUnmatchedEscapedBracket() { TypeNameParser.Parse("SomeName\\["); }
public void UnexpectedGenericTypeStart(string typeName) { var exception = Assert.Throws <WeavingException>(() => TypeNameParser.Parse(typeName)); Assert.Equal("Unexpected generic type start", exception.Message); }
public void UnexpectedNameToken(string typeName) { var exception = Assert.Throws <WeavingException>(() => TypeNameParser.Parse(typeName)); Assert.Equal("Unexpected name token", exception.Message); }
public void GenericTypeMissingAssemblyNameSeparator_UnexpectedGenericTypeSeparator() { var exception = Assert.Throws <WeavingException>(() => TypeNameParser.Parse("a<b,")); Assert.Equal("Expected assembly name separator, got ,", exception.Message); }
public void UnexpectedAssemblyNameSeparator(string typeName) { var exception = Assert.Throws <WeavingException>(() => TypeNameParser.Parse(typeName)); Assert.Equal("Unexpected assembly name separator", exception.Message); }
public void UnbalancedTypeSpec_TypeName() { var exception = Assert.Throws <WeavingException>(() => TypeNameParser.Parse("a<b|c")); Assert.Equal("Unbalanced type specification, are you missing a >?", exception.Message); }
private string GetClassNameWithoutAssembly(string unqualifiedName) { return(TypeNameParser.Parse(unqualifiedName, mappings.DefaultNamespace, mappings.DefaultAssembly).Type); }
public void TestGenericTypes() { // Custom strings. var res = TypeNameParser.Parse("List`1[[Int]]"); Assert.AreEqual("List`1", res.GetName()); Assert.AreEqual("List`1", res.GetFullName()); Assert.AreEqual("Int", res.Generics.Single().GetName()); Assert.AreEqual("Int", res.Generics.Single().GetFullName()); // One arg. res = TypeNameParser.Parse(typeof(List <int>).AssemblyQualifiedName); Assert.AreEqual("List`1", res.GetName()); Assert.AreEqual("System.Collections.Generic.List`1", res.GetFullName()); Assert.IsTrue(res.GetAssemblyName().StartsWith("mscorlib,")); Assert.AreEqual(1, res.Generics.Count); var gen = res.Generics.Single(); Assert.AreEqual("Int32", gen.GetName()); Assert.AreEqual("System.Int32", gen.GetFullName()); Assert.IsTrue(gen.GetAssemblyName().StartsWith("mscorlib,")); // Two args. res = TypeNameParser.Parse(typeof(Dictionary <int, string>).AssemblyQualifiedName); Assert.AreEqual("Dictionary`2", res.GetName()); Assert.AreEqual("System.Collections.Generic.Dictionary`2", res.GetFullName()); Assert.IsTrue(res.GetAssemblyName().StartsWith("mscorlib,")); Assert.AreEqual(2, res.Generics.Count); gen = res.Generics.First(); Assert.AreEqual("Int32", gen.GetName()); Assert.AreEqual("System.Int32", gen.GetFullName()); Assert.IsTrue(gen.GetAssemblyName().StartsWith("mscorlib,")); gen = res.Generics.Last(); Assert.AreEqual("String", gen.GetName()); Assert.AreEqual("System.String", gen.GetFullName()); Assert.IsTrue(gen.GetAssemblyName().StartsWith("mscorlib,")); // Nested args. res = TypeNameParser.Parse(typeof(Dictionary <int, List <string> >).FullName); Assert.AreEqual("Dictionary`2", res.GetName()); Assert.AreEqual("System.Collections.Generic.Dictionary`2", res.GetFullName()); Assert.IsNull(res.GetAssemblyName()); Assert.AreEqual(2, res.Generics.Count); gen = res.Generics.Last(); Assert.AreEqual("List`1", gen.GetName()); Assert.AreEqual("System.Collections.Generic.List`1", gen.GetFullName()); Assert.IsTrue(gen.GetAssemblyName().StartsWith("mscorlib,")); Assert.AreEqual(1, gen.Generics.Count); gen = gen.Generics.Single(); Assert.AreEqual("String", gen.GetName()); Assert.AreEqual("System.String", gen.GetFullName()); Assert.IsTrue(gen.GetAssemblyName().StartsWith("mscorlib,")); // Nested class. res = TypeNameParser.Parse(typeof(NestedGeneric <int>).FullName); Assert.AreEqual("NestedGeneric`1", res.GetName()); Assert.AreEqual("Apache.Ignite.Core.Tests.Binary.TypeNameParserTest+NestedGeneric`1", res.GetFullName()); gen = res.Generics.Single(); Assert.AreEqual("Int32", gen.GetName()); Assert.AreEqual("System.Int32", gen.GetFullName()); res = TypeNameParser.Parse(typeof(NestedGeneric <int> .NestedGeneric2 <string>).AssemblyQualifiedName); Assert.AreEqual("NestedGeneric2`1", res.GetName()); Assert.AreEqual("Apache.Ignite.Core.Tests.Binary.TypeNameParserTest+NestedGeneric`1+NestedGeneric2`1", res.GetFullName()); Assert.AreEqual(2, res.Generics.Count); Assert.AreEqual("Int32", res.Generics.First().GetName()); Assert.AreEqual("String", res.Generics.Last().GetName()); }
/// <summary> /// Formats the specified token. /// </summary> /// <param name="token">The token.</param> /// <returns>The token in serialized form.</returns> protected override string Format(TypeToken token) { typeCache[token.Id] = TypeNameParser.Parse(token.TypeName).GetTypeNameInCode(false); return(""); }
private static bool TestType(Type typeToTest, string typeName, TestMethod selectedTestMethod, int currentTestNo) { var testMethodName = selectedTestMethod.ToString("F"); var passed = false; var fgColor = IsUnix ? ConsoleColor.Black : Console.ForegroundColor; try { Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++"); Console.WriteLine("Test no: " + currentTestNo); Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++"); Console.ForegroundColor = fgColor; Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("Type's "); Console.WriteLine(testMethodName + ": "); Console.WriteLine("------------------------------------------------"); Console.ForegroundColor = fgColor; Console.WriteLine(typeName); var result = TypeNameParser.Parse(typeName, false); var tn = (result != null ? result.Scope : null); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("Parser's "); Console.WriteLine(testMethodName + ": "); Console.WriteLine("------------------------------------------------"); Console.ForegroundColor = fgColor; var tns = (string)null; if (tn != null) { switch (selectedTestMethod) { case TestMethod.AssemblyQualifiedName: tns = tn.AssemblyQualifiedName; break; case TestMethod.FullName: tns = tn.FullName; break; case TestMethod.ToString: tns = tn.ShortName; break; } } Console.WriteLine(tns); Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("------------------------------------------------"); Console.ForegroundColor = fgColor; passed = ((typeName ?? String.Empty).Trim() == tns); if (passed) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("PARSING PASSED"); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("PARSING FAILED !!!"); } var type = (result.Scope != null) ? result.Scope.ResolveType(false, true) : null; passed = (type != null && type == typeToTest); if (passed) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("RESOLVE PASSED"); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("RESOLVE FAILED !!!"); } } finally { Console.ForegroundColor = fgColor; } return(passed); }
public void TestGenericTypes() { // Simple name. var res = TypeNameParser.Parse("List`1[[Int]]"); Assert.AreEqual("List`1", res.GetName()); Assert.AreEqual("List`1", res.GetNameWithNamespace()); Assert.AreEqual("Int", res.Generics.Single().GetName()); Assert.AreEqual("Int", res.Generics.Single().GetNameWithNamespace()); // Simple name array. res = TypeNameParser.Parse("List`1[[Byte[]]]"); Assert.AreEqual("List`1", res.GetName()); Assert.AreEqual("List`1", res.GetNameWithNamespace()); Assert.AreEqual("Byte", res.Generics.Single().GetName()); Assert.AreEqual("Byte", res.Generics.Single().GetNameWithNamespace()); Assert.AreEqual("[]", res.Generics.Single().GetArray()); // Simple name two-dimension array. res = TypeNameParser.Parse("List`1[[Byte[,]]]"); Assert.AreEqual("List`1", res.GetName()); Assert.AreEqual("List`1", res.GetNameWithNamespace()); Assert.AreEqual("Byte", res.Generics.Single().GetName()); Assert.AreEqual("Byte", res.Generics.Single().GetNameWithNamespace()); Assert.AreEqual("[,]", res.Generics.Single().GetArray()); // Simple name jagged array. res = TypeNameParser.Parse("List`1[[Byte[][]]]"); Assert.AreEqual("List`1", res.GetName()); Assert.AreEqual("List`1", res.GetNameWithNamespace()); Assert.AreEqual("Byte", res.Generics.Single().GetName()); Assert.AreEqual("Byte", res.Generics.Single().GetNameWithNamespace()); Assert.AreEqual("[][]", res.Generics.Single().GetArray()); // Open generic. res = TypeNameParser.Parse("List`1"); Assert.AreEqual("List`1", res.GetName()); Assert.AreEqual("List`1", res.GetNameWithNamespace()); Assert.IsEmpty(res.Generics); // One arg. res = TypeNameParser.Parse(typeof(List <int>).AssemblyQualifiedName); Assert.AreEqual("List`1", res.GetName()); Assert.AreEqual("System.Collections.Generic.List`1", res.GetNameWithNamespace()); Assert.IsTrue(res.GetAssemblyName().StartsWith("mscorlib,")); Assert.AreEqual(1, res.Generics.Count); var gen = res.Generics.Single(); Assert.AreEqual("Int32", gen.GetName()); Assert.AreEqual("System.Int32", gen.GetNameWithNamespace()); Assert.IsTrue(gen.GetAssemblyName().StartsWith("mscorlib,")); // One arg open. res = TypeNameParser.Parse(typeof(List <>).AssemblyQualifiedName); Assert.AreEqual("List`1", res.GetName()); Assert.AreEqual("System.Collections.Generic.List`1", res.GetNameWithNamespace()); Assert.IsTrue(res.GetAssemblyName().StartsWith("mscorlib,")); Assert.IsEmpty(res.Generics); // Two args. res = TypeNameParser.Parse(typeof(Dictionary <int, string>).AssemblyQualifiedName); Assert.AreEqual("Dictionary`2", res.GetName()); Assert.AreEqual("System.Collections.Generic.Dictionary`2", res.GetNameWithNamespace()); Assert.IsTrue(res.GetAssemblyName().StartsWith("mscorlib,")); Assert.AreEqual(2, res.Generics.Count); gen = res.Generics.First(); Assert.AreEqual("Int32", gen.GetName()); Assert.AreEqual("System.Int32", gen.GetNameWithNamespace()); Assert.IsTrue(gen.GetAssemblyName().StartsWith("mscorlib,")); gen = res.Generics.Last(); Assert.AreEqual("String", gen.GetName()); Assert.AreEqual("System.String", gen.GetNameWithNamespace()); Assert.IsTrue(gen.GetAssemblyName().StartsWith("mscorlib,")); // Nested args. res = TypeNameParser.Parse(typeof(Dictionary <int, List <string> >).FullName); Assert.AreEqual("Dictionary`2", res.GetName()); Assert.AreEqual("System.Collections.Generic.Dictionary`2", res.GetNameWithNamespace()); Assert.IsNull(res.GetAssemblyName()); Assert.AreEqual(2, res.Generics.Count); gen = res.Generics.Last(); Assert.AreEqual("List`1", gen.GetName()); Assert.AreEqual("System.Collections.Generic.List`1", gen.GetNameWithNamespace()); Assert.IsTrue(gen.GetAssemblyName().StartsWith("mscorlib,")); Assert.AreEqual(1, gen.Generics.Count); gen = gen.Generics.Single(); Assert.AreEqual("String", gen.GetName()); Assert.AreEqual("System.String", gen.GetNameWithNamespace()); Assert.IsTrue(gen.GetAssemblyName().StartsWith("mscorlib,")); // Nested class. res = TypeNameParser.Parse(typeof(NestedGeneric <int>).FullName); Assert.AreEqual("NestedGeneric`1", res.GetName()); Assert.AreEqual("Apache.Ignite.Core.Tests.Binary.TypeNameParserTest+NestedGeneric`1", res.GetNameWithNamespace()); gen = res.Generics.Single(); Assert.AreEqual("Int32", gen.GetName()); Assert.AreEqual("System.Int32", gen.GetNameWithNamespace()); res = TypeNameParser.Parse(typeof(NestedGeneric <int> .NestedGeneric2 <string>).AssemblyQualifiedName); Assert.AreEqual("NestedGeneric2`1", res.GetName()); Assert.AreEqual("Apache.Ignite.Core.Tests.Binary.TypeNameParserTest+NestedGeneric`1+NestedGeneric2`1", res.GetNameWithNamespace()); Assert.AreEqual(2, res.Generics.Count); Assert.AreEqual("Int32", res.Generics.First().GetName()); Assert.AreEqual("String", res.Generics.Last().GetName()); }
public void GenericParamSeparatorWithoutTypeName(string typeName) { var exception = Assert.Throws <WeavingException>(() => TypeNameParser.Parse(typeName)); Assert.Equal("Expected a name, got ,", exception.Message); }