From 1400da1b8780a3402a33b7fa123ceba035a32a41 Mon Sep 17 00:00:00 2001 From: "Alecio Furanze (Ale)" Date: Wed, 11 Dec 2024 13:29:07 +0200 Subject: [PATCH] =?UTF-8?q?remove=20project=20build=20warning=20=E2=9A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/src/primitive/partials/PrimitiveGet.cs | 16 +++++++-------- test/primitive/Primitive.Array.cs | 2 ++ test/primitive/Primitive.Class.cs | 24 +++++++++++++--------- test/primitive/Primitive.Struct.cs | 5 ++++- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/src/primitive/partials/PrimitiveGet.cs b/src/src/primitive/partials/PrimitiveGet.cs index 52a5499..59dd54d 100644 --- a/src/src/primitive/partials/PrimitiveGet.cs +++ b/src/src/primitive/partials/PrimitiveGet.cs @@ -3,8 +3,8 @@ using System.Collections.Generic; using System.Data; using System.IO; +using System.Linq; using System.Numerics; -using System.Reflection; using System.Text; namespace Byter @@ -374,7 +374,7 @@ public object Class(Type type) return instance; } - catch (Exception e) + catch { return SetError(); } @@ -391,7 +391,7 @@ public T Class() if (!IsValidObject()) return default; // empty or null data var instance = (T)Activator.CreateInstance(typeof(T)); - + var props = typeof(T).GetProperties(); if (props.Length <= 0) return default; @@ -434,7 +434,7 @@ public object Struct(Type type) if (!IsValidPrefix(Prefix.Struct)) throw new InvalidDataException(); if (!IsValidObject()) return default; // empty or null data - + var instance = Activator.CreateInstance(type); var props = type.GetProperties(); @@ -506,8 +506,6 @@ public object Struct(Type type) public object Array(Type type) { - const List listName = null; - if (type == null) return null; if (!type.IsArray) return null; Type childrenType = type.GetElementType(); @@ -519,8 +517,8 @@ public object Array(Type type) var list = Activator.CreateInstance(listType); - var addMethod = list.GetType().GetMethod(nameof(listName.Add)); - var toArrayMethod = list.GetType().GetMethod(nameof(listName.ToArray)); + var addMethod = list.GetType().GetMethod(nameof(IList.Add)); + var toArrayMethod = list.GetType().GetMethod(nameof(Enumerable.ToArray)); if (addMethod == null) throw new NullReferenceException(nameof(addMethod)); if (toArrayMethod == null) throw new NullReferenceException(nameof(toArrayMethod)); @@ -542,7 +540,7 @@ public object Array(Type type) return toArrayMethod.Invoke(list, null); } - catch (Exception e) + catch { return SetError(); } diff --git a/test/primitive/Primitive.Array.cs b/test/primitive/Primitive.Array.cs index 82f505b..a70bc54 100644 --- a/test/primitive/Primitive.Array.cs +++ b/test/primitive/Primitive.Array.cs @@ -143,6 +143,7 @@ private void _Array3() Assert.True(primitive.IsValid); } + [Serializable] private class Array3Info { public int Number { get; set; } @@ -152,6 +153,7 @@ private class Array3Info public string[]? Array { get; set; } public Sub? SubClass { get; set; } + [Serializable] public class Sub { public string? String { get; set; } diff --git a/test/primitive/Primitive.Class.cs b/test/primitive/Primitive.Class.cs index 9e7ca93..2205508 100644 --- a/test/primitive/Primitive.Class.cs +++ b/test/primitive/Primitive.Class.cs @@ -106,23 +106,26 @@ public void _Class() Assert.True(primitive.IsValid); } + [Serializable] private class MyComplexClass { public int Number { get; set; } - public string String { get; set; } + public string String { get; set; } = null!; public bool Bool { get; set; } - public byte[] ByteArray { get; set; } - public List StringList { get; set; } - public List SubClassList { get; set; } - public List SubStructList { get; set; } + public byte[] ByteArray { get; set; } = null!; + public List StringList { get; set; } = null!; + public List SubClassList { get; set; } = null!; + public List SubStructList { get; set; } = null!; - public string[] StringArray { get; set; } - public MySubClass[] SubClassArray { get; set; } - public MySubStruct[] SubStructArray { get; set; } + public string[] StringArray { get; set; } = null!; + public MySubClass[] SubClassArray { get; set; } = null!; + public MySubStruct[] SubStructArray { get; set; } = null!; - public MySubClass SubClass { get; set; } + public MySubClass SubClass { get; set; } = null!; public MySubStruct SubStruct { get; set; } + + [Serializable] public struct MySubStruct { public long Number { get; set; } @@ -138,10 +141,11 @@ public static MySubStruct Random() } } + [Serializable] public class MySubClass { public long Number { get; set; } - public string String { get; set; } + public string String { get; set; } = null!; public static MySubClass Random() { diff --git a/test/primitive/Primitive.Struct.cs b/test/primitive/Primitive.Struct.cs index ca9cc74..a4ab611 100644 --- a/test/primitive/Primitive.Struct.cs +++ b/test/primitive/Primitive.Struct.cs @@ -108,6 +108,7 @@ public void _Struct() Assert.True(primitive.IsValid); } + [Serializable] private struct MyComplexStruct { public int Number { get; set; } @@ -125,6 +126,7 @@ private struct MyComplexStruct public MySubClass SubClass { get; set; } public MySubStruct SubStruct { get; set; } + [Serializable] public struct MySubStruct { public long Number { get; set; } @@ -140,10 +142,11 @@ public static MySubStruct Random() } } + [Serializable] public class MySubClass { public long Number { get; set; } - public string String { get; set; } + public string String { get; set; } = null!; public static MySubClass Random() {