clone

How to deep clone objects containing an IList property using AutoMapper

懵懂的女人 提交于 2019-11-30 17:40:02
I am trying to deep clone the following class using AutoMapper: public class MainData { public MainData() { Details = new List<Detail>(); } public int Id { get; private set; } public DateTime LastUpdate { get; private set; } public IList<Detail> Details { get; private set; } public int Prop1 { get; set; } public int Prop2 { get; set; } public void AddDetail(Detail detail) { Details.Add(detail); } public void RemoveDetail(Detail detail) { Details.Remove(detail); } public MainData Clone() { Mapper.Reset(); Mapper.CreateMap<MainData, MainData>().ForMember(d => d.Id, o => o.Ignore()); // Mapper

jQuery: clone elements AND events

老子叫甜甜 提交于 2019-11-30 17:35:35
Whenever I use ajax to dynamically create new content, .clone(), append() etc, the new element looses any triggers and events I programmed =( After making copy, simple things that WORK on other elements like adding a class to , on the copied elements no longer work. Any new ajax content does not work. Command buttons no longer work. What can I do? I am cloning this HTML, and the command buttons no longer work. Styling the span elements no longer work on the CLONED elements: <div name="shows" id="x"><br/> <!-- The ID depends on the database--> <div name="shows" id="x"> ID: <input disabled=

clone() has protected access - made public Object clone()

ⅰ亾dé卋堺 提交于 2019-11-30 17:17:47
I'm writing code to create an object, clone the object, then compare the two. The object in question, Octagon, is an extension of an object GeometricObject public class Octagon extends GeometricObject implements Comparable<Octagon>, Cloneable { private double side; public Octagon (double side){ this.side = side; } public Object clone() throws CloneNotSupportedException { Octagon octClone = (Octagon)super.clone(); return octClone; } In a file named Octagon.java In another, TestOctagon.java, is my main method: public class TestOctagon { public static void main(String[] args) { GeometricObject

How can I “deeply” clone the properties of closed source 3rd party classes?

♀尐吖头ヾ 提交于 2019-11-30 16:45:40
The ICloneable interface of the .NET framework usually provides a way to support cloning of an instance of a class. But if I have multiple 3rd party classes , and don't want to care about each of the properties individually, how can I clone objects of those classes efficiently? (The source code of those classes is not available). Is there a way using generics and extension methods ? What I need is a deep clone which creates an exact copy including all the properties and (child) objects. Example: Suppose you want to clone a UserQuery object in LinqPad : void Main() { UserQuery uc=this; var copy

How to deep clone objects containing an IList property using AutoMapper

落花浮王杯 提交于 2019-11-30 16:42:54
问题 I am trying to deep clone the following class using AutoMapper: public class MainData { public MainData() { Details = new List<Detail>(); } public int Id { get; private set; } public DateTime LastUpdate { get; private set; } public IList<Detail> Details { get; private set; } public int Prop1 { get; set; } public int Prop2 { get; set; } public void AddDetail(Detail detail) { Details.Add(detail); } public void RemoveDetail(Detail detail) { Details.Remove(detail); } public MainData Clone() {

Clone Entire JavaScript ScriptEngine

只谈情不闲聊 提交于 2019-11-30 14:37:30
I need to somehow deep clone the entire set of bindings of my ScriptEngine object. What I have tried I have tried so far the Cloner library to clone the entire Bindings structure. This would be great if it worked because it would have ensured a precise copy, including private variables. But this leads to jvm heap corruption (the jvm just crashes with exit code -1073740940). Sometimes it doesn't crash but weird things happen, like the System.out.println() stops working as it should... I have also looked into cloning the objects using js code inside the ScriptEngine, so that I can get those as

Why no default clone() in Cloneable in Java 8

微笑、不失礼 提交于 2019-11-30 13:56:15
问题 Cloneable in Java is inherently broken. Specifically, my biggest problem with the interface is it expects a method behavior that doesn't define the method itself. So if traversing through a Cloneable list you must use reflection to access its defined behavior. However, in Java 8, we now have default methods and now I ask why there isn't a default clone() method in Cloneable . I understand why interfaces cannot default Object methods, however, this was an explicit design decision and so

Cloning datepicker objects [JQuery]

一曲冷凌霜 提交于 2019-11-30 13:48:40
I have an input field that I define as a datepicker through a css class. I now want to clone this input field and have it so the cloned inputs are also datepickers. After reading from various sources I was lead to believe that the following code should work but it doesn't. I was hoping maybe someone could help me figure out what I was doing wrong :) <input type="text" id="date" name="date" class="calendar" /> <input type="button" id="clone" name="clone" value="Clone dates" /> And here's the javascript: <script type="text/javascript"> $(document).ready(function(){ $('.calendar').datepicker(); $

Can clone method create object using constructor

丶灬走出姿态 提交于 2019-11-30 13:42:17
I always thought that clone() creates an object without calling a constructor. But, while reading Effective Java Item 11: Override clone judiciously , I found a statement which says that The provision that “no constructors are called” is too strong. A well-behaved clone method can call constructors to create objects internal to the clone under construction. If the class is final, clone can even return an object created by a constructor. Can someone please explain this to me? I always thought that clone() creates an object without calling a constructor. The implementation in Object.clone()

Duplicating a Ruby array of strings

﹥>﹥吖頭↗ 提交于 2019-11-30 12:44:47
arr = ["red","green","yellow"] arr2 = arr.clone arr2[0].replace("blue") puts arr.inspect puts arr2.inspect produces: ["blue", "green", "yellow"] ["blue", "green", "yellow"] Is there anyway to do a deep copy of an array of strings, other than using Marshal as i understand that is a hack. I could do: arr2 = [] arr.each do |e| arr2 << e.clone end but it doesn't seem very elegant, or efficient. Thanks Your second solution can be shortened to arr2 = arr.map do |e| e.dup end (unless you actually need the behaviour of clone , it's recommended to use dup instead). Other than that your two solutions