private static HashSet <String> copyRecord(DataRecord source, DataRecord target, bool copyReadOnlyFields, bool copyNonReplicatableFields, ICollection <String> fields) { var errors = new HashSet <String>(); foreach (var tgtFf in target.getFormat()) { var fieldName = tgtFf.getName(); var srcFf = source.getFormat().getFieldFormat(fieldName); if (fields != null && !fields.Contains(tgtFf.getName())) { continue; } if (srcFf == null) { continue; } if (tgtFf.isReadonly() && !copyReadOnlyFields) { continue; } if (!copyNonReplicatableFields) { if (tgtFf.isNotReplicated() || srcFf.isNotReplicated()) { continue; } } try { if (srcFf.getFieldWrappedClass().Equals(tgtFf.getFieldWrappedClass())) { target.setValue(fieldName, CloneUtils.genericClone(source.getValue(fieldName))); } else { target.setValue(fieldName, tgtFf.valueFromString(srcFf.valueToString(source.getValue(fieldName)))); } } catch (Exception ex2) { var msg = String.Format(Cres.get().getString("dtErrCopyingField"), fieldName); Logger.getLogger(Log.DATATABLE).debug(msg, ex2); errors.Add(msg + ": " + ex2.Message); continue; } } return(errors); }
public void TestCorrectComplexClass() { var obj1 = new CorrectComplexClass(101, "abc"); var obj2 = (CorrectComplexClass)CloneUtils.genericClone(obj1); AssertAreEqualButNotSame(obj1, obj2); AssertAreEqualButNotSame(obj1.objectField, obj2.objectField); obj1.objectField.intValue = 303; Assert.AreEqual(101, obj2.objectField.intValue); }
public void TestList() { var l1 = new List <CorrectSuperComplexClass> { new CorrectSuperComplexClass(101, "abc"), new CorrectSuperComplexClass(202, "def") }; var l2 = (List <CorrectSuperComplexClass>)CloneUtils.genericClone(l1); Assert.AreNotSame(l1, l2); AssertAreEqualButNotSame(l1[0], l2[0]); AssertAreEqualButNotSame(l1[1], l2[1]); }
public void TestStruct() { var struct1 = new SimpleStruct(101, "abc"); var struct2 = (SimpleStruct)CloneUtils.genericClone(struct1); AssertAreEqualButNotSame(struct1, struct2); struct1.intValue = 303; Assert.AreEqual(101, struct2.intValue); Assert.AreEqual("abc", struct1.stringValue); struct2.stringValue = "def"; Assert.AreEqual("abc", struct1.stringValue); }
public void TestSimpleClass() { var obj1 = new SimpleClass(101, "abc"); var obj2 = (SimpleClass)CloneUtils.genericClone(obj1); AssertAreEqualButNotSame(obj1, obj2); obj1.intValue = 303; Assert.AreEqual(101, obj2.intValue); obj2.stringValue = "def"; Assert.AreEqual("abc", obj1.stringValue); obj2.structValue.intValue = 505; Assert.AreEqual(101, obj1.structValue.intValue); }
// TODO: Resync with Java, may (surely?) missing some (new) fields public object Clone() { FieldFormat cl; try { cl = (FieldFormat)this.MemberwiseClone(); } catch (CloneNotSupportedException ex) { throw new InvalidOperationException(ex.Message, ex); } cl.defaultValue = CloneUtils.genericClone(this.getDefaultValue()); cl.selectionValues = (AgDictionary <NullableObject, string>)CloneUtils.deepClone(this.selectionValues); cl.validators = (AgList <FieldValidator>)CloneUtils.deepClone(this.validators); cl.immutable = false; return(cl); }
public void TestObject() { CloneUtils.genericClone(new Object()); }