Exemplo n.º 1
0
    public override unsafe string ToString()
    {
        if (HasNamespace == false)
        {
            return(_name.ToString());
        }
        var utf8      = Encoding.UTF8;
        var nsCharLen = utf8.GetCharCount((byte *)_namespaceName.Ptr, _namespaceName.Length);
        var nCharLen  = utf8.GetCharCount((byte *)_name.Ptr, _name.Length);
        var charLen   = nsCharLen + nCharLen + 1;

        var state = (Self : this, NsCharLen : nsCharLen, NCharLen : nCharLen);

        var str    = new string('\0', charLen);
        var nsName = state.Self.NamespaceName;
        var name   = state.Self.Name;

        fixed(char *buf = str)
        {
            utf8.GetChars((byte *)nsName.Ptr, nsName.Length, buf, state.NsCharLen);
            utf8.GetChars((byte *)name.Ptr, name.Length, buf + nsName.Length + 1, state.NCharLen);
            buf[nsName.Length] = '.';
        }

        return(str);
    }