-
Clone基类http://www.legalsoft.com.cn/docs/986.html
-
-
-
-
-
-
- public abstract class BaseObject : ICloneable
- {
-
-
-
-
- public object Clone()
- {
-
- object newObject = Activator.CreateInstance(this.GetType());
-
- FieldInfo[] fields = newObject.GetType().GetFields();
- int i = 0;
- foreach (FieldInfo fi in this.GetType().GetFields())
- {
-
- Type ICloneType = fi.FieldType.GetInterface("ICloneable", true);
- if (ICloneType != null)
- {
-
- ICloneable IClone = (ICloneable)fi.GetValue(this);
-
- fields[i].SetValue(newObject, IClone.Clone());
- }
- else
- {
-
- fields[i].SetValue(newObject, fi.GetValue(this));
- }
-
-
- Type IEnumerableType = fi.FieldType.GetInterface("IEnumerable", true);
- if (IEnumerableType != null)
- {
-
- IEnumerable IEnum = (IEnumerable)fi.GetValue(this);
- Type IListType = fields[i].FieldType.GetInterface("IList", true);
- Type IDicType = fields[i].FieldType.GetInterface("IDictionary", true);
- int j = 0;
- if (IListType != null)
- {
-
- IList list = (IList)fields[i].GetValue(newObject);
- foreach (object obj in IEnum)
- {
-
- ICloneType = obj.GetType().GetInterface("ICloneable", true);
- if (ICloneType != null)
- {
-
-
- ICloneable clone = (ICloneable)obj;
- list[j] = clone.Clone();
- }
-
-
-
- j++;
- }
- }
- else if (IDicType != null)
- {
-
- IDictionary dic = (IDictionary)fields[i].GetValue(newObject);
- j = 0;
- foreach (DictionaryEntry de in IEnum)
- {
-
- ICloneType = de.Value.GetType().
- GetInterface("ICloneable", true);
- if (ICloneType != null)
- {
- ICloneable clone = (ICloneable)de.Value;
- dic[de.Key] = clone.Clone();
- }
- j++;
- }
- }
- }
- i++;
- }
- return newObject;
- }
- }
-
相关阅读:
Go语言通道(chan)——goroutine之间通信的管道
GO语言数组,切片,MAP总结
GO数组
GO切片
GO语言测试
GO语言html模板
Go语言中defer语句使用小结
微信小程序 某个页面直接返回首页
小程序常用变量
bzoj1030
-
原文地址:https://www.cnblogs.com/si812cn/p/1629699.html
Copyright © 2020-2023
润新知