public TypeNameConfig(int nestingLevel, TypeNameConfig[] genericParamsConfig, ArrayKind arrayKind, bool assemblyQualified) { this.nestingLevel = nestingLevel; this.genericParamsConfig = genericParamsConfig; this.arrayKind = arrayKind; this.assemblyQualified = assemblyQualified; }
public TypeNameConfig(int nestingLevel, TypeNameConfig[] genericParamsConfig, int pointerCount, ArrayKind arrayKind, bool assemblyQualified) { this.NestingLevel = nestingLevel; this.GenericParamsConfig = genericParamsConfig; this.PointerCount = pointerCount; this.ArrayKind = arrayKind; this.AssemblyQualified = assemblyQualified; }
private static string[] GenerateTypeNamesToDecode( TypeNameConfig[] typeNameConfigs, out MetadataHelpers.AssemblyQualifiedTypeName[] expectedDecodeNames ) { var pooledStrBuilder = PooledStringBuilder.GetInstance(); StringBuilder typeNameBuilder = pooledStrBuilder.Builder; var typeNamesToDecode = new string[typeNameConfigs.Length]; expectedDecodeNames = new MetadataHelpers.AssemblyQualifiedTypeName[ typeNameConfigs.Length ]; for (int index = 0; index < typeNameConfigs.Length; index++) { TypeNameConfig typeNameConfig = typeNameConfigs[index]; string expectedTopLevelTypeName = "X"; typeNameBuilder.Append("X"); string[] expectedNestedTypes = null; if (typeNameConfig.NestingLevel > 0) { expectedNestedTypes = new string[typeNameConfig.NestingLevel]; for (int i = 0; i < typeNameConfig.NestingLevel; i++) { expectedNestedTypes[i] = "Y" + i; typeNameBuilder.Append("+" + expectedNestedTypes[i]); } } MetadataHelpers.AssemblyQualifiedTypeName[] expectedTypeArguments; if (typeNameConfig.GenericParamsConfig == null) { expectedTypeArguments = null; } else { string[] genericParamsToDecode = GenerateTypeNamesToDecode( typeNameConfig.GenericParamsConfig, out expectedTypeArguments ); var genericArityStr = "`" + genericParamsToDecode.Length.ToString(); typeNameBuilder.Append(genericArityStr); if (typeNameConfig.NestingLevel == 0) { expectedTopLevelTypeName += genericArityStr; } else { expectedNestedTypes[typeNameConfig.NestingLevel - 1] += genericArityStr; } typeNameBuilder.Append("["); for (int i = 0; i < genericParamsToDecode.Length; i++) { if (i > 0) { typeNameBuilder.Append(", "); } if (typeNameConfig.GenericParamsConfig[i].AssemblyQualified) { typeNameBuilder.Append("["); typeNameBuilder.Append(genericParamsToDecode[i]); typeNameBuilder.Append("]"); } else { typeNameBuilder.Append(genericParamsToDecode[i]); } } typeNameBuilder.Append("]"); } int expectedPointerCount = typeNameConfig.PointerCount; typeNameBuilder.Append('*', expectedPointerCount); int[] expectedArrayRanks = null; switch (typeNameConfig.ArrayKind) { case ArrayKind.SzArray: typeNameBuilder.Append("[]"); expectedArrayRanks = new[] { 0 }; break; case ArrayKind.SingleDimensional: typeNameBuilder.Append("[*]"); expectedArrayRanks = new[] { 1 }; break; case ArrayKind.MultiDimensional: typeNameBuilder.Append("[,]"); expectedArrayRanks = new[] { 2 }; break; case ArrayKind.JaggedSzArray: typeNameBuilder.Append("[,][]"); expectedArrayRanks = new[] { 2, 0 }; break; case ArrayKind.Jagged: typeNameBuilder.Append("[,][*]"); expectedArrayRanks = new[] { 2, 1 }; break; } string expectedAssemblyName; if (typeNameConfig.AssemblyQualified) { expectedAssemblyName = "Assembly, Version=0.0.0.0, Culture=neutral, null"; typeNameBuilder.Append(", " + expectedAssemblyName); } else { expectedAssemblyName = null; } typeNamesToDecode[index] = typeNameBuilder.ToString(); expectedDecodeNames[index] = new MetadataHelpers.AssemblyQualifiedTypeName( expectedTopLevelTypeName, expectedNestedTypes, expectedTypeArguments, expectedPointerCount, expectedArrayRanks, expectedAssemblyName ); typeNameBuilder.Clear(); } pooledStrBuilder.Free(); return(typeNamesToDecode); }
private static string[] GenerateTypeNamesToDecode(TypeNameConfig[] typeNameConfigs, out MetadataHelpers.AssemblyQualifiedTypeName[] expectedDecodeNames) { var pooledStrBuilder = PooledStringBuilder.GetInstance(); StringBuilder typeNamebuilder = pooledStrBuilder.Builder; var typeNamesToDecode = new string[typeNameConfigs.Length]; expectedDecodeNames = new MetadataHelpers.AssemblyQualifiedTypeName[typeNameConfigs.Length]; for (int index = 0; index < typeNameConfigs.Length; index++) { TypeNameConfig typeNameConfig = typeNameConfigs[index]; string expectedTopLevelTypeName = "X"; typeNamebuilder.Append("X"); string[] expectedNestedTypes = null; if (typeNameConfig.nestingLevel > 0) { expectedNestedTypes = new string[typeNameConfig.nestingLevel]; for (int i = 0; i < typeNameConfig.nestingLevel; i++) { expectedNestedTypes[i] = "Y" + i; typeNamebuilder.Append("+" + expectedNestedTypes[i]); } } MetadataHelpers.AssemblyQualifiedTypeName[] expectedTypeArguments; if (typeNameConfig.genericParamsConfig == null) { expectedTypeArguments = null; } else { string[] genericParamsToDecode = GenerateTypeNamesToDecode(typeNameConfig.genericParamsConfig, out expectedTypeArguments); var genericArityStr = "`" + genericParamsToDecode.Length.ToString(); typeNamebuilder.Append(genericArityStr); if (typeNameConfig.nestingLevel == 0) { expectedTopLevelTypeName += genericArityStr; } else { expectedNestedTypes[typeNameConfig.nestingLevel - 1] += genericArityStr; } typeNamebuilder.Append("["); for (int i = 0; i < genericParamsToDecode.Length; i++) { if (i > 0) { typeNamebuilder.Append(", "); } if (typeNameConfig.genericParamsConfig[i].assemblyQualified) { typeNamebuilder.Append("["); typeNamebuilder.Append(genericParamsToDecode[i]); typeNamebuilder.Append("]"); } else { typeNamebuilder.Append(genericParamsToDecode[i]); } } typeNamebuilder.Append("]"); } int[] expectedArrayRanks = null; switch (typeNameConfig.arrayKind) { case ArrayKind.SingleDimensional: typeNamebuilder.Append("[]"); expectedArrayRanks = new [] { 1 }; break; case ArrayKind.MultiDimensional: typeNamebuilder.Append("[,]"); expectedArrayRanks = new[] { 2 }; break; case ArrayKind.Jagged: typeNamebuilder.Append("[,][]"); expectedArrayRanks = new[] { 1, 2 }; break; } string expectedAssemblyName; if (typeNameConfig.assemblyQualified) { expectedAssemblyName = "Assembly, Version=0.0.0.0, Culture=neutral, null"; typeNamebuilder.Append(", " + expectedAssemblyName); } else { expectedAssemblyName = null; } typeNamesToDecode[index] = typeNamebuilder.ToString(); expectedDecodeNames[index] = new MetadataHelpers.AssemblyQualifiedTypeName(expectedTopLevelTypeName, expectedNestedTypes, expectedTypeArguments, expectedArrayRanks, expectedAssemblyName); typeNamebuilder.Clear(); } pooledStrBuilder.Free(); return typeNamesToDecode; }