public static void CloneObject(object cloneFrom, object cloneTo) { foreach (PropertyInfo propertyInfo in SFClass.PropertyInfoGetAll(cloneFrom)) { try { SFClass.SetPropertyValue(cloneTo, propertyInfo.Name, propertyInfo.GetValue(cloneFrom)); } catch { } } }
public static object CloneObject(object source) { object instance = Activator.CreateInstance(source.GetType()); foreach (PropertyInfo propertyInfo in SFClass.PropertyInfoGetAll(source)) { try { SFClass.SetPropertyValue(instance, propertyInfo.Name, propertyInfo.GetValue(source)); } catch { } } return(instance); }
public static void SetObjectFromString(ref object sourceObject, char delimiter, string value) { if (string.IsNullOrEmpty(value) || sourceObject == null) { return; } List <string> stringList = new List <string>((IEnumerable <string>)value.Split(delimiter)); if (stringList.Count <= 0) { return; } for (int index = 0; index < stringList.Count; ++index) { string[] strArray = stringList[index].Split(':'); if (strArray.Length == 2) { SFClass.SetPropertyValue(sourceObject, strArray[0], (object)strArray[1]); } } }