private static MetadataType ResolveCustomAttributeTypeNameToTypeDesc(string name, ModuleDesc module) { MetadataType containingType = null; StringBuilder typeName = new StringBuilder(name.Length); bool escaped = false; for (var c = name.Begin(); c < name.End(); c++) { if (c.Current == '\\' && !escaped) { escaped = true; continue; } if (escaped) { escaped = false; typeName.Append(c.Current); continue; } if (c.Current == ',') { break; } if (c.Current == '[' || c.Current == '*' || c.Current == '&') { break; } if (c.Current == '+') { if (containingType != null) { containingType = containingType.GetNestedType(typeName.ToString()); } else { containingType = module.GetType(typeName.ToString()); } typeName.Length = 0; continue; } typeName.Append(c.Current); } if (containingType != null) { return(containingType.GetNestedType(typeName.ToString())); } return(module.GetType(typeName.ToString())); }
public TypeNameParsingTests() { _context = new TestTypeSystemContext(TargetArchitecture.X64); // TODO-NICE: split test types into a separate, non-core, module _testModule = _context.CreateModuleForSimpleName("CoreTestAssembly"); _context.SetSystemModule(_testModule); _simpleType = _testModule.GetType("TypeNameParsing", "Simple"); _nestedType = _simpleType.GetNestedType("Nested"); _nestedTwiceType = _nestedType.GetNestedType("NestedTwice"); _genericType = _testModule.GetType("TypeNameParsing", "Generic`1"); _nestedGenericType = _genericType.GetNestedType("NestedGeneric`1"); _nestedNongenericType = _genericType.GetNestedType("NestedNongeneric"); _veryGenericType = _testModule.GetType("TypeNameParsing", "VeryGeneric`3"); _structType = _testModule.GetType("TypeNameParsing", "Struct"); _coreAssemblyQualifier = ((IAssemblyDesc)_testModule).GetName().FullName; }
public void TestNestedTypeReference() { // A type reference nested under a type that has a definition record. The transform is required // to create a type reference for the containing type because a type *definition* can't be a parent // to a type *reference*. var sampleMetadataModule = _context.GetModuleForSimpleName("SampleMetadataAssembly"); Cts.MetadataType genericOutside = sampleMetadataModule.GetType("SampleMetadata", "GenericOutside`1"); Cts.MetadataType inside = genericOutside.GetNestedType("Inside"); { MockPolicy policy = new MockPolicy( type => { return(type == genericOutside); }); var result = MetadataTransform.Run(policy, new[] { sampleMetadataModule }); Assert.Equal(1, result.Scopes.Count); Assert.Equal(1, result.Scopes.Single().GetAllTypes().Count()); var genericOutsideDefRecord = result.GetTransformedTypeDefinition(genericOutside); Assert.NotNull(genericOutsideDefRecord); Assert.Null(result.GetTransformedTypeReference(inside)); var insideRecord = result.Transform.HandleType(inside); Assert.IsType <TypeReference>(insideRecord); var genericOutsideRefRecord = ((TypeReference)insideRecord).ParentNamespaceOrType as TypeReference; Assert.NotNull(genericOutsideRefRecord); Assert.Equal(genericOutside.Name, genericOutsideRefRecord.TypeName.Value); Assert.Same(genericOutsideDefRecord, result.GetTransformedTypeDefinition(genericOutside)); } }
public override MetadataType GetNestedType(string name) { // Return the result from the typical type definition. return(_typeDef.GetNestedType(name)); }
public static MetadataType ResolveCustomAttributeTypeDefinitionName(string name, ModuleDesc module, bool throwIfNotFound) { MetadataType containingType = null; StringBuilder typeName = new StringBuilder(name.Length); bool escaped = false; for (var c = name.Begin(); c < name.End(); c++) { if (c.Current == '\\' && !escaped) { escaped = true; continue; } if (escaped) { escaped = false; typeName.Append(c.Current); continue; } if (c.Current == ',') { break; } if (c.Current == '[' || c.Current == '*' || c.Current == '&') { break; } if (c.Current == '+') { if (containingType != null) { MetadataType outerType = containingType; containingType = outerType.GetNestedType(typeName.ToString()); if (containingType == null) { if (throwIfNotFound) { ThrowHelper.ThrowTypeLoadException(typeName.ToString(), outerType.Module); } return(null); } } else { containingType = module.GetType(typeName.ToString(), throwIfNotFound); if (containingType == null) { return(null); } } typeName.Length = 0; continue; } typeName.Append(c.Current); } if (containingType != null) { MetadataType type = containingType.GetNestedType(typeName.ToString()); if ((type == null) && throwIfNotFound) { ThrowHelper.ThrowTypeLoadException(typeName.ToString(), containingType.Module); } return(type); } return(module.GetType(typeName.ToString(), throwIfNotFound)); }