Skip to content

Commit

Permalink
remove project build warning ⚠
Browse files Browse the repository at this point in the history
  • Loading branch information
alec1o committed Dec 11, 2024
1 parent 6d23a32 commit 1400da1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
16 changes: 7 additions & 9 deletions src/src/primitive/partials/PrimitiveGet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -374,7 +374,7 @@ public object Class(Type type)

return instance;
}
catch (Exception e)
catch
{
return SetError<object>();
}
Expand All @@ -391,7 +391,7 @@ public T Class<T>()
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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -506,8 +506,6 @@ public object Struct(Type type)

public object Array(Type type)
{
const List<byte> listName = null;

if (type == null) return null;
if (!type.IsArray) return null;
Type childrenType = type.GetElementType();
Expand All @@ -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));
Expand All @@ -542,7 +540,7 @@ public object Array(Type type)

return toArrayMethod.Invoke(list, null);
}
catch (Exception e)
catch
{
return SetError<object>();
}
Expand Down
2 changes: 2 additions & 0 deletions test/primitive/Primitive.Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ private void _Array3()
Assert.True(primitive.IsValid);
}

[Serializable]
private class Array3Info
{
public int Number { get; set; }
Expand All @@ -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; }
Expand Down
24 changes: 14 additions & 10 deletions test/primitive/Primitive.Class.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> StringList { get; set; }
public List<MySubClass> SubClassList { get; set; }
public List<MySubStruct> SubStructList { get; set; }
public byte[] ByteArray { get; set; } = null!;
public List<string> StringList { get; set; } = null!;
public List<MySubClass> SubClassList { get; set; } = null!;
public List<MySubStruct> 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; }
Expand All @@ -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()
{
Expand Down
5 changes: 4 additions & 1 deletion test/primitive/Primitive.Struct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public void _Struct()
Assert.True(primitive.IsValid);
}

[Serializable]
private struct MyComplexStruct
{
public int Number { get; set; }
Expand All @@ -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; }
Expand All @@ -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()
{
Expand Down

0 comments on commit 1400da1

Please sign in to comment.