Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ExportDefaultValue()

static string System.Xml.Serialization.XmlSchemaExporter.ExportDefaultValue ( TypeMapping mapping,
object value )
inlinestaticpackage

Definition at line 907 of file XmlSchemaExporter.cs.

908 {
909 if (!(mapping is PrimitiveMapping))
910 {
911 return null;
912 }
913 if (value == null || value == DBNull.Value)
914 {
915 return null;
916 }
917 if (mapping is EnumMapping)
918 {
919 EnumMapping enumMapping = (EnumMapping)mapping;
920 ConstantMapping[] constants = enumMapping.Constants;
921 if (enumMapping.IsFlags)
922 {
923 string[] array = new string[constants.Length];
924 long[] array2 = new long[constants.Length];
925 Hashtable hashtable = new Hashtable();
926 for (int i = 0; i < constants.Length; i++)
927 {
928 array[i] = constants[i].XmlName;
929 array2[i] = 1 << i;
930 hashtable.Add(constants[i].Name, array2[i]);
931 }
932 long num = XmlCustomFormatter.ToEnum((string)value, hashtable, enumMapping.TypeName, validate: false);
933 if (num == 0L)
934 {
935 return null;
936 }
937 return XmlCustomFormatter.FromEnum(num, array, array2, mapping.TypeDesc.FullName);
938 }
939 for (int j = 0; j < constants.Length; j++)
940 {
941 if (constants[j].Name == (string)value)
942 {
943 return constants[j].XmlName;
944 }
945 }
946 return null;
947 }
948 PrimitiveMapping primitiveMapping = (PrimitiveMapping)mapping;
949 if (!primitiveMapping.TypeDesc.HasCustomFormatter)
950 {
951 if (primitiveMapping.TypeDesc.FormatterName == "String")
952 {
953 return (string)value;
954 }
955 Type typeFromHandle = typeof(XmlConvert);
956 MethodInfo method = typeFromHandle.GetMethod("ToString", new Type[1] { primitiveMapping.TypeDesc.Type });
957 if (method != null)
958 {
959 return (string)method.Invoke(typeFromHandle, new object[1] { value });
960 }
962 }
963 string text = XmlCustomFormatter.FromDefaultValue(value, primitiveMapping.TypeDesc.FormatterName);
964 if (text == null)
965 {
967 }
968 return text;
969 }
virtual void Add(object key, object? value)
Definition Hashtable.cs:676
object? Invoke(object? obj, object?[]? parameters)
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string XmlInvalidDefaultValue
Definition SR.cs:1520
Definition SR.cs:7

References System.Collections.Hashtable.Add(), System.array, System.Xml.Dictionary, System.SR.Format(), System.Xml.Serialization.XmlCustomFormatter.FromDefaultValue(), System.Xml.Serialization.XmlCustomFormatter.FromEnum(), System.Reflection.MethodBase.Invoke(), System.Xml.L, System.Xml.Name, System.text, System.Xml.Serialization.XmlCustomFormatter.ToEnum(), System.DBNull.Value, System.value, and System.SR.XmlInvalidDefaultValue.

Referenced by System.Xml.Serialization.XmlSchemaExporter.ExportAttributeAccessor(), and System.Xml.Serialization.XmlSchemaExporter.ExportElementAccessor().