Skip to content

Commit

Permalink
dotnet bug. try fix struct->SetValue (reflection)
Browse files Browse the repository at this point in the history
  • Loading branch information
alec1o committed May 21, 2024
1 parent d806d19 commit da8d599
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/src/partials/PrimitiveGet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public T Class<T>()
try
{
if (!typeof(T).IsClass) throw new InvalidOperationException("Only class is accepted");

if (!IsValidPrefix(Prefix.Class)) throw new InvalidDataException();

int objectCount = BitConverter.ToInt32(VaultArray, Position);
Expand Down Expand Up @@ -425,7 +425,7 @@ public T Class<T>()
public T Struct<T>()
{
Type type = typeof(T);

try
{
if (!(type.IsValueType && !type.IsEnum && !type.IsPrimitive))
Expand Down Expand Up @@ -475,8 +475,18 @@ public T Struct<T>()
throw new InvalidDataException();
}

// TODO: fix this bug (is set value)
prop.SetValue(instance, result.Value);
{
// WARNING: dotnet standard bug. but this code working if running in dotnet 8+
// NOTICE 1*: https://stackoverflow.com/questions/9694404/propertyinfo-setvalue-not-working-but-no-errors
// NOTICE 1 (original): https://bytes.com/topic/visual-basic-net/372981-cannot-get-propertyinfo-setvalue-work-structure
// prop.SetValue(instance, result.Value);
}
{
// NOTICE 1*: https://stackoverflow.com/questions/9694404/propertyinfo-setvalue-not-working-but-no-errors
// NOTICE 1 (Original): https://stackoverflow.com/questions/6280506/is-there-a-way-to-set-properties-on-struct-instances-using-reflection

// typeof(T).GetField(prop.Name).SetValue(instance, result.Value);
}
}
}

Expand Down

0 comments on commit da8d599

Please sign in to comment.