Genericize conversions from instance/expressions to XML

This commit is contained in:
Yoshi Askharoun
2025-07-17 14:07:44 -05:00
parent c4a8be37cb
commit 109c44e8eb
4 changed files with 159 additions and 88 deletions
+8 -3
View File
@@ -347,15 +347,20 @@ public class Disassembler
}
var runtimeType = constantValue.GetType();
var typeSchema = loadResult.ImportTables.TypeImports.FirstOrDefault(t => t.RuntimeType == runtimeType)
?? loadResult.ImportTables.TypeImports.FirstOrDefault(t => t.RuntimeType == runtimeType.BaseType)
?? throw new Exception($"Failed to find type schema for '{runtimeType.Name}' in {loadResult.Uri}");
var typeSchema = GuessTypeSchema(runtimeType, loadResult);
yield return new(c, typeSchema, constantValue);
}
}
}
public static TypeSchema GuessTypeSchema(Type runtimeType, MarkupLoadResult loadResult)
{
return loadResult.ImportTables.TypeImports.FirstOrDefault(t => t.RuntimeType == runtimeType)
?? loadResult.ImportTables.TypeImports.FirstOrDefault(t => t.RuntimeType == runtimeType.BaseType)
?? throw new Exception($"Failed to find type schema for '{runtimeType.Name}' in {loadResult.Uri}");
}
private ConstantDirective EncodeConstant(object constantValue, string constantName, TypeSchema typeSchema)
{
var qualifiedTypeName = GetQualifiedName(typeSchema);