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
+15 -1
View File
@@ -1,8 +1,22 @@
using System.Linq.Expressions;
using Microsoft.Iris.Asm;
using System;
using System.Linq.Expressions;
namespace Microsoft.Iris.DecompXml.Mock;
internal class IrisExpression : Expression
{
public virtual string Decompile(Decompiler decompiler) => ToString();
public static Expression ToExpression(object p)
{
return p switch
{
null => Constant(null),
Expression expr => expr,
Disassembler.RawConstantInfo constantInfo => new IrisConstantExpression(constantInfo.Value, constantInfo.Type),
_ => throw new NotImplementedException()
};
}
}
+38
View File
@@ -0,0 +1,38 @@
using Microsoft.Iris.Asm;
using Microsoft.Iris.Markup;
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Linq;
namespace Microsoft.Iris.DecompXml.Mock;
internal record IrisObject(object Object, TypeSchema Type)
{
public static IrisObject Create(object objIn, TypeSchema type, Decompiler decompiler)
{
object obj = objIn;
if (objIn is IrisObject irisObj)
{
return irisObj.Type is null
? (irisObj with { Type = type })
: irisObj;
}
if (objIn is Disassembler.RawConstantInfo constantInfo)
{
obj = constantInfo.Value;
type ??= constantInfo.Type;
}
if (objIn is IReturnValueProvider hasReturnValue)
{
type ??= hasReturnValue.ReturnType;
}
type ??= Disassembler.GuessTypeSchema(obj.GetType(), decompiler._loadResult);
return new(obj, type);
}
}