obfuz/Editor/Emit/ConstValue.cs

28 lines
971 B
C#
Raw Normal View History

using System;
using UnityEngine.Assertions;
namespace Obfuz.Emit
2025-04-20 15:20:13 +08:00
{
public struct ConstValue
{
public readonly DataNodeType type;
public readonly object value;
2025-04-21 08:58:25 +08:00
2025-04-20 15:20:13 +08:00
public ConstValue(DataNodeType type, object value)
{
switch (type)
{
case DataNodeType.Int32: Assert.IsTrue(value is int); break;
case DataNodeType.Int64: Assert.IsTrue(value is long); break;
case DataNodeType.Float32: Assert.IsTrue(value is float); break;
case DataNodeType.Float64: Assert.IsTrue(value is double); break;
case DataNodeType.String: Assert.IsTrue(value is string); break;
case DataNodeType.Bytes: Assert.IsTrue(value is byte[]); break;
default: throw new NotSupportedException($"Unsupported type {type} for ConstValue");
}
2025-04-20 15:20:13 +08:00
this.type = type;
this.value = value;
}
}
}