diff --git a/Cast.cs b/Cast.cs
index e8ad79b..58f28c5 100644
--- a/Cast.cs
+++ b/Cast.cs
@@ -33,7 +33,30 @@ namespace ln.types
!Explicit(value, value.GetType(), targetType, out casted)
)
{
- casted = Convert.ChangeType(value, targetType);
+ if (targetType.IsEnum)
+ {
+ if (value is string sValue)
+ {
+ casted = Enum.Parse(targetType, sValue);
+ } else
+ {
+ throw new NotSupportedException();
+ }
+ }
+ else if (targetType.IsArray)
+ {
+ Array array = value as Array;
+ Array castedArray = Array.CreateInstance(targetType.GetElementType(), array.Length);
+
+ for (int n = 0; n < array.Length; n++)
+ castedArray.SetValue(To(array.GetValue(n), targetType.GetElementType()), n);
+
+ casted = castedArray;
+ }
+ else
+ {
+ casted = Convert.ChangeType(value, targetType);
+ }
}
return casted;
}
diff --git a/ln.types.csproj b/ln.types.csproj
index 37fda00..7c6b08e 100644
--- a/ln.types.csproj
+++ b/ln.types.csproj
@@ -148,6 +148,7 @@
+
diff --git a/reflection/AttributeDescriptor.cs b/reflection/AttributeDescriptor.cs
index ad5fd0b..1b3d283 100644
--- a/reflection/AttributeDescriptor.cs
+++ b/reflection/AttributeDescriptor.cs
@@ -27,11 +27,13 @@ namespace ln.types.reflection
{
Owner = propertyInfo.DeclaringType;
IsPublic = propertyInfo.GetGetMethod().IsPublic;
- IsReadonly = !(propertyInfo.CanWrite && propertyInfo.GetSetMethod().IsPublic);
+ IsReadonly = !(propertyInfo.CanWrite && propertyInfo.GetSetMethod(true).IsPublic);
AttributeName = propertyInfo.Name;
AttributeType = propertyInfo.PropertyType;
- SetAction = propertyInfo.SetValue;
+ if (propertyInfo.CanWrite)
+ SetAction = propertyInfo.SetValue;
+
GetFunc = propertyInfo.GetValue;
}
public AttributeDescriptor(FieldInfo fieldInfo)
@@ -42,13 +44,18 @@ namespace ln.types.reflection
AttributeName = fieldInfo.Name;
AttributeType = fieldInfo.FieldType;
- SetAction = fieldInfo.SetValue;
+ if (!fieldInfo.IsInitOnly)
+ SetAction = fieldInfo.SetValue;
+
GetFunc = fieldInfo.GetValue;
}
public TypeDescriptor TypeDescriptor => TypeDescriptor.GetDescriptor(Owner);
public object GetValue(object instance) => GetFunc(instance);
- public void SetValue(object instance, object value) => SetAction(instance, value);
+ public void SetValue(object instance, object value) {
+ if (SetAction != null)
+ SetAction(instance, value);
+ }
}
}
diff --git a/reflection/ObjectPool.cs b/reflection/ObjectPool.cs
index f2b8e8f..8a72467 100644
--- a/reflection/ObjectPool.cs
+++ b/reflection/ObjectPool.cs
@@ -1,6 +1,7 @@
using System;
using ln.types.btree;
using System.Collections.Generic;
+using System.Linq;
namespace ln.types.reflection
{
public class ObjectPool
@@ -24,10 +25,22 @@ namespace ln.types.reflection
getIdentity = getIdentityDelegate;
}
- public IEnumerable