diff --git a/generator/plugins/dotnet/custom/OrTypeConverter.cs b/generator/plugins/dotnet/custom/OrTypeConverter.cs index f2aadbf..641c0d1 100644 --- a/generator/plugins/dotnet/custom/OrTypeConverter.cs +++ b/generator/plugins/dotnet/custom/OrTypeConverter.cs @@ -37,7 +37,7 @@ public class OrTypeConverter : JsonConverter> Type[] types = new Type[] { typeof(T), typeof(U) }; - if (reader.TokenType == JsonToken.Integer && (Validators.HasType(types, typeof(uint)) || Validators.HasType(types, typeof(int)))) + if (reader.TokenType == JsonToken.Integer && (Validators.HasType(types, typeof(long)) || Validators.HasType(types, typeof(int)))) { return ReadIntegerToken(reader, serializer, types); } @@ -61,15 +61,15 @@ public class OrTypeConverter : JsonConverter> private static OrType ReadIntegerToken(JsonReader reader, JsonSerializer serializer, Type[] types) { long integer = serializer.Deserialize(reader); - if (Validators.InUIntegerRange(integer) && Validators.HasType(types, typeof(uint))) + if (Validators.InUIntegerRange(integer) && Validators.HasType(types, typeof(long))) { - if (typeof(T) == typeof(uint)) + if (typeof(T) == typeof(long)) { - return new OrType((T)(object)(uint)integer); + return new OrType((T)(object)(long)integer); } - if (typeof(U) == typeof(uint)) + if (typeof(U) == typeof(long)) { - return new OrType((U)(object)(uint)integer); + return new OrType((U)(object)(long)integer); } } if (Validators.InIntegerRange(integer) && Validators.HasType(types, typeof(int))) @@ -83,7 +83,7 @@ private static OrType ReadIntegerToken(JsonReader reader, JsonSerializer s return new OrType((U)(object)(int)integer); } } - throw new ArgumentOutOfRangeException($"Integer out-of-range of LSP Signed Integer[{int.MinValue}:{int.MaxValue}] and out-of-range of LSP Unsigned Integer [{uint.MinValue}:{uint.MaxValue}] => {integer}"); + throw new ArgumentOutOfRangeException($"Integer out-of-range of LSP Signed Integer[{int.MinValue}:{int.MaxValue}] and out-of-range of LSP Unsigned Integer [{long.MinValue}:{long.MaxValue}] => {integer}"); } private static OrType ReadFloatToken(JsonReader reader, JsonSerializer serializer, Type[] types) @@ -136,9 +136,9 @@ private static OrType ReadObjectToken(JToken token, JsonSerializer seriali try { object? value = null; - if (token.Type == JTokenType.Array && type == typeof((uint, uint))) + if (token.Type == JTokenType.Array && type == typeof((long, long))) { - uint[]? o = token.ToObject(serializer); + long[]? o = token.ToObject(serializer); if (o != null) { value = (o[0], o[1]); @@ -179,10 +179,10 @@ public override void WriteJson(JsonWriter writer, OrType? value, JsonSeria { writer.WriteNull(); } - else if (value?.Value?.GetType() == typeof((uint, uint))) + else if (value?.Value?.GetType() == typeof((long, long))) { - ValueTuple o = (ValueTuple)(value.Value); - serializer.Serialize(writer, new uint[] { o.Item1, o.Item2 }); + ValueTuple o = (ValueTuple)(value.Value); + serializer.Serialize(writer, new long[] { o.Item1, o.Item2 }); } else { @@ -204,7 +204,7 @@ public class OrTypeConverter : JsonConverter> Type[] types = new Type[] { typeof(T), typeof(U), typeof(V) }; - if (reader.TokenType == JsonToken.Integer && (Validators.HasType(types, typeof(uint)) || Validators.HasType(types, typeof(int)))) + if (reader.TokenType == JsonToken.Integer && (Validators.HasType(types, typeof(long)) || Validators.HasType(types, typeof(int)))) { return ReadIntegerToken(reader, serializer, types); } @@ -228,19 +228,19 @@ public class OrTypeConverter : JsonConverter> private static OrType ReadIntegerToken(JsonReader reader, JsonSerializer serializer, Type[] types) { long integer = serializer.Deserialize(reader); - if (Validators.InUIntegerRange(integer) && Validators.HasType(types, typeof(uint))) + if (Validators.InUIntegerRange(integer) && Validators.HasType(types, typeof(long))) { - if (typeof(T) == typeof(uint)) + if (typeof(T) == typeof(long)) { - return new OrType((T)(object)(uint)integer); + return new OrType((T)(object)(long)integer); } - if (typeof(U) == typeof(uint)) + if (typeof(U) == typeof(long)) { - return new OrType((U)(object)(uint)integer); + return new OrType((U)(object)(long)integer); } - if (typeof(V) == typeof(uint)) + if (typeof(V) == typeof(long)) { - return new OrType((V)(object)(uint)integer); + return new OrType((V)(object)(long)integer); } } if (Validators.InIntegerRange(integer) && Validators.HasType(types, typeof(int))) @@ -258,7 +258,7 @@ private static OrType ReadIntegerToken(JsonReader reader, JsonSerialize return new OrType((V)(object)(int)integer); } } - throw new ArgumentOutOfRangeException($"Integer out-of-range of LSP Signed Integer[{int.MinValue}:{int.MaxValue}] and out-of-range of LSP Unsigned Integer [{uint.MinValue}:{uint.MaxValue}] => {integer}"); + throw new ArgumentOutOfRangeException($"Integer out-of-range of LSP Signed Integer[{int.MinValue}:{int.MaxValue}] and out-of-range of LSP Unsigned Integer [{long.MinValue}:{long.MaxValue}] => {integer}"); } private static OrType ReadFloatToken(JsonReader reader, JsonSerializer serializer, Type[] types) @@ -323,9 +323,9 @@ private static OrType ReadObjectToken(JToken token, JsonSerializer seri try { object? value = null; - if (token.Type == JTokenType.Array && type == typeof((uint, uint))) + if (token.Type == JTokenType.Array && type == typeof((long, long))) { - uint[]? o = token.ToObject(serializer); + long[]? o = token.ToObject(serializer); if (o != null) { value = (o[0], o[1]); @@ -368,10 +368,10 @@ public override void WriteJson(JsonWriter writer, OrType? value, JsonSe { writer.WriteNull(); } - else if (value?.Value?.GetType() == typeof((uint, uint))) + else if (value?.Value?.GetType() == typeof((long, long))) { - ValueTuple o = (ValueTuple)(value.Value); - serializer.Serialize(writer, new uint[] { o.Item1, o.Item2 }); + ValueTuple o = (ValueTuple)(value.Value); + serializer.Serialize(writer, new long[] { o.Item1, o.Item2 }); } else { @@ -393,7 +393,7 @@ public class OrTypeConverter : JsonConverter> Type[] types = new Type[] { typeof(T), typeof(U), typeof(V), typeof(W) }; - if (reader.TokenType == JsonToken.Integer && (Validators.HasType(types, typeof(uint)) || Validators.HasType(types, typeof(int)))) + if (reader.TokenType == JsonToken.Integer && (Validators.HasType(types, typeof(long)) || Validators.HasType(types, typeof(int)))) { return ReadIntegerToken(reader, serializer, types); } @@ -417,23 +417,23 @@ public class OrTypeConverter : JsonConverter> private static OrType ReadIntegerToken(JsonReader reader, JsonSerializer serializer, Type[] types) { long integer = serializer.Deserialize(reader); - if (Validators.InUIntegerRange(integer) && Validators.HasType(types, typeof(uint))) + if (Validators.InUIntegerRange(integer) && Validators.HasType(types, typeof(long))) { - if (typeof(T) == typeof(uint)) + if (typeof(T) == typeof(long)) { - return new OrType((T)(object)(uint)integer); + return new OrType((T)(object)(long)integer); } - if (typeof(U) == typeof(uint)) + if (typeof(U) == typeof(long)) { - return new OrType((U)(object)(uint)integer); + return new OrType((U)(object)(long)integer); } - if (typeof(V) == typeof(uint)) + if (typeof(V) == typeof(long)) { - return new OrType((V)(object)(uint)integer); + return new OrType((V)(object)(long)integer); } - if (typeof(W) == typeof(uint)) + if (typeof(W) == typeof(long)) { - return new OrType((W)(object)(uint)integer); + return new OrType((W)(object)(long)integer); } } if (Validators.InIntegerRange(integer) && Validators.HasType(types, typeof(int))) @@ -455,7 +455,7 @@ private static OrType ReadIntegerToken(JsonReader reader, JsonSerial return new OrType((W)(object)(int)integer); } } - throw new ArgumentOutOfRangeException($"Integer out-of-range of LSP Signed Integer[{int.MinValue}:{int.MaxValue}] and out-of-range of LSP Unsigned Integer [{uint.MinValue}:{uint.MaxValue}] => {integer}"); + throw new ArgumentOutOfRangeException($"Integer out-of-range of LSP Signed Integer[{int.MinValue}:{int.MaxValue}] and out-of-range of LSP Unsigned Integer [{long.MinValue}:{long.MaxValue}] => {integer}"); } private static OrType ReadFloatToken(JsonReader reader, JsonSerializer serializer, Type[] types) @@ -532,9 +532,9 @@ private static OrType ReadObjectToken(JToken token, JsonSerializer s try { object? value = null; - if (token.Type == JTokenType.Array && type == typeof((uint, uint))) + if (token.Type == JTokenType.Array && type == typeof((long, long))) { - uint[]? o = token.ToObject(serializer); + long[]? o = token.ToObject(serializer); if (o != null) { value = (o[0], o[1]); @@ -582,10 +582,10 @@ public override void WriteJson(JsonWriter writer, OrType? value, Jso { writer.WriteNull(); } - else if (value?.Value?.GetType() == typeof((uint, uint))) + else if (value?.Value?.GetType() == typeof((long, long))) { - ValueTuple o = (ValueTuple)(value.Value); - serializer.Serialize(writer, new uint[] { o.Item1, o.Item2 }); + ValueTuple o = (ValueTuple)(value.Value); + serializer.Serialize(writer, new long[] { o.Item1, o.Item2 }); } else { diff --git a/generator/plugins/dotnet/custom/Validators.cs b/generator/plugins/dotnet/custom/Validators.cs index 9edc18f..680c81a 100644 --- a/generator/plugins/dotnet/custom/Validators.cs +++ b/generator/plugins/dotnet/custom/Validators.cs @@ -17,4 +17,24 @@ 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"); + } } \ No newline at end of file diff --git a/generator/plugins/dotnet/dotnet_classes.py b/generator/plugins/dotnet/dotnet_classes.py index 7a2abac..f1794f3 100644 --- a/generator/plugins/dotnet/dotnet_classes.py +++ b/generator/plugins/dotnet/dotnet_classes.py @@ -60,7 +60,7 @@ def lsp_to_base_types(lsp_type: model.BaseType): elif lsp_type.name in ["integer"]: return "int" elif lsp_type.name in ["uinteger"]: - return "uint" + return "long" elif lsp_type.name in ["boolean"]: return "bool" elif lsp_type.name in ["null"]: @@ -250,6 +250,12 @@ def generate_property( lines.append( f'public {type_name}{optional} {name} {{ get; init; }} = "{prop_def.type.value}";' ) + elif prop_def.type.kind == "base" and prop_def.type.name == "uinteger": + private_name = f"_{prop_def.name}" if prop_def.name == name else prop_def.name + lines.append( + f"public {type_name}{optional} {name} {{ get => {private_name}; set => {private_name} = Validators.validUInteger(value); }}" + ) + lines.append(f"private {type_name}{optional} {private_name};") else: lines.append(f"public {type_name}{optional} {name} {{ get; init; }}")