KeePassLib.Serialization.Kdb4File.WriteObject C# (CSharp) Метод

WriteObject() приватный Метод

private WriteObject ( string name, ProtectedString value, bool bIsEntryString ) : void
name string
value ProtectedString
bIsEntryString bool
Результат void
        private void WriteObject(string name, ProtectedString value, bool bIsEntryString)
        {
            Debug.Assert(name != null);
            Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value");

            m_xmlWriter.WriteStartElement(ElemString);
            m_xmlWriter.WriteStartElement(ElemKey);
            m_xmlWriter.WriteString(StrUtil.SafeXmlString(name));
            m_xmlWriter.WriteEndElement();
            m_xmlWriter.WriteStartElement(ElemValue);

            if(bIsEntryString)
            {
                if(name == PwDefs.TitleField)
                    value.EnableProtection(m_pwDatabase.MemoryProtection.ProtectTitle);
                else if(name == PwDefs.UserNameField)
                    value.EnableProtection(m_pwDatabase.MemoryProtection.ProtectUserName);
                else if(name == PwDefs.PasswordField)
                    value.EnableProtection(m_pwDatabase.MemoryProtection.ProtectPassword);
                else if(name == PwDefs.UrlField)
                    value.EnableProtection(m_pwDatabase.MemoryProtection.ProtectUrl);
                else if(name == PwDefs.NotesField)
                    value.EnableProtection(m_pwDatabase.MemoryProtection.ProtectNotes);
            }

            if(value.IsProtected && (m_format != Kdb4Format.PlainXml))
            {
                m_xmlWriter.WriteAttributeString(AttrProtected, ValTrue);

                byte[] pbEncoded = value.ReadXorredString(m_randomStream);
                if(pbEncoded.Length > 0)
                    m_xmlWriter.WriteBase64(pbEncoded, 0, pbEncoded.Length);
            }
            else
            {
                string strValue = value.ReadString();

                // If names should be localized, we need to apply the language-dependent
                // string transformation here. By default, language-dependent conversions
                // should be applied, otherwise characters could be rendered incorrectly
                // (code page problems).
                if(m_bLocalizedNames)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach(char ch in strValue)
                    {
                        char chMapped = ch;

                        // Symbols and surrogates must be moved into the correct code
                        // page area
                        if(char.IsSymbol(ch) || char.IsSurrogate(ch))
                        {
                            System.Globalization.UnicodeCategory cat = char.GetUnicodeCategory(ch);
                            // Map character to correct position in code page
                            chMapped = (char)((int)cat * 32 + ch);
                        }
                        else if(char.IsControl(ch))
                        {
                            if(ch >= 256) // Control character in high ANSI code page
                            {
                                // Some of the control characters map to corresponding ones
                                // in the low ANSI range (up to 255) when calling
                                // ToLower on them with invariant culture (see
                                // http://lists.ximian.com/pipermail/mono-patches/2002-February/086106.html )
                                chMapped = char.ToLower(ch, CultureInfo.InvariantCulture);
                            }
                        }

                        sb.Append(chMapped);
                    }

                    strValue = sb.ToString(); // Correct string for current code page
                }

                m_xmlWriter.WriteString(StrUtil.SafeXmlString(strValue));
            }

            m_xmlWriter.WriteEndElement(); // ElemValue
            m_xmlWriter.WriteEndElement(); // ElemString
        }

Same methods

Kdb4File::WriteObject ( string name, DateTime value ) : void
Kdb4File::WriteObject ( string name, ProtectedBinary value, bool bAllowRef ) : void
Kdb4File::WriteObject ( string name, PwDeletedObject value ) : void
Kdb4File::WriteObject ( string name, PwUuid value ) : void
Kdb4File::WriteObject ( string name, bool value ) : void
Kdb4File::WriteObject ( string name, int value ) : void
Kdb4File::WriteObject ( string name, long value ) : void
Kdb4File::WriteObject ( string name, string value, bool bFilterValueXmlChars ) : void
Kdb4File::WriteObject ( string name, string strKeyName, string strValueName, string>.KeyValuePair kvp ) : void
Kdb4File::WriteObject ( string name, uint value ) : void
Kdb4File::WriteObject ( string name, ulong value ) : void