System.Xml.Serialization.XmlCustomFormatter.ToDateTime C# (CSharp) Method

ToDateTime() static private method

static private ToDateTime ( string value ) : System.DateTime
value string
return System.DateTime
        internal static DateTime ToDateTime(string value)
        {
            if (Mode == DateTimeSerializationSection.DateTimeSerializationMode.Local)
            {
                return ToDateTime(value, s_allDateTimeFormats);
            }
            else
            {
                // for mode DateTimeSerializationMode.Roundtrip and DateTimeSerializationMode.Default
                return XmlConvert.ToDateTime(value, XmlDateTimeSerializationMode.RoundtripKind);
            }
        }

Same methods

XmlCustomFormatter::ToDateTime ( string value, string formats ) : System.DateTime

Usage Example

 private object ImportDefaultValue(TypeMapping mapping, string defaultValue)
 {
     if (defaultValue == null)
     {
         return(null);
     }
     if (mapping is PrimitiveMapping)
     {
         if (mapping is EnumMapping)
         {
             EnumMapping       mapping2  = (EnumMapping)mapping;
             ConstantMapping[] constants = mapping2.Constants;
             if (mapping2.IsFlags)
             {
                 Hashtable vals     = new Hashtable();
                 string[]  strArray = new string[constants.Length];
                 long[]    ids      = new long[constants.Length];
                 for (int j = 0; j < constants.Length; j++)
                 {
                     ids[j]      = mapping2.IsFlags ? (((long)1L) << j) : ((long)j);
                     strArray[j] = constants[j].Name;
                     vals.Add(constants[j].Name, ids[j]);
                 }
                 return(XmlCustomFormatter.FromEnum(XmlCustomFormatter.ToEnum(defaultValue, vals, mapping2.TypeName, true), strArray, ids, mapping2.TypeDesc.FullName));
             }
             for (int i = 0; i < constants.Length; i++)
             {
                 if (constants[i].XmlName == defaultValue)
                 {
                     return(constants[i].Name);
                 }
             }
             throw new InvalidOperationException(Res.GetString("XmlInvalidDefaultValue", new object[] { defaultValue, mapping2.TypeDesc.FullName }));
         }
         PrimitiveMapping mapping3 = (PrimitiveMapping)mapping;
         if (!mapping3.TypeDesc.HasCustomFormatter)
         {
             if (mapping3.TypeDesc.FormatterName == "String")
             {
                 return(defaultValue);
             }
             if (mapping3.TypeDesc.FormatterName == "DateTime")
             {
                 return(XmlCustomFormatter.ToDateTime(defaultValue));
             }
             Type       type   = typeof(XmlConvert);
             MethodInfo method = type.GetMethod("To" + mapping3.TypeDesc.FormatterName, new Type[] { typeof(string) });
             if (method != null)
             {
                 return(method.Invoke(type, new object[] { defaultValue }));
             }
         }
         else if (mapping3.TypeDesc.HasDefaultSupport)
         {
             return(XmlCustomFormatter.ToDefaultValue(defaultValue, mapping3.TypeDesc.FormatterName));
         }
     }
     return(DBNull.Value);
 }
All Usage Examples Of System.Xml.Serialization.XmlCustomFormatter::ToDateTime