/// <summary> /// Performs a deep copy of an object if possible. /// </summary> public static object Clone(object source) { if (source == null) { return(null); } if (source.GetType().IsValueType) { return(source); } if (source.GetType().IsArray || source.GetType() == typeof(Array)) { Array array = (Array)((Array)source).Clone(); for (int ii = 0; ii < array.Length; ii++) { array.SetValue(OpcConvert.Clone(array.GetValue(ii)), ii); } return(array); } try { return(((ICloneable)source).Clone()); } catch { throw new NotSupportedException("Object cannot be cloned."); } }
/// <summary> /// Returns a copy of the collection as an array. /// </summary> public virtual Array ToArray() { return((Array)OpcConvert.Clone(array_)); }