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

41 lines
1.1 KiB
C#

using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.Iris.Markup;
using System;
using System.Linq.Expressions;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
namespace Microsoft.Iris.DecompXml.Mock;
internal class IrisConstantExpression : IrisExpression, IReturnValueProvider
{
public IrisConstantExpression(object value, TypeSchema typeSchema)
{
Value = value;
TypeSchema = typeSchema;
}
public sealed override ExpressionType NodeType => ExpressionType.Constant;
public object Value { get; }
public TypeSchema TypeSchema { get; }
public TypeSchema ReturnType => TypeSchema;
public override ExpressionSyntax ToSyntax(DecompileContext context)
{
return Value switch
{
Enum enumValue => MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
IdentifierName(context.GetQualifiedName(TypeSchema).ToString()),
IdentifierName(Value.ToString())
),
_ => ToSyntax(Value, context)
};
}
}