progress
This commit is contained in:
parent
16e76d6b31
commit
484dbfc9d9
529 changed files with 113694 additions and 0 deletions
130
AspClassic.Scripting/SymbolId.cs
Normal file
130
AspClassic.Scripting/SymbolId.cs
Normal file
|
@ -0,0 +1,130 @@
|
|||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Security.Permissions;
|
||||
using AspClassic.Scripting.Utils;
|
||||
|
||||
namespace AspClassic.Scripting;
|
||||
|
||||
[Serializable]
|
||||
public struct SymbolId : ISerializable, IComparable, IComparable<SymbolId>, IEquatable<SymbolId>
|
||||
{
|
||||
public const int EmptyId = 0;
|
||||
|
||||
public const int InvalidId = -1;
|
||||
|
||||
private readonly int _id;
|
||||
|
||||
public static readonly SymbolId Empty = new SymbolId(0);
|
||||
|
||||
public static readonly SymbolId[] EmptySymbols = new SymbolId[0];
|
||||
|
||||
public static readonly SymbolId Invalid = new SymbolId(-1);
|
||||
|
||||
public int Id => _id;
|
||||
|
||||
public SymbolId CaseInsensitiveIdentifier => new SymbolId(_id & 0xFFFFFF);
|
||||
|
||||
public int CaseInsensitiveId => _id & 0xFFFFFF;
|
||||
|
||||
public bool IsCaseInsensitive => (_id & -16777216) == 0;
|
||||
|
||||
public bool IsEmpty => _id == 0;
|
||||
|
||||
public bool IsInvalid => _id == -1;
|
||||
|
||||
public SymbolId(int value)
|
||||
{
|
||||
_id = value;
|
||||
}
|
||||
|
||||
public SymbolId(SymbolId value)
|
||||
{
|
||||
_id = value._id;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is SymbolId))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return Equals((SymbolId)obj);
|
||||
}
|
||||
|
||||
public bool Equals(SymbolId other)
|
||||
{
|
||||
if (_id == other._id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (IsCaseInsensitive || other.IsCaseInsensitive)
|
||||
{
|
||||
return (_id & 0xFFFFFF) == (other._id & 0xFFFFFF);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return _id & 0xFFFFFF;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return SymbolTable.IdToString(this);
|
||||
}
|
||||
|
||||
public static explicit operator SymbolId(string s)
|
||||
{
|
||||
return SymbolTable.StringToId(s);
|
||||
}
|
||||
|
||||
public static bool operator ==(SymbolId a, SymbolId b)
|
||||
{
|
||||
return a.Equals(b);
|
||||
}
|
||||
|
||||
public static bool operator !=(SymbolId a, SymbolId b)
|
||||
{
|
||||
return !a.Equals(b);
|
||||
}
|
||||
|
||||
public static bool operator <(SymbolId a, SymbolId b)
|
||||
{
|
||||
return a.CompareTo(b) < 0;
|
||||
}
|
||||
|
||||
public static bool operator >(SymbolId a, SymbolId b)
|
||||
{
|
||||
return a.CompareTo(b) > 0;
|
||||
}
|
||||
|
||||
public int CompareTo(object obj)
|
||||
{
|
||||
if (!(obj is SymbolId))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return CompareTo((SymbolId)obj);
|
||||
}
|
||||
|
||||
public int CompareTo(SymbolId other)
|
||||
{
|
||||
string text = SymbolTable.IdToString(this);
|
||||
string strB = SymbolTable.IdToString(other);
|
||||
return text.CompareTo(strB);
|
||||
}
|
||||
|
||||
private SymbolId(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
ContractUtils.RequiresNotNull(info, "info");
|
||||
_id = SymbolTable.StringToId(info.GetString("symbolName"))._id;
|
||||
}
|
||||
|
||||
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
|
||||
public void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
ContractUtils.RequiresNotNull(info, "info");
|
||||
info.AddValue("symbolName", SymbolTable.IdToString(this));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue