Objekttiefe Kopie in Silverlight
Ich habe versucht, eine Kopie von Objekten in zu erstellensilverligth 5 wo Schnittstellen wie IFormatters und IcCloanble nicht unterstützen. *
Meine Objekte sind wie folgt: (Beachten Sie, dass diese Objekte beim Deserialisieren von XML erhalten werden): Ich habe versucht, wie folgt zu kopieren:
[XmlRoot(ElementName = "component")]
public class Component
{
[XmlElement("attributes")]
public Attributes Attributes { get; set; }
[XmlIgnore]
public Attributes atrbtOrginal = new Attributes();
[XmlIgnore]
public Attributes atrbtCopy{ get; set; }
}
public Component()
{
atrbtCopy= atrbtOrginal ;
}
Sicher, es wird nicht funktionieren, dann habe ich diesen Code zum Seraching bei Google:
public static class ObjectCopier
{
public static T Clone<T>(T source)
{
if (!typeof(T).IsSerializable)
{
throw new ArgumentException("The type must be serializable.", "source");
}
// Don't serialize a null object, simply return the default for that object
if (Object.ReferenceEquals(source, null))
{
return default(T);
}
IFormatter formatter = new BinaryFormatter();
Stream stream = new MemoryStream();
using (stream)
{
formatter.Serialize(stream, source);
stream.Seek(0, SeekOrigin.Begin);
return (T)formatter.Deserialize(stream);
}
}
}
And i thought of doing something liek this:
objectOrginal.Clone();.
Aber das Problem bei silverligth5 ist:
Error 2 The type or namespace name 'BinaryFormatter' could not be found (are you missing a using directive or an assembly reference?)
Error 1 The type or namespace name 'IFormatter' could not be found (are you missing a using directive or an assembly reference?)
Gibt es eine Alternative in Silverlight 5? Bitte erläutern Sie im Detail. Danke vielmals.