tlang-runtime-compiler/TLang.Common/TLangVersion.cs

54 lines
1.7 KiB
C#
Raw Normal View History

2023-07-29 00:11:09 +00:00
using System;
namespace TLang.Common
{
public class TLangVersion
{
public static TLangVersion Version => new TLangVersion(1,0,0,0);
public int IntegerVersion => Major << 24 | Minor << 16 | Patch << 8 | Build;
public static TLangVersion FromBytes(byte[] data,int offset=0)
{
TLangVersion version=new TLangVersion();
if(offset < data.Length) version.Major = data[offset];
if(offset + 1 < data.Length) version.Minor = data[offset + 1];
if(offset + 2 < data.Length) version.Minor = data[offset + 2];
if(offset + 3 < data.Length) version.Minor = data[offset + 3];
return version;
}
public TLangVersion() : this(1,0,0,0)
{
}
public TLangVersion(byte major,byte minor,byte patch,byte build)
{
Major =major;
Minor = minor;
Patch = patch;
Build = build;
}
public TLangVersion(byte major,byte minor) : this(major,minor,0,0)
{
}
public static explicit operator Version(TLangVersion version)
{
return new Version(version.Major,version.Minor,version.Patch,version.Build);
}
public static explicit operator TLangVersion(Version version)
{
return new TLangVersion((byte)version.Major,(byte)version.Minor,(byte)version.Build,(byte)version.Revision);
}
public byte Major {get;set;}
public byte Minor {get;set;}
public byte Patch {get;set;}
public byte Build {get;set;}
public override string ToString()
{
return $"{Major}.{Minor}.{Patch}.{Build}";
}
}
}