Example #1
0
 internal byte[] ReadContentAsBase64(string str)
 {
     byte[] buffer;
     if (str == null)
     {
         return(null);
     }
     str = str.Trim();
     if (str.Length == 0)
     {
         return(new byte[0]);
     }
     try
     {
         buffer = Convert.FromBase64String(str);
     }
     catch (ArgumentException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "byte[]", exception));
     }
     catch (FormatException exception2)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "byte[]", exception2));
     }
     return(buffer);
 }
Example #2
0
        // Overridden because base reader relies on XmlConvert.ToUInt64 for conversion to ulong
        internal override UInt64 ReadElementContentAsUnsignedLong()
        {
            if (isEndOfEmptyElement)
            {
                throw new XmlException(SR.Format(SR.XmlStartElementExpected, "EndElement"));
            }

            string value = reader.ReadElementContentAsString();

            if (value == null || value.Length == 0)
            {
                throw new XmlException(XmlObjectSerializer.TryAddLineInfo(this, SR.Format(SR.XmlInvalidConversion, value, "UInt64")));
            }

            try
            {
                return(ulong.Parse(value, NumberStyles.Float, NumberFormatInfo.InvariantInfo));
            }
            catch (ArgumentException exception)
            {
                throw XmlExceptionHelper.CreateConversionException(value, "UInt64", exception);
            }
            catch (FormatException exception)
            {
                throw XmlExceptionHelper.CreateConversionException(value, "UInt64", exception);
            }
            catch (OverflowException exception)
            {
                throw XmlExceptionHelper.CreateConversionException(value, "UInt64", exception);
            }
        }
        internal override UInt64 ReadElementContentAsUnsignedLong()
#endif
        {
            if (isEndOfEmptyElement)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString(System.Runtime.Serialization.SR.XmlStartElementExpected, "EndElement")));
            }

            string value = reader.ReadElementContentAsString();

            if (value == null || value.Length == 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(XmlObjectSerializer.TryAddLineInfo(this, System.Runtime.Serialization.SR.GetString(System.Runtime.Serialization.SR.XmlInvalidConversion, value, "UInt64"))));
            }

            try
            {
                return(ulong.Parse(value, NumberStyles.Float, NumberFormatInfo.InvariantInfo));
            }
            catch (ArgumentException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "UInt64", exception));
            }
            catch (FormatException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "UInt64", exception));
            }
            catch (OverflowException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "UInt64", exception));
            }
        }
Example #4
0
        internal byte[] ReadContentAsBase64(string str)
        {
            if (str == null)
            {
                return(null);
            }
            str = str.Trim();
            if (str.Length == 0)
            {
                return(Array.Empty <byte>());
            }

            try
            {
                return(Convert.FromBase64String(str));
            }
            catch (ArgumentException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "byte[]", exception));
            }
            catch (FormatException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "byte[]", exception));
            }
        }
Example #5
0
        internal Guid ReadElementContentAsGuid()
#endif
        {
            if (isEndOfEmptyElement)
            {
                ThrowNotAtElement();
            }

            string str = reader.ReadElementContentAsString();

            try
            {
                return(new Guid(str));
            }
            catch (ArgumentException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
            }
            catch (FormatException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
            }
            catch (OverflowException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
            }
        }
        internal override ulong ReadElementContentAsUnsignedLong()
        {
            ulong num;

            if (base.isEndOfEmptyElement)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("XmlStartElementExpected", new object[] { "EndElement" })));
            }
            string s = base.reader.ReadElementContentAsString();

            if ((s == null) || (s.Length == 0))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(XmlObjectSerializer.TryAddLineInfo(this, System.Runtime.Serialization.SR.GetString("XmlInvalidConversion", new object[] { s, "UInt64" }))));
            }
            try
            {
                num = ulong.Parse(s, NumberStyles.Float, NumberFormatInfo.InvariantInfo);
            }
            catch (ArgumentException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(s, "UInt64", exception));
            }
            catch (FormatException exception2)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(s, "UInt64", exception2));
            }
            catch (OverflowException exception3)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(s, "UInt64", exception3));
            }
            return(num);
        }
Example #7
0
        public Guid ReadElementContentAsGuid()
        {
            Guid guid;

            if (this.isEndOfEmptyElement)
            {
                this.ThrowNotAtElement();
            }
            string input = this.reader.ReadElementContentAsString();

            try
            {
                guid = Guid.Parse(input);
            }
            catch (ArgumentException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(input, "Guid", exception));
            }
            catch (FormatException exception2)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(input, "Guid", exception2));
            }
            catch (OverflowException exception3)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(input, "Guid", exception3));
            }
            return(guid);
        }
Example #8
0
 public static DateTime ToDateTime(long value)
 {
     try
     {
         return(DateTime.FromBinary(value));
     }
     catch (ArgumentException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(ToString(value), "DateTime", exception));
     }
 }
Example #9
0
 public static UniqueId ToUniqueId(string value)
 {
     try
     {
         return(new UniqueId(Trim(value)));
     }
     catch (ArgumentException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "UniqueId", exception));
     }
     catch (FormatException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "UniqueId", exception));
     }
 }
Example #10
0
 public static DateTime ToDateTime(string value)
 {
     try
     {
         return(XmlConvert.ToDateTime(value, XmlDateTimeSerializationMode.RoundtripKind));
     }
     catch (ArgumentException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "DateTime", exception));
     }
     catch (FormatException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "DateTime", exception));
     }
 }
Example #11
0
 public static bool ToBoolean(string value)
 {
     try
     {
         return(XmlConvert.ToBoolean(value));
     }
     catch (ArgumentException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Boolean", exception));
     }
     catch (FormatException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Boolean", exception));
     }
 }
Example #12
0
 internal Uri ReadContentAsUri()
 {
     string str = ReadContentAsString();
     try
     {
         return new Uri(str, UriKind.RelativeOrAbsolute);
     }
     catch (ArgumentException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Uri", exception));
     }
     catch (FormatException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Uri", exception));
     }
 }
        public static DateTimeOffset GetDateTimeOffset(DateTimeOffsetAdapter value)
        {
            DateTimeOffset offset2;

            try
            {
                if (value.UtcDateTime.Kind == DateTimeKind.Unspecified)
                {
                    return(new DateTimeOffset(value.UtcDateTime, new TimeSpan(0, value.OffsetMinutes, 0)));
                }
                offset2 = new DateTimeOffset(value.UtcDateTime).ToOffset(new TimeSpan(0, value.OffsetMinutes, 0));
            }
            catch (ArgumentException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "DateTimeOffset", exception));
            }
            return(offset2);
        }
Example #14
0
 public static int ToInt32(string value)
 {
     try
     {
         return(XmlConvert.ToInt32(value));
     }
     catch (ArgumentException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Int32", exception));
     }
     catch (FormatException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Int32", exception));
     }
     catch (OverflowException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Int32", exception));
     }
 }
Example #15
0
 public static ulong ToUInt64(string value)
 {
     try
     {
         return(ulong.Parse(value, NumberFormatInfo.InvariantInfo));
     }
     catch (ArgumentException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "UInt64", exception));
     }
     catch (FormatException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "UInt64", exception));
     }
     catch (OverflowException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "UInt64", exception));
     }
 }
Example #16
0
 public static Guid ToGuid(string value)
 {
     try
     {
         return(Guid.Parse(Trim(value)));
     }
     catch (FormatException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Guid", exception));
     }
     catch (ArgumentException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Guid", exception));
     }
     catch (OverflowException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Guid", exception));
     }
 }
Example #17
0
        internal Uri ReadContentAsUri()
        {
            Uri    uri;
            string uriString = this.ReadContentAsString();

            try
            {
                uri = new Uri(uriString, UriKind.RelativeOrAbsolute);
            }
            catch (ArgumentException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(uriString, "Uri", exception));
            }
            catch (FormatException exception2)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(uriString, "Uri", exception2));
            }
            return(uri);
        }
Example #18
0
 internal Guid ReadContentAsGuid()
 {
     string str = reader.ReadContentAsString();
     try
     {
         return Guid.Parse(str);
     }
     catch (ArgumentException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
     }
     catch (FormatException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
     }
     catch (OverflowException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
     }
 }
        public Uri ReadElementContentAsUri()
        {
            if (_isEndOfEmptyElement)
            {
                ThrowNotAtElement();
            }

            string str = ReadElementContentAsString();

            try
            {
                return(new Uri(str, UriKind.RelativeOrAbsolute));
            }
            catch (ArgumentException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Uri", exception));
            }
            catch (FormatException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Uri", exception));
            }
        }
Example #20
0
        internal Guid ReadContentAsGuid()
        {
            Guid   guid;
            string input = this.reader.ReadContentAsString();

            try
            {
                guid = Guid.Parse(input);
            }
            catch (ArgumentException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(input, "Guid", exception));
            }
            catch (FormatException exception2)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(input, "Guid", exception2));
            }
            catch (OverflowException exception3)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(input, "Guid", exception3));
            }
            return(guid);
        }
Example #21
0
        public static DateTimeOffset GetDateTimeOffset(DateTimeOffsetAdapter value)
        {
            try
            {
                switch (value.UtcDateTime.Kind)
                {
                case DateTimeKind.Unspecified:
                    return(new DateTimeOffset(value.UtcDateTime, new TimeSpan(0, value.OffsetMinutes, 0)));

                //DateTimeKind.Utc and DateTimeKind.Local
                //Read in deserialized DateTime portion of the DateTimeOffsetAdapter and convert DateTimeKind to Unspecified.
                //Apply ofset information read from OffsetMinutes portion of the DateTimeOffsetAdapter.
                //Return converted DateTimeoffset object.
                default:
                    DateTimeOffset deserialized = new DateTimeOffset(value.UtcDateTime);
                    return(deserialized.ToOffset(new TimeSpan(0, value.OffsetMinutes, 0)));
                }
            }
            catch (ArgumentException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "DateTimeOffset", exception));
            }
        }
Example #22
0
        public Uri ReadElementContentAsUri()
        {
            Uri uri;

            if (this.isEndOfEmptyElement)
            {
                this.ThrowNotAtElement();
            }
            string uriString = this.ReadElementContentAsString();

            try
            {
                uri = new Uri(uriString, UriKind.RelativeOrAbsolute);
            }
            catch (ArgumentException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(uriString, "Uri", exception));
            }
            catch (FormatException exception2)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(uriString, "Uri", exception2));
            }
            return(uri);
        }
Example #23
0
        internal static DateTime ParseJsonDateInDefaultFormat(string originalDateTimeValue)
        {
            // Dates are represented in JSON as "\/Date(number of ticks)\/".
            // The number of ticks is the number of milliseconds since January 1, 1970.

            string dateTimeValue;

            if (!string.IsNullOrEmpty(originalDateTimeValue))
            {
                dateTimeValue = originalDateTimeValue.Trim();
            }
            else
            {
                dateTimeValue = originalDateTimeValue;
            }

            if (string.IsNullOrEmpty(dateTimeValue) ||
                !dateTimeValue.StartsWith(JsonGlobals.DateTimeStartGuardReader, StringComparison.Ordinal) ||
                !dateTimeValue.EndsWith(JsonGlobals.DateTimeEndGuardReader, StringComparison.Ordinal))
            {
                throw new FormatException(SR.Format(SR.JsonInvalidDateTimeString, originalDateTimeValue, JsonGlobals.DateTimeStartGuardWriter, JsonGlobals.DateTimeEndGuardWriter));
            }

            string       ticksvalue = dateTimeValue.Substring(6, dateTimeValue.Length - 8);
            long         millisecondsSinceUnixEpoch;
            DateTimeKind dateTimeKind          = DateTimeKind.Utc;
            int          indexOfTimeZoneOffset = ticksvalue.IndexOf('+', 1);

            if (indexOfTimeZoneOffset == -1)
            {
                indexOfTimeZoneOffset = ticksvalue.IndexOf('-', 1);
            }

            if (indexOfTimeZoneOffset != -1)
            {
                dateTimeKind = DateTimeKind.Local;
                ticksvalue   = ticksvalue.Substring(0, indexOfTimeZoneOffset);
            }

            try
            {
                millisecondsSinceUnixEpoch = Int64.Parse(ticksvalue, CultureInfo.InvariantCulture);
            }
            catch (ArgumentException exception)
            {
                throw XmlExceptionHelper.CreateConversionException(ticksvalue, "Int64", exception);
            }
            catch (FormatException exception)
            {
                throw XmlExceptionHelper.CreateConversionException(ticksvalue, "Int64", exception);
            }
            catch (OverflowException exception)
            {
                throw XmlExceptionHelper.CreateConversionException(ticksvalue, "Int64", exception);
            }

            // Convert from # millseconds since epoch to # of 100-nanosecond units, which is what DateTime understands
            long ticks = millisecondsSinceUnixEpoch * 10000 + JsonGlobals.unixEpochTicks;

            try
            {
                DateTime dateTime = new DateTime(ticks, DateTimeKind.Utc);
                switch (dateTimeKind)
                {
                case DateTimeKind.Local:
                    return(dateTime.ToLocalTime());

                case DateTimeKind.Unspecified:
                    return(DateTime.SpecifyKind(dateTime.ToLocalTime(), DateTimeKind.Unspecified));

                case DateTimeKind.Utc:
                default:
                    return(dateTime);
                }
            }
            catch (ArgumentException exception)
            {
                throw XmlExceptionHelper.CreateConversionException(ticksvalue, "DateTime", exception);
            }
        }
        internal static DateTime ParseJsonDate(string originalDateTimeValue)
        {
            string   str;
            long     num;
            DateTime time2;

            if (!string.IsNullOrEmpty(originalDateTimeValue))
            {
                str = originalDateTimeValue.Trim();
            }
            else
            {
                str = originalDateTimeValue;
            }
            if ((string.IsNullOrEmpty(str) || !str.StartsWith("/Date(", StringComparison.Ordinal)) || !str.EndsWith(")/", StringComparison.Ordinal))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(System.Runtime.Serialization.SR.GetString("JsonInvalidDateTimeString", new object[] { originalDateTimeValue, @"\/Date(", @")\/" })));
            }
            string       s     = str.Substring(6, str.Length - 8);
            DateTimeKind utc   = DateTimeKind.Utc;
            int          index = s.IndexOf('+', 1);

            if (index == -1)
            {
                index = s.IndexOf('-', 1);
            }
            if (index != -1)
            {
                utc = DateTimeKind.Local;
                s   = s.Substring(0, index);
            }
            try
            {
                num = long.Parse(s, CultureInfo.InvariantCulture);
            }
            catch (ArgumentException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(s, "Int64", exception));
            }
            catch (FormatException exception2)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(s, "Int64", exception2));
            }
            catch (OverflowException exception3)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(s, "Int64", exception3));
            }
            long ticks = (num * 0x2710L) + JsonGlobals.unixEpochTicks;

            try
            {
                DateTime time = new DateTime(ticks, DateTimeKind.Utc);
                switch (utc)
                {
                case DateTimeKind.Unspecified:
                    return(DateTime.SpecifyKind(time.ToLocalTime(), DateTimeKind.Unspecified));

                case DateTimeKind.Local:
                    return(time.ToLocalTime());
                }
                time2 = time;
            }
            catch (ArgumentException exception4)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(s, "DateTime", exception4));
            }
            return(time2);
        }
        private object DeserializeStringIntoDateTime()
        {
            string       dateTimeValue = DeserializeString();
            string       ticksvalue    = dateTimeValue.Substring(6, dateTimeValue.Length - 8);
            long         millisecondsSinceUnixEpoch;
            DateTimeKind dateTimeKind          = DateTimeKind.Utc;
            int          indexOfTimeZoneOffset = ticksvalue.IndexOf('+', 1);

            if (indexOfTimeZoneOffset == -1)
            {
                indexOfTimeZoneOffset = ticksvalue.IndexOf('-', 1);
            }

            if (indexOfTimeZoneOffset != -1)
            {
                dateTimeKind = DateTimeKind.Local;
                ticksvalue   = ticksvalue.Substring(0, indexOfTimeZoneOffset);
            }

            try
            {
                millisecondsSinceUnixEpoch = Int64.Parse(ticksvalue, NumberStyles.Integer, CultureInfo.InvariantCulture);
            }
            catch (ArgumentException exception)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(ticksvalue, "Int64", exception));
            }
            catch (FormatException exception)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(ticksvalue, "Int64", exception));
            }
            catch (OverflowException exception)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(ticksvalue, "Int64", exception));
            }

            // Convert from # millseconds since epoch to # of 100-nanosecond units, which is what DateTime understands
            long ticks = millisecondsSinceUnixEpoch * 10000 + JsonGlobals.unixEpochTicks;

            try
            {
                DateTime dateTime = new DateTime(ticks, DateTimeKind.Utc);
                switch (dateTimeKind)
                {
                case DateTimeKind.Local:
                    dateTime = dateTime.ToLocalTime();
                    break;

                case DateTimeKind.Unspecified:
                    dateTime = DateTime.SpecifyKind(dateTime.ToLocalTime(), DateTimeKind.Unspecified);
                    break;

                case DateTimeKind.Utc:
                default:
                    break;
                }

                // This string could be serialized from DateTime or String, keeping both until DataContract information is available
                return(Tuple.Create <DateTime, string>(dateTime, dateTimeValue));
            }
            catch (ArgumentException exception)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(ticksvalue, "DateTime", exception));
            }
        }