File: Validators.cs

package info (click to toggle)
lsprotocol 2025.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,408 kB
  • sloc: python: 7,567; cs: 1,225; sh: 15; makefile: 4
file content (40 lines) | stat: -rw-r--r-- 997 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

using System;

public static class Validators
{
    public static bool HasType(Type[] types, Type type)
    {
        return types.Contains(type);
    }

    public static bool InIntegerRange(long value)
    {
        return value >= int.MinValue && value <= int.MaxValue;
    }

    public static bool InUIntegerRange(long value)
    {
        return value >= uint.MinValue && value <= uint.MaxValue;
    }

    public static long? validUInteger(long? value){
        if(value == null){
            return null;
        }

        if (Validators.InUIntegerRange((long)value))
        {
            return value;
        }
        throw new ArgumentOutOfRangeException("value", value, "Value is not in the range of LSP uinteger");
    }

    public static long validUInteger(long value){
        if (Validators.InUIntegerRange(value))
        {
            return value;
        }
        throw new ArgumentOutOfRangeException("value", value, "Value is not in the range of LSP uinteger");
    }
}