Files
6098/Cowain.Bake.Common/Models/VarValue.cs

103 lines
2.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Cowain.Bake.Common.Models
{
[StructLayout(LayoutKind.Explicit, Size = 4)]
public class VarValue
{
// Fields
[FieldOffset(0)]
public bool Boolean;
[FieldOffset(0)]
public byte Byte;
[FieldOffset(0)]
public short Int16;
[FieldOffset(0)]
public ushort UInt16;
[FieldOffset(0)]
public int Int32;
[FieldOffset(0)]
public uint UInt32;
[FieldOffset(0)]
public float Single;
public string GetValue(string tp)
{
if (string.IsNullOrEmpty(tp))
{
return "";
}
else if (tp == "BOOL")
{
return this.Boolean == true ? "TRUE" : "FALSE";
}
else
{
return this.Int32.ToString();
}
}
public override bool Equals(object obj)
{
if (obj == null)
return false;
Type type = obj.GetType();
if (type == typeof(VarValue))
return this.Int32 == ((VarValue)obj).Int32;
else
{
if (type == typeof(int))
return this.Int32 == (int)obj;
if (type == typeof(uint))
return this.UInt32 == (uint)obj;
if (type == typeof(short))
return this.Int16 == (short)obj;
if (type == typeof(ushort))
return this.UInt16 == (ushort)obj;
if (type == typeof(byte))
return this.Byte == (byte)obj;
if (type == typeof(bool))
return this.Boolean == (bool)obj;
if (type == typeof(float))
return this.Single == (float)obj;
if (type == typeof(string))
return this.ToString() == obj.ToString();
else
return false;
}
}
public override int GetHashCode()
{
return Int32.GetHashCode();
}
public static bool Equals(VarValue a, VarValue b)
{
if (a == null || b == null)
{
return false;
}
if (a.Int32 != b.Int32)
{
return false;
}
else
return false;
}
public override string ToString()
{
return this.Int32.ToString();
}
}
}