Add serialization support for SemanticVersion
This commit is contained in:
parent
046af59538
commit
2b74b89f76
2 changed files with 54 additions and 1 deletions
|
@ -235,6 +235,11 @@ namespace System.Management.Automation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal const string VersionTag = "Version";
|
internal const string VersionTag = "Version";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Element tag for SemanticVersion property
|
||||||
|
/// </summary>
|
||||||
|
internal const string SemanticVersionTag = "SemanticVersion";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Element tag for XmlDocument
|
/// Element tag for XmlDocument
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -2464,6 +2464,24 @@ namespace System.Management.Automation
|
||||||
WriteRawString(serializer, streamName, property, Convert.ToString(source, CultureInfo.InvariantCulture), entry);
|
WriteRawString(serializer, streamName, property, Convert.ToString(source, CultureInfo.InvariantCulture), entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes SemanticVersion
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serializer">The serializer to which the object is serialized.</param>
|
||||||
|
/// <param name="streamName"></param>
|
||||||
|
/// <param name="property">name of property. pass null for item</param>
|
||||||
|
/// <param name="source">Version to write</param>
|
||||||
|
/// <param name="entry">serialization information about source</param>
|
||||||
|
internal static void WriteSemanticVersion(InternalSerializer serializer, string streamName, string property, object source, TypeSerializationInfo entry)
|
||||||
|
{
|
||||||
|
Dbg.Assert(serializer != null, "caller should have validated the information");
|
||||||
|
Dbg.Assert(source != null, "caller should have validated the information");
|
||||||
|
Dbg.Assert(source is SemanticVersion, "Caller should verify that typeof(source) is Version");
|
||||||
|
Dbg.Assert(entry != null, "caller should have validated the information");
|
||||||
|
|
||||||
|
WriteRawString(serializer, streamName, property, Convert.ToString(source, CultureInfo.InvariantCulture), entry);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Serialize scriptblock as item or property
|
/// Serialize scriptblock as item or property
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -4210,6 +4228,29 @@ namespace System.Management.Automation
|
||||||
throw deserializer.NewXmlException(Serialization.InvalidPrimitiveType, recognizedException, typeof(Version).FullName);
|
throw deserializer.NewXmlException(Serialization.InvalidPrimitiveType, recognizedException, typeof(Version).FullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static object DeserializeSemanticVersion(InternalDeserializer deserializer)
|
||||||
|
{
|
||||||
|
Dbg.Assert(deserializer != null, "Caller should validate the parameter");
|
||||||
|
Exception recognizedException = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return new SemanticVersion(deserializer._reader.ReadElementContentAsString());
|
||||||
|
}
|
||||||
|
catch (ArgumentException e)
|
||||||
|
{
|
||||||
|
recognizedException = e;
|
||||||
|
}
|
||||||
|
catch (FormatException e)
|
||||||
|
{
|
||||||
|
recognizedException = e;
|
||||||
|
}
|
||||||
|
catch (OverflowException e)
|
||||||
|
{
|
||||||
|
recognizedException = e;
|
||||||
|
}
|
||||||
|
throw deserializer.NewXmlException(Serialization.InvalidPrimitiveType, recognizedException, typeof(Version).FullName);
|
||||||
|
}
|
||||||
|
|
||||||
internal static object DeserializeInt16(InternalDeserializer deserializer)
|
internal static object DeserializeInt16(InternalDeserializer deserializer)
|
||||||
{
|
{
|
||||||
Dbg.Assert(deserializer != null, "Caller should validate the parameter");
|
Dbg.Assert(deserializer != null, "Caller should validate the parameter");
|
||||||
|
@ -5149,6 +5190,13 @@ namespace System.Management.Automation
|
||||||
SerializationStrings.VersionTag,
|
SerializationStrings.VersionTag,
|
||||||
InternalSerializer.WriteVersion,
|
InternalSerializer.WriteVersion,
|
||||||
InternalDeserializer.DeserializeVersion),
|
InternalDeserializer.DeserializeVersion),
|
||||||
|
|
||||||
|
new TypeSerializationInfo(typeof(SemanticVersion),
|
||||||
|
SerializationStrings.SemanticVersionTag,
|
||||||
|
SerializationStrings.SemanticVersionTag,
|
||||||
|
InternalSerializer.WriteSemanticVersion,
|
||||||
|
InternalDeserializer.DeserializeSemanticVersion),
|
||||||
|
|
||||||
s_xdInfo,
|
s_xdInfo,
|
||||||
|
|
||||||
new TypeSerializationInfo(typeof(ProgressRecord),
|
new TypeSerializationInfo(typeof(ProgressRecord),
|
||||||
|
@ -5162,7 +5210,7 @@ namespace System.Management.Automation
|
||||||
SerializationStrings.SecureStringTag,
|
SerializationStrings.SecureStringTag,
|
||||||
InternalSerializer.WriteSecureString,
|
InternalSerializer.WriteSecureString,
|
||||||
InternalDeserializer.DeserializeSecureString),
|
InternalDeserializer.DeserializeSecureString),
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Hashtable of knowntypes.
|
/// Hashtable of knowntypes.
|
||||||
|
|
Loading…
Reference in a new issue