ToString() static public method

static public ToString ( System.DateTime value ) : string
value System.DateTime
return string
        public override void WriteUniqueIdText(UniqueId value)
        {
            string str = XmlConverter.ToString(value);

            if (this.text)
            {
                this.writer.WriteText(str);
            }
            else
            {
                this.writer.WriteUniqueIdText(value);
            }
            this.signingWriter.WriteText(str);
        }
Esempio n. 2
0
        public override void WriteGuidText(Guid value)
        {
            string s = XmlConverter.ToString(value);

            if (_text)
            {
                _writer.WriteText(s);
            }
            else
            {
                _writer.WriteGuidText(value);
            }
            _signingWriter.WriteText(s);
        }
        public override void WriteTimeSpanText(TimeSpan value)
        {
            string str = XmlConverter.ToString(value);

            if (this.text)
            {
                this.writer.WriteText(str);
            }
            else
            {
                this.writer.WriteTimeSpanText(value);
            }
            this.signingWriter.WriteText(str);
        }
        public override void WriteTimeSpanText(TimeSpan value)
        {
            string s = XmlConverter.ToString(value);

            if (text)
            {
                writer.WriteText(s);
            }
            else
            {
                writer.WriteTimeSpanText(value);
            }
            signingWriter.WriteText(s);
        }
        public override void WriteUniqueIdText(UniqueId value)
        {
            string s = XmlConverter.ToString(value);

            if (text)
            {
                writer.WriteText(s);
            }
            else
            {
                writer.WriteUniqueIdText(value);
            }
            signingWriter.WriteText(s);
        }
Esempio n. 6
0
        public string GetString()
        {
            ValueHandleType type = _type;

            if (type == ValueHandleType.UTF8)
            {
                return(GetCharsText());
            }

            switch (type)
            {
            case ValueHandleType.False:
                return("false");

            case ValueHandleType.True:
                return("true");

            case ValueHandleType.Zero:
                return("0");

            case ValueHandleType.One:
                return("1");

            case ValueHandleType.Int8:
            case ValueHandleType.Int16:
            case ValueHandleType.Int32:
                return(XmlConverter.ToString(ToInt()));

            case ValueHandleType.Int64:
                return(XmlConverter.ToString(GetInt64()));

            case ValueHandleType.UInt64:
                return(XmlConverter.ToString(GetUInt64()));

            case ValueHandleType.Single:
                return(XmlConverter.ToString(GetSingle()));

            case ValueHandleType.Double:
                return(XmlConverter.ToString(GetDouble()));

            case ValueHandleType.Decimal:
                return(XmlConverter.ToString(GetDecimal()));

            case ValueHandleType.DateTime:
                return(XmlConverter.ToString(ToDateTime()));

            case ValueHandleType.Empty:
                return(string.Empty);

            case ValueHandleType.Unicode:
                return(GetUnicodeCharsText());

            case ValueHandleType.EscapedUTF8:
                return(GetEscapedCharsText());

            case ValueHandleType.Char:
                return(GetCharText());

            case ValueHandleType.Dictionary:
                return(GetDictionaryString().Value);

            case ValueHandleType.Base64:
                byte[] bytes = ToByteArray();
                DiagnosticUtility.DebugAssert(bytes != null, "");
                return(Base64Encoding.GetString(bytes, 0, bytes.Length));

            case ValueHandleType.List:
                return(XmlConverter.ToString(ToList()));

            case ValueHandleType.UniqueId:
                return(XmlConverter.ToString(ToUniqueId()));

            case ValueHandleType.Guid:
                return(XmlConverter.ToString(ToGuid()));

            case ValueHandleType.TimeSpan:
                return(XmlConverter.ToString(ToTimeSpan()));

            case ValueHandleType.QName:
                return(GetQNameDictionaryText());

            case ValueHandleType.ConstString:
                return(s_constStrings[_offset]);

            default:
                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException());
            }
        }
Esempio n. 7
0
        public unsafe bool Equals2(int offset1, int length1, string s2)
        {
            int byteLength = length1;
            int charLength = s2.Length;

            // N Unicode chars will be represented in at least N bytes, but
            // no more than N * 3 bytes.  If the byte count falls outside of this
            // range, then the strings cannot be equal.
            if (byteLength < charLength || byteLength > charLength * maxBytesPerChar)
            {
                return(false);
            }

            byte[] buffer = _buffer;
            if (length1 < 8)
            {
                int length = Math.Min(byteLength, charLength);
                int offset = offset1;
                for (int i = 0; i < length; i++)
                {
                    byte b = buffer[offset + i];
                    if (b >= 0x80)
                    {
                        return(XmlConverter.ToString(buffer, offset1, length1) == s2);
                    }
                    if (s2[i] != (char)b)
                    {
                        return(false);
                    }
                }
                return(byteLength == charLength);
            }
            else
            {
                int length = Math.Min(byteLength, charLength);
                fixed(byte *_pb = &buffer[offset1])
                {
                    byte *pb    = _pb;
                    byte *pbMax = pb + length;

                    fixed(char *_pch = s2)
                    {
                        char *pch = _pch;
                        // Try to do the fast comparison in ASCII space
                        int t = 0;

                        while (pb < pbMax && *pb < 0x80)
                        {
                            t = *pb - (byte)*pch;
                            // The code generated is better if we break out then return
                            if (t != 0)
                            {
                                break;
                            }
                            pb++;
                            pch++;
                        }
                        if (t != 0)
                        {
                            return(false);
                        }
                        if (pb == pbMax)
                        {
                            return(byteLength == charLength);
                        }
                    }
                }

                return(XmlConverter.ToString(buffer, offset1, length1) == s2);
            }
        }
        public unsafe bool Equals2(int offset1, int length1, string s2)
        {
            int num    = length1;
            int length = s2.Length;

            if ((num < length) || (num > (length * 3)))
            {
                return(false);
            }
            byte[] buffer = this.buffer;
            if (length1 < 8)
            {
                int num3 = Math.Min(num, length);
                int num4 = offset1;
                for (int i = 0; i < num3; i++)
                {
                    byte num6 = buffer[num4 + i];
                    if (num6 >= 0x80)
                    {
                        return(XmlConverter.ToString(buffer, offset1, length1) == s2);
                    }
                    if (s2[i] != num6)
                    {
                        return(false);
                    }
                }
                return(num == length);
            }
            int num7 = Math.Min(num, length);

            fixed(byte *numRef = &(buffer[offset1]))
            {
                byte *numPtr  = numRef;
                byte *numPtr2 = numPtr + num7;

                fixed(char *str = ((char *)s2))
                {
                    char *chPtr2 = str;
                    int   num8   = 0;

                    while ((numPtr < numPtr2) && (numPtr[0] < 0x80))
                    {
                        num8 = numPtr[0] - ((byte)chPtr2[0]);
                        if (num8 != 0)
                        {
                            break;
                        }
                        numPtr++;
                        chPtr2++;
                    }
                    if (num8 != 0)
                    {
                        return(false);
                    }
                    if (numPtr == numPtr2)
                    {
                        return(num == length);
                    }
                }
            }

            return(XmlConverter.ToString(buffer, offset1, length1) == s2);
        }
Esempio n. 9
0
        public string GetString()
        {
            ValueHandleType type = this.type;

            if (type == ValueHandleType.UTF8)
            {
                return(this.GetCharsText());
            }
            switch (type)
            {
            case ValueHandleType.Empty:
                return(string.Empty);

            case ValueHandleType.True:
                return("true");

            case ValueHandleType.False:
                return("false");

            case ValueHandleType.Zero:
                return("0");

            case ValueHandleType.One:
                return("1");

            case ValueHandleType.Int8:
            case ValueHandleType.Int16:
            case ValueHandleType.Int32:
                return(XmlConverter.ToString(this.ToInt()));

            case ValueHandleType.Int64:
                return(XmlConverter.ToString(this.GetInt64()));

            case ValueHandleType.UInt64:
                return(XmlConverter.ToString(this.GetUInt64()));

            case ValueHandleType.Single:
                return(XmlConverter.ToString(this.GetSingle()));

            case ValueHandleType.Double:
                return(XmlConverter.ToString(this.GetDouble()));

            case ValueHandleType.Decimal:
                return(XmlConverter.ToString(this.GetDecimal()));

            case ValueHandleType.DateTime:
                return(XmlConverter.ToString(this.ToDateTime()));

            case ValueHandleType.TimeSpan:
                return(XmlConverter.ToString(this.ToTimeSpan()));

            case ValueHandleType.Guid:
                return(XmlConverter.ToString(this.ToGuid()));

            case ValueHandleType.UniqueId:
                return(XmlConverter.ToString(this.ToUniqueId()));

            case ValueHandleType.UTF8:
                return(this.GetCharsText());

            case ValueHandleType.EscapedUTF8:
                return(this.GetEscapedCharsText());

            case ValueHandleType.Base64:
                return(Base64Encoding.GetString(this.ToByteArray()));

            case ValueHandleType.Dictionary:
                return(this.GetDictionaryString().Value);

            case ValueHandleType.List:
                return(XmlConverter.ToString(this.ToList()));

            case ValueHandleType.Char:
                return(this.GetCharText());

            case ValueHandleType.Unicode:
                return(this.GetUnicodeCharsText());

            case ValueHandleType.QName:
                return(this.GetQNameDictionaryText());

            case ValueHandleType.ConstString:
                return(constStrings[this.offset]);
            }
            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException());
        }