ISerializationInfo

  • Thread starter Thread starter emma middlebrook
  • Start date Start date
E

emma middlebrook

Hi

Why do we have both AddValue(string, object) and AddValue(string,
object, Type)?

Also, why are the other overloads of AddValue with all the specific
types as the 2nd parameter necessary?

It seems we just require AddValue(string, object) only!

Thanks in advance for any clarification.

Emma Middlebrook
(e-mail address removed)
 
Emma,
Why do we have both AddValue(string, object) and AddValue(string,
object, Type)?

I think it's because of type-safe serialization. In other words, this should
prevent you from serializing an object of type A and then de-serializing it
as an object of type B.
Remember that the GetValue method requires the type of the value to be
specified, so it should be able to detect any type inconsistency ASAP when
the type has been specified in the AddValue call.

I also suppose this might optimize type conversion - the serialization
engine will know to which type to convert the retrieved value so you won't
have to do any type conversion manually, only type casting will be
necessary.
 
Thanks for your reply!

But the implementation of AddValue(string, object) could/should just
call object.GetType() so why do we need both? Would we ever want to
add object via AddValue without always wanting it to be added as
object.GetType()?

See what I mean?

Cheers

Emma

Dmitriy Lapshin said:
Emma,
Why do we have both AddValue(string, object) and AddValue(string,
object, Type)?

I think it's because of type-safe serialization. In other words, this should
prevent you from serializing an object of type A and then de-serializing it
as an object of type B.
Remember that the GetValue method requires the type of the value to be
specified, so it should be able to detect any type inconsistency ASAP when
the type has been specified in the AddValue call.

I also suppose this might optimize type conversion - the serialization
engine will know to which type to convert the retrieved value so you won't
have to do any type conversion manually, only type casting will be
necessary.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

emma middlebrook said:
Hi

Why do we have both AddValue(string, object) and AddValue(string,
object, Type)?

Also, why are the other overloads of AddValue with all the specific
types as the 2nd parameter necessary?

It seems we just require AddValue(string, object) only!

Thanks in advance for any clarification.

Emma Middlebrook
(e-mail address removed)
 
Emma,

You are welcome and I see your point. My guess is that the user might pass a
reference upcast to System.Object (this might prevent automatic type
derivation) and would still like to have an ability to serialize the
instance as a given type.
 
Back
Top