in src/AutoRest.CSharp/Common/Output/Builders/XmlSerializationMethodsBuilder.cs [392:479]
private static ValueExpression DeserializeValue(XmlValueSerialization serialization, ValueExpression value)
{
var type = serialization.Type;
if (type.IsFrameworkType)
{
var frameworkType = type.FrameworkType;
if (frameworkType == typeof(bool) ||
frameworkType == typeof(char) ||
frameworkType == typeof(short) ||
frameworkType == typeof(int) ||
frameworkType == typeof(long) ||
frameworkType == typeof(float) ||
frameworkType == typeof(double) ||
frameworkType == typeof(decimal) ||
frameworkType == typeof(string)
)
{
return value.CastTo(type);
}
if (frameworkType == typeof(ResourceIdentifier))
{
return New.Instance(typeof(ResourceIdentifier), value.CastTo(typeof(string)));
}
if (frameworkType == typeof(SystemData))
{
// XML Deserialization of SystemData isn't supported yet.
return Null;
}
if (frameworkType == typeof(ResourceType))
{
return value.CastTo(typeof(string));
}
if (frameworkType == typeof(Guid))
{
return value is XElementExpression xElement
? New.Instance(typeof(Guid), xElement.Value)
: value.CastTo(typeof(Guid));
}
if (frameworkType == typeof(Uri))
{
return New.Instance(typeof(Uri), value.CastTo(typeof(string)));
}
if (value is XElementExpression element)
{
if (frameworkType == typeof(byte[]))
{
return element.GetBytesFromBase64Value(serialization.Format.ToFormatSpecifier());
}
if (frameworkType == typeof(DateTimeOffset))
{
return element.GetDateTimeOffsetValue(serialization.Format.ToFormatSpecifier());
}
if (frameworkType == typeof(TimeSpan))
{
return element.GetTimeSpanValue(serialization.Format.ToFormatSpecifier());
}
if (frameworkType == typeof(object))
{
return element.GetObjectValue(serialization.Format.ToFormatSpecifier());
}
}
}
switch (type.Implementation)
{
case SerializableObjectType serializableObjectType:
return SerializableObjectTypeExpression.Deserialize(serializableObjectType, value);
case EnumType clientEnum when value is XElementExpression xe:
return EnumExpression.ToEnum(clientEnum, xe.Value);
case EnumType clientEnum when value is XAttributeExpression xa:
return EnumExpression.ToEnum(clientEnum, xa.Value);
default:
throw new NotSupportedException();
}
}