Hi Joannes,
What I am supposed to do with this ISerializable object ? One idiotic
solution is to create a BinaryFormatter and to use it to serialize the
object. In this case it would even "fit" my needs. But is there any way
where I do not need to rely on an existing formatter to implement my own ?
Have a look at
FormatterServices
SerializationInfo.GetEnumerator()
SerializationInfoEnumerator
public void Serialize(Stream stream, object graph)
{
if(someObject.GetType().IsSubClassOf(typeof(ISerialisable))
{
SerializationInfo info = new SerializationInfo(
someObject.GetType(), new FormatterConverter());
((ISerializable)someObject).GetObjectData(info, context);
SerializationInfoEnumerator e = info.GetEnumerator();
while (e.MoveNext) {
// do something with e.Name, e.Value ...
}
}
else { // not ISerializable
MemberInfo[] memberList =
FormatterServices.GetSerializableMember(someObject.GetType());
object[] dataList =
FormatterServices.GetObjectData(someObject, memberList);
for (int i = 0; i < memberList.Length; i++) {
// do something with memberList
and dataList
}
}
}
This might not be complete! I never developed a formatter,
just took a look at one. You are supposed to handle ISerialization-
Surrogates too.
bye
Rob