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

35 lines
902 B
C#

using Microsoft.Iris.Markup;
using System.Linq.Expressions;
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 string Decompile(Decompiler decompiler)
{
if (TypeSchema.IsEnum)
return $"{decompiler.GetQualifiedName(TypeSchema)}.{Value}";
return Value switch
{
string str => str,
IStringEncodable strEnc => strEnc.EncodeString(),
_ => Value?.ToString() ?? "null",
};
}
}