Hi,
Proposal
Please add a couple of generic methods to the SerializationInfo class.
Added API:
public class SerializationInfo {
+ public void AddValue<T>(string name, T value);
+ public T GetValue<T>(string name);
}
Motive
Currently, when we want to use SerializationInfo in a serialization context (binary in my scenario), I have to convert all the fields back and forth.
Here's an example of how ugly this can get.
protected CategoryGroupDefinition(SerializationInfo info, StreamingContext context)
: this(
(Guid)info.GetValue(nameof(Id), typeof(Guid)),
info.GetString(nameof(Title)),
(CategoryGroupDefinition)info.GetValue(nameof(Parent), typeof(CategoryGroupDefinition)),
(GroupType)info.GetValue(nameof(Type), typeof(GroupType)),
info.GetBoolean(nameof(IsMandatory)),
(CategoryDefinition[])info.GetValue(nameof(Children), typeof(CategoryDefinition[])))
{
}
Adding some generic methods will shorten the above to:
protected CategoryGroupDefinition(SerializationInfo info, StreamingContext context)
: this(
info.GetValue<Guid>(nameof(Id)),
info.GetString(nameof(Title)),
info.GetValue<CategoryGroupDefinition>(nameof(Parent)),
info.GetValue<GroupType>(nameof(Type)),
info.GetBoolean(nameof(IsMandatory)),
info.GetValue<CategoryDefinition[]>(nameof(Children)))
{
}
Hi,
Proposal
Please add a couple of generic methods to the
SerializationInfoclass.Added API:
Motive
Currently, when we want to use
SerializationInfoin a serialization context (binary in my scenario), I have to convert all the fields back and forth.Here's an example of how ugly this can get.
Adding some generic methods will shorten the above to: