|
@@ -42,11 +42,10 @@ namespace WCS.Core
|
|
|
objs = new ConcurrentDictionary<object, object>();
|
|
|
ExObjsOfWorld[world] = objs;
|
|
|
}
|
|
|
- if (!objs.TryGetValue(source, out var obj))
|
|
|
- {
|
|
|
- obj = Activator.CreateInstance(typeof(T), source, world);
|
|
|
- objs[source] = obj;
|
|
|
- }
|
|
|
+
|
|
|
+ if (objs.TryGetValue(source, out var obj)) return (T)obj;
|
|
|
+ obj = Activator.CreateInstance(typeof(T), source, world);
|
|
|
+ objs[source] = obj;
|
|
|
return (T)obj;
|
|
|
}
|
|
|
|
|
@@ -90,10 +89,7 @@ namespace WCS.Core
|
|
|
var name = Enum.GetName<T>(source);
|
|
|
var f = source.GetType().GetField(name);
|
|
|
var attr = f.GetCustomAttribute<DescriptionAttribute>();
|
|
|
- if (attr == null)
|
|
|
- return source.ToString();
|
|
|
- else
|
|
|
- return attr.Description;
|
|
|
+ return attr == null ? source.ToString() : attr.Description;
|
|
|
}
|
|
|
|
|
|
public static object Copy(this object source, Type t, DateTime farme)
|
|
@@ -102,18 +98,16 @@ namespace WCS.Core
|
|
|
foreach (var p in t.GetProperties())
|
|
|
{
|
|
|
var p2 = source.GetType().GetProperty(p.Name);
|
|
|
- if (p2 != null)
|
|
|
+ if (p2 == null) continue;
|
|
|
+ var value = p2.GetValue(source);
|
|
|
+ //判断一下P2的类型是否为字符串
|
|
|
+ if (p2.PropertyType == typeof(string))
|
|
|
{
|
|
|
- var value = p2.GetValue(source);
|
|
|
- //判断一下P2的类型是否为字符串
|
|
|
- if (p2.PropertyType == typeof(string))
|
|
|
- {
|
|
|
- var sValue = (string)value;
|
|
|
- value = sValue.Trim('\0', '\a', '\b', '\f', '\n', '\r', '\t', '\v').Trim();
|
|
|
- }
|
|
|
-
|
|
|
- p.SetValue(obj, value);
|
|
|
+ var sValue = (string)value;
|
|
|
+ value = sValue.Trim('\0', '\a', '\b', '\f', '\n', '\r', '\t', '\v').Trim();
|
|
|
}
|
|
|
+
|
|
|
+ p.SetValue(obj, value);
|
|
|
}
|
|
|
t.GetProperty("Frame").SetValue(obj, farme);
|
|
|
return obj;
|