Move some classes to Cryville.Common.

This commit is contained in:
2023-05-03 22:51:30 +08:00
parent 8f211568be
commit b143fb49ce
90 changed files with 788 additions and 2457 deletions

View File

@@ -1,4 +1,6 @@
using Cryville.Common.Collections;
using Cryville.Common.Logging;
using Cryville.Common.Reflection;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -266,14 +268,17 @@ namespace Cryville.Common.Pdt {
else {
MemberInfo prop = null;
bool flag = false;
if (pkey is string) prop = ReflectionHelper.TryGetMember(type, (string)pkey);
if (prop == null) flag = ReflectionHelper.TryFindMemberWithAttribute<T>(type, out prop);
if (pkey is string) prop = FieldLikeHelper.GetMember(type, (string)pkey);
if (prop == null) {
prop = FieldLikeHelper.FindMemberWithAttribute<T>(type);
flag = true;
}
if (prop == null) throw new MissingMemberException(string.Format("The property \"{0}\" is not found", pkey));
Type ptype = ReflectionHelper.GetMemberType(prop);
Type ptype = FieldLikeHelper.GetMemberType(prop);
if (flag) {
var origCollection = ReflectionHelper.GetValue(prop, result);
var origCollection = FieldLikeHelper.GetValue(prop, result);
if (origCollection == null) {
ReflectionHelper.SetValue(prop, result, origCollection = Activator.CreateInstance(ptype));
FieldLikeHelper.SetValue(prop, result, origCollection = Activator.CreateInstance(ptype));
}
using (var collection = new PairCollection(origCollection)) {
var ktype = ptype.GetGenericArguments()[0];
@@ -283,7 +288,7 @@ namespace Cryville.Common.Pdt {
collection.Add(key, value);
}
}
else ReflectionHelper.SetValue(prop, result, vfunc(ptype), _binder);
else FieldLikeHelper.SetValue(prop, result, vfunc(ptype), _binder);
}
}
/// <summary>