private static string CreateReproArgumentString(MethodDesc method) { StringBuilder sb = new StringBuilder(); var formatter = new CustomAttributeTypeNameFormatter((IAssemblyDesc)method.Context.SystemModule); sb.Append($"--singlemethodtypename \"{formatter.FormatName(method.OwningType, true)}\""); sb.Append($" --singlemethodname \"{method.Name}\""); { int curIndex = 0; foreach (var searchMethod in method.OwningType.GetMethods()) { if (searchMethod.Name != method.Name) { continue; } curIndex++; if (searchMethod == method.GetMethodDefinition()) { sb.Append($" --singlemethodindex {curIndex}"); } } } for (int i = 0; i < method.Instantiation.Length; i++) { sb.Append($" --singlemethodgenericarg \"{formatter.FormatName(method.Instantiation[i], true)}\""); } return(sb.ToString()); }
private static bool DumpReproArguments(CodeGenerationFailedException ex) { Console.WriteLine(SR.DumpReproInstructions); MethodDesc failingMethod = ex.Method; var formatter = new CustomAttributeTypeNameFormatter((IAssemblyDesc)failingMethod.Context.SystemModule); Console.Write($"--singlemethodtypename \"{formatter.FormatName(failingMethod.OwningType, true)}\""); Console.Write($" --singlemethodname {failingMethod.Name}"); { int curIndex = 0; foreach (var searchMethod in failingMethod.OwningType.GetMethods()) { if (searchMethod.Name != failingMethod.Name) { continue; } curIndex++; if (searchMethod == failingMethod.GetMethodDefinition()) { Console.Write($" --singlemethodindex {curIndex}"); } } } for (int i = 0; i < failingMethod.Instantiation.Length; i++) { Console.Write($" --singlemethodgenericarg \"{formatter.FormatName(failingMethod.Instantiation[i], true)}\""); } Console.WriteLine(); return(false); }
static string GetStringForType(TypeDesc type, Dictionary <TypeDesc, string> typeStringCache) { string str; if (typeStringCache.TryGetValue(type, out str)) { return(str); } CustomAttributeTypeNameFormatter caFormat = new CustomAttributeTypeNameFormatter(); str = caFormat.FormatName(type, true); typeStringCache.Add(type, str); return(str); }
private static bool DumpReproArguments(CodeGenerationFailedException ex) { Console.WriteLine("To repro, add following arguments to the command line:"); MethodDesc failingMethod = ex.Method; var formatter = new CustomAttributeTypeNameFormatter((IAssemblyDesc)failingMethod.Context.SystemModule); Console.Write($"--singlemethodtypename \"{formatter.FormatName(failingMethod.OwningType, true)}\""); Console.Write($" --singlemethodname {failingMethod.Name}"); for (int i = 0; i < failingMethod.Instantiation.Length; i++) Console.Write($" --singlemethodgenericarg \"{formatter.FormatName(failingMethod.Instantiation[i], true)}\""); return false; }
public void TestRoundtripping() { foreach (TypeDesc type in GetTypesForRoundtripTest()) { { var fmt = new CustomAttributeTypeNameFormatter((IAssemblyDesc)_testModule); string formatted = fmt.FormatName(type, true); TypeDesc roundTripped = _testModule.GetTypeByCustomAttributeTypeName(formatted); Assert.Equal(type, roundTripped); } { var fmt = new CustomAttributeTypeNameFormatter(); string formatted = fmt.FormatName(type, true); TypeDesc roundTripped = _testModule.GetTypeByCustomAttributeTypeName(formatted); Assert.Equal(type, roundTripped); } } }