コード例 #1
0
    public override async Task Load(XElement node, bool requireName = true)
    {
        await base.Load(node, requireName);

        if (!HasRange)
        {
            return;
        }

        float minFloat, maxFloat;

        if (string.IsNullOrWhiteSpace(Min) && string.IsNullOrWhiteSpace(Max))
        {
            throw new ArgumentException($"Value was not convertable to range: {Min}-{Max}");
        }

        if (string.IsNullOrWhiteSpace(Min))
        {
            minFloat = float.MinValue;
            Min      = "float.MinValue";
        }
        else if (!float.TryParse(Min, out minFloat))
        {
            throw new ArgumentException($"Value was not convertable to float: {Min}");
        }

        if (string.IsNullOrWhiteSpace(Max))
        {
            maxFloat = float.MaxValue;
            Max      = "float.MaxValue";
        }
        else if (!float.TryParse(Max, out maxFloat))
        {
            throw new ArgumentException($"Value was not convertable to float: {Max}");
        }

        if (minFloat > maxFloat)
        {
            throw new ArgumentException($"Min {minFloat} was greater than max {maxFloat}");
        }

        if (!minFloat.Equals(float.MinValue) &&
            !Min.EndsWith("f"))
        {
            Min += "f";
        }

        if (!maxFloat.Equals(float.MaxValue) &&
            !Max.EndsWith("f"))
        {
            Max += "f";
        }
    }
コード例 #2
0
    public override async Task Load(XElement node, bool requireName = true)
    {
        await base.Load(node, requireName);

        if (!HasRange)
        {
            return;
        }

        double min, max;

        if (string.IsNullOrWhiteSpace(Min) && string.IsNullOrWhiteSpace(Max))
        {
            throw new ArgumentException($"Value was not convertable to range: {Min}-{Max}");
        }

        if (string.IsNullOrWhiteSpace(Min))
        {
            min = double.MinValue;
            Min = "double.MinValue";
        }
        else if (!double.TryParse(Min, out min))
        {
            throw new ArgumentException($"Value was not convertable to double: {Min}");
        }

        if (string.IsNullOrWhiteSpace(Max))
        {
            max = double.MaxValue;
            Max = "double.MaxValue";
        }
        else if (!double.TryParse(Max, out max))
        {
            throw new ArgumentException($"Value was not convertable to double: {Max}");
        }

        if (min > max)
        {
            throw new ArgumentException($"Min {min} was greater than max {max}");
        }

        if (!Min.EndsWith("d"))
        {
            Min += "d";
        }

        if (!Max.EndsWith("d"))
        {
            Max += "d";
        }
    }