Files
ZuneUIXTools/libs/UIX.DecompXml/Mock/IrisExpression.cs
T

54 lines
2.0 KiB
C#
Raw Normal View History

2025-07-18 00:23:23 -05:00
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.Iris.Asm;
using Microsoft.Iris.Markup;
using System;
2025-07-17 00:46:05 -05:00
2025-07-18 00:23:23 -05:00
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
2025-07-17 00:46:05 -05:00
namespace Microsoft.Iris.DecompXml.Mock;
2025-07-20 10:24:49 -05:00
internal static class IrisExpression
2025-07-17 00:46:05 -05:00
{
2025-07-18 00:23:23 -05:00
public static ExpressionSyntax ToSyntax(object obj, DecompileContext context)
{
return obj switch
{
null => LiteralExpression(SyntaxKind.NullLiteralExpression),
int intValue => LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(intValue)),
2025-07-20 10:24:35 -05:00
bool boolValue => LiteralExpression(boolValue ? SyntaxKind.TrueLiteralExpression : SyntaxKind.FalseLiteralExpression),
2025-07-18 00:23:23 -05:00
string strValue => LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(strValue)),
IStringEncodable strEnc => ParseExpression(strEnc.EncodeString()),
2025-07-20 10:24:49 -05:00
Disassembler.RawConstantInfo constantInfo => ToSyntax(constantInfo.Value, constantInfo.Type, context),
IrisObject irisObj => ToSyntax(irisObj.Object, irisObj.Type, context),
2025-07-18 00:43:22 -05:00
SymbolReference symbolRef => ToSyntax(symbolRef),
TypeSchema typeSchema => ToSyntax(typeSchema, context),
2025-07-18 00:23:23 -05:00
ExpressionSyntax exprSyn => exprSyn,
_ => IdentifierName(obj.ToString())
};
}
2025-07-18 00:43:22 -05:00
public static IdentifierNameSyntax ToSyntax(TypeSchema type, DecompileContext context) =>
IdentifierName(context.GetQualifiedName(type).ToString());
public static IdentifierNameSyntax ToSyntax(SymbolReference symbolRef) =>
IdentifierName(symbolRef.Symbol);
2025-07-20 10:24:49 -05:00
public static ExpressionSyntax ToSyntax(object obj, TypeSchema type, DecompileContext context)
{
return obj switch
{
Enum _ => MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
IdentifierName(context.GetQualifiedName(type).ToString()),
IdentifierName(obj.ToString())
),
_ => ToSyntax(obj, context),
};
}
2025-07-17 00:46:05 -05:00
}