Skip to content

Commit

Permalink
fix. PrimitiveGet->Array(object)
Browse files Browse the repository at this point in the history
  • Loading branch information
alec1o committed May 31, 2024
1 parent c7e0d27 commit 0ce5808
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/src/primitive/partials/PrimitiveGet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Data;
using System.IO;
using System.Numerics;
using System.Reflection;
using System.Text;

namespace Byter
Expand Down Expand Up @@ -398,7 +399,7 @@ public object Class(Type type)

return instance;
}
catch
catch (Exception e)

Check warning on line 402 in src/src/primitive/partials/PrimitiveGet.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'e' is declared but never used
{
return SetError<object>();
}
Expand Down Expand Up @@ -584,6 +585,8 @@ 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 @@ -593,7 +596,13 @@ public object Array(Type type)
{
if (!IsValidPrefix(Prefix.Array)) throw new InvalidDataException();

var list = (List<dynamic>)Activator.CreateInstance(listType);

var list = Activator.CreateInstance(listType);
var addMethod = list.GetType().GetMethod(nameof(listName.Add));
var toArrayMethod = list.GetType().GetMethod(nameof(listName.ToArray));

if (addMethod == null) throw new NullReferenceException(nameof(addMethod));
if (toArrayMethod == null) throw new NullReferenceException(nameof(toArrayMethod));

var objectCount = BitConverter.ToInt32(VaultArray, Position);
Position += sizeof(int);
Expand Down Expand Up @@ -625,13 +634,13 @@ public object Array(Type type)

if (result.IsError) throw new InvalidDataException();

list.Add(result.Value);
addMethod.Invoke(list, new[] { result.Value });
}
}

return list.ToArray();
return toArrayMethod.Invoke(list, null);
}
catch
catch (Exception e)

Check warning on line 643 in src/src/primitive/partials/PrimitiveGet.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'e' is declared but never used
{
return SetError<object>();
}
Expand Down

0 comments on commit 0ce5808

Please sign in to comment.