Terraria v1.4.4.9
Terraria source code documentation
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros

◆ WritePrimitive()

object System.Xml.Serialization.ReflectionXmlSerializationReader.WritePrimitive ( TypeMapping mapping,
Func< object, string > readFunc,
object funcState )
inlineprivate

Definition at line 1045 of file ReflectionXmlSerializationReader.cs.

1046 {
1047 if (mapping is EnumMapping mapping2)
1048 {
1050 }
1051 if (mapping.TypeDesc == StringTypeDesc)
1052 {
1053 return readFunc(funcState);
1054 }
1055 if (mapping.TypeDesc.FormatterName == "String")
1056 {
1057 if (mapping.TypeDesc.CollapseWhitespace)
1058 {
1060 }
1061 return readFunc(funcState);
1062 }
1063 if (!mapping.TypeDesc.HasCustomFormatter)
1064 {
1065 string s = readFunc(funcState);
1066 return mapping.TypeDesc.FormatterName switch
1067 {
1068 "Boolean" => XmlConvert.ToBoolean(s),
1069 "Int32" => XmlConvert.ToInt32(s),
1070 "Int16" => XmlConvert.ToInt16(s),
1071 "Int64" => XmlConvert.ToInt64(s),
1072 "Single" => XmlConvert.ToSingle(s),
1073 "Double" => XmlConvert.ToDouble(s),
1074 "Decimal" => XmlConvert.ToDecimal(s),
1075 "Byte" => XmlConvert.ToByte(s),
1076 "SByte" => XmlConvert.ToSByte(s),
1077 "UInt16" => XmlConvert.ToUInt16(s),
1078 "UInt32" => XmlConvert.ToUInt32(s),
1079 "UInt64" => XmlConvert.ToUInt64(s),
1080 "Guid" => XmlConvert.ToGuid(s),
1081 "Char" => XmlConvert.ToChar(s),
1082 "TimeSpan" => XmlConvert.ToTimeSpan(s),
1083 "DateTimeOffset" => XmlConvert.ToDateTimeOffset(s),
1084 _ => throw new InvalidOperationException(System.SR.Format(System.SR.XmlInternalErrorDetails, "unknown FormatterName: " + mapping.TypeDesc.FormatterName)),
1085 };
1086 }
1087 string name = "To" + mapping.TypeDesc.FormatterName;
1088 MethodInfo method = typeof(XmlSerializationReader).GetMethod(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { typeof(string) });
1089 if (method == null)
1090 {
1091 throw new InvalidOperationException(System.SR.Format(System.SR.XmlInternalErrorDetails, "unknown FormatterName: " + mapping.TypeDesc.FormatterName));
1092 }
1093 return method.Invoke(this, new object[1] { readFunc(funcState) });
1094 }
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string XmlInternalErrorDetails
Definition SR.cs:1814
Definition SR.cs:7
object WriteEnumMethod(EnumMapping mapping, Func< object, string > readFunc, object funcState)

References System.Xml.Serialization.CollapseWhitespace, System.Xml.Dictionary, System.SR.Format(), System.s, System.Xml.Serialization.ReflectionXmlSerializationReader.StringTypeDesc, System.Xml.XmlConvert.ToBoolean(), System.Xml.XmlConvert.ToByte(), System.Xml.XmlConvert.ToChar(), System.Xml.XmlConvert.ToDateTimeOffset(), System.Xml.XmlConvert.ToDecimal(), System.Xml.XmlConvert.ToDouble(), System.Xml.XmlConvert.ToGuid(), System.Xml.XmlConvert.ToInt16(), System.Xml.XmlConvert.ToInt32(), System.Xml.XmlConvert.ToInt64(), System.Xml.XmlConvert.ToSByte(), System.Xml.XmlConvert.ToSingle(), System.Xml.XmlConvert.ToTimeSpan(), System.Xml.XmlConvert.ToUInt16(), System.Xml.XmlConvert.ToUInt32(), System.Xml.XmlConvert.ToUInt64(), System.Xml.Serialization.ReflectionXmlSerializationReader.WriteEnumMethod(), and System.SR.XmlInternalErrorDetails.

Referenced by System.Xml.Serialization.ReflectionXmlSerializationReader.WriteAttribute(), System.Xml.Serialization.ReflectionXmlSerializationReader.WriteElement(), and System.Xml.Serialization.ReflectionXmlSerializationReader.WriteMemberText().