Example #1
0
        private void WriteVariable(Variable value, BinaryWriter writer)
        {
            writer.Write((int)value.Type);
            switch (value.Type)
            {
            case VarType.String:
                writer.Write(value.ToString());
                break;

            case VarType.Integer:
                writer.Write(value.ToInteger());
                break;

            case VarType.Float:
                writer.Write(value.ToFloat());
                break;

            case VarType.List:
                writer.Write(value.ListCount);
                foreach (var item in value.GetList())
                {
                    WriteVariable(item, writer);
                }
                break;

            default:
                throw new Exception("Unable to write unknown variable type.");
            }
        }
Example #2
0
 public int CompareTo(Variable value)
 {
     return(value.Type switch
     {
         VarType.String => CompareTo(value.ToString()),
         VarType.Integer => CompareTo(value.ToInteger()),
         VarType.Float => CompareTo(value.ToFloat()),
         VarType.List => CompareTo((ListValue)value.Value),
         _ => throw new InvalidOperationException(),
     });
Example #3
0
 public override Variable Add(Variable value) => value.IsFloat() ? new Variable(Value + value.ToFloat()) : new Variable(Value + value.ToInteger());
Example #4
0
 public override Variable Add(Variable value) => new Variable(Value + value.ToFloat());
Example #5
0
 public override Variable Modulus(Variable value) => new Variable(Value % value.ToFloat());
Example #6
0
 public override bool IsEqual(Variable value) => (Value == value.ToFloat());
Example #7
0
 public override Variable Divide(Variable value) => new Variable(Value / value.ToFloat());
Example #8
0
 public override Variable Power(Variable value) => new Variable(Math.Pow(Value, value.ToFloat()));
Example #9
0
 public override Variable Subtract(Variable value) => new Variable(Value - value.ToFloat());
Example #10
0
 public override Variable Multiply(Variable value) => new Variable(Value * value.ToFloat());
Example #11
0
 public override Variable Add(Variable value) => (IsFloat() || value.IsFloat()) ? new Variable(ToFloat() + value.ToFloat()) : new Variable(ToInteger() + value.ToInteger());
Example #12
0
 public override Variable Subtract(Variable value) => value.IsFloat() ? new Variable(Value - value.ToFloat()) : new Variable(Value - value.ToInteger());
Example #13
0
 public override Variable Modulus(Variable value) => (IsFloat() || value.IsFloat()) ? new Variable(ToFloat() % value.ToFloat()) : new Variable(ToInteger() % value.ToInteger());
Example #14
0
 public override Variable Multiply(Variable value) => (IsFloat() || value.IsFloat()) ? new Variable(ToFloat() * value.ToFloat()) : new Variable(ToInteger() * value.ToInteger());
Example #15
0
 public override Variable Subtract(Variable value) => (IsFloat() || value.IsFloat()) ? new Variable(ToFloat() - value.ToFloat()) : new Variable(ToInteger() - value.ToInteger());
Example #16
0
 public override Variable Modulus(Variable value) => value.IsFloat() ? new Variable(Value % value.ToFloat()) : new Variable(Value % value.ToInteger());
Example #17
0
 public override Variable Multiply(Variable value) => value.IsFloat() ? new Variable(Value * value.ToFloat()) : new Variable(Value * value.ToInteger());