: DataContract Serializable .net
, , :
"... , , ?"
Reflection, , , .
. , . :
private void InspectRecursively(object input,
Dictionary<object, bool> processedObjects)
{
if ((input != null) && !processedObjects.ContainsKey(input))
{
processedObjects.Add(input, true);
List<FieldInfo> fields = type.GetFields(BindingFlags.Instance |
BindingFlags.Public | BindingFlags.NonPublic );
foreach (FieldInfo field in fields)
{
object nextInput = field.GetValue(input);
if (nextInput is System.Collections.IEnumerable)
{
System.Collections.IEnumerator enumerator = (nextInput as
System.Collections.IEnumerable).GetEnumerator();
while (enumerator.MoveNext())
{
InspectRecursively(enumerator.Current, processedObjects);
}
}
else
{
InspectRecursively(nextInput, processedObjects);
}
}
}
}
, - System.Runtime.Serialization.FormatterServices.GetUninitializedObject(Type type) ( ) . , - field.SetValue(input, output)
However, this implementation does not support registered event handlers, which are _ un _supported by deserialization. In addition, each object in the hierarchy will be split if its class constructor needs to initialize anything other than setting all the fields. The last point only works with serialization if the class has an appropriate implementation, for example. the method noted [OnDeserialized]implements ISerializable....
source
share