mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
KeePassLib finally portable (but version 2.19)
Windows Store project stub
This commit is contained in:
220
ModernKeePassLib/Collections/AutoTypeConfig.cs
Normal file
220
ModernKeePassLib/Collections/AutoTypeConfig.cs
Normal file
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
using ModernKeePassLib.Interfaces;
|
||||
|
||||
namespace ModernKeePassLib.Collections
|
||||
{
|
||||
[Flags]
|
||||
public enum AutoTypeObfuscationOptions
|
||||
{
|
||||
None = 0,
|
||||
UseClipboard = 1
|
||||
}
|
||||
|
||||
public sealed class AutoTypeAssociation : IEquatable<AutoTypeAssociation>,
|
||||
IDeepCloneable<AutoTypeAssociation>
|
||||
{
|
||||
private string m_strWindow = string.Empty;
|
||||
public string WindowName
|
||||
{
|
||||
get { return m_strWindow; }
|
||||
set
|
||||
{
|
||||
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value");
|
||||
m_strWindow = value;
|
||||
}
|
||||
}
|
||||
|
||||
private string m_strSequence = string.Empty;
|
||||
public string Sequence
|
||||
{
|
||||
get { return m_strSequence; }
|
||||
set
|
||||
{
|
||||
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value");
|
||||
m_strSequence = value;
|
||||
}
|
||||
}
|
||||
|
||||
public AutoTypeAssociation() { }
|
||||
|
||||
public AutoTypeAssociation(string strWindow, string strSeq)
|
||||
{
|
||||
if(strWindow == null) throw new ArgumentNullException("strWindow");
|
||||
if(strSeq == null) throw new ArgumentNullException("strSeq");
|
||||
|
||||
m_strWindow = strWindow;
|
||||
m_strSequence = strSeq;
|
||||
}
|
||||
|
||||
public bool Equals(AutoTypeAssociation other)
|
||||
{
|
||||
if(other == null) return false;
|
||||
|
||||
if(m_strWindow != other.m_strWindow) return false;
|
||||
if(m_strSequence != other.m_strSequence) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public AutoTypeAssociation CloneDeep()
|
||||
{
|
||||
return (AutoTypeAssociation)this.MemberwiseClone();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A list of auto-type associations.
|
||||
/// </summary>
|
||||
public sealed class AutoTypeConfig : IEquatable<AutoTypeConfig>,
|
||||
IDeepCloneable<AutoTypeConfig>
|
||||
{
|
||||
private bool m_bEnabled = true;
|
||||
private AutoTypeObfuscationOptions m_atooObfuscation =
|
||||
AutoTypeObfuscationOptions.None;
|
||||
private string m_strDefaultSequence = string.Empty;
|
||||
private List<AutoTypeAssociation> m_lWindowAssocs =
|
||||
new List<AutoTypeAssociation>();
|
||||
|
||||
/// <summary>
|
||||
/// Specify whether auto-type is enabled or not.
|
||||
/// </summary>
|
||||
public bool Enabled
|
||||
{
|
||||
get { return m_bEnabled; }
|
||||
set { m_bEnabled = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specify whether the typing should be obfuscated.
|
||||
/// </summary>
|
||||
public AutoTypeObfuscationOptions ObfuscationOptions
|
||||
{
|
||||
get { return m_atooObfuscation; }
|
||||
set { m_atooObfuscation = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The default keystroke sequence that is auto-typed if
|
||||
/// no matching window is found in the <c>Associations</c>
|
||||
/// container.
|
||||
/// </summary>
|
||||
public string DefaultSequence
|
||||
{
|
||||
get { return m_strDefaultSequence; }
|
||||
set
|
||||
{
|
||||
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value");
|
||||
m_strDefaultSequence = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all auto-type window/keystroke sequence pairs.
|
||||
/// </summary>
|
||||
public IEnumerable<AutoTypeAssociation> Associations
|
||||
{
|
||||
get { return m_lWindowAssocs; }
|
||||
}
|
||||
|
||||
public int AssociationsCount
|
||||
{
|
||||
get { return m_lWindowAssocs.Count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Construct a new auto-type associations list.
|
||||
/// </summary>
|
||||
public AutoTypeConfig()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all associations.
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
m_lWindowAssocs.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clone the auto-type associations list.
|
||||
/// </summary>
|
||||
/// <returns>New, cloned object.</returns>
|
||||
public AutoTypeConfig CloneDeep()
|
||||
{
|
||||
AutoTypeConfig newCfg = new AutoTypeConfig();
|
||||
|
||||
newCfg.m_bEnabled = m_bEnabled;
|
||||
newCfg.m_atooObfuscation = m_atooObfuscation;
|
||||
newCfg.m_strDefaultSequence = m_strDefaultSequence;
|
||||
|
||||
foreach(AutoTypeAssociation a in m_lWindowAssocs)
|
||||
newCfg.Add(a.CloneDeep());
|
||||
|
||||
return newCfg;
|
||||
}
|
||||
|
||||
public bool Equals(AutoTypeConfig other)
|
||||
{
|
||||
if(other == null) { Debug.Assert(false); return false; }
|
||||
|
||||
if(m_bEnabled != other.m_bEnabled) return false;
|
||||
if(m_atooObfuscation != other.m_atooObfuscation) return false;
|
||||
if(m_strDefaultSequence != other.m_strDefaultSequence) return false;
|
||||
|
||||
if(m_lWindowAssocs.Count != other.m_lWindowAssocs.Count) return false;
|
||||
for(int i = 0; i < m_lWindowAssocs.Count; ++i)
|
||||
{
|
||||
if(!m_lWindowAssocs[i].Equals(other.m_lWindowAssocs[i]))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Add(AutoTypeAssociation a)
|
||||
{
|
||||
Debug.Assert(a != null); if(a == null) throw new ArgumentNullException("a");
|
||||
|
||||
m_lWindowAssocs.Add(a);
|
||||
}
|
||||
|
||||
public AutoTypeAssociation GetAt(int iIndex)
|
||||
{
|
||||
if((iIndex < 0) || (iIndex >= m_lWindowAssocs.Count))
|
||||
throw new ArgumentOutOfRangeException("iIndex");
|
||||
|
||||
return m_lWindowAssocs[iIndex];
|
||||
}
|
||||
|
||||
public void RemoveAt(int iIndex)
|
||||
{
|
||||
if((iIndex < 0) || (iIndex >= m_lWindowAssocs.Count))
|
||||
throw new ArgumentOutOfRangeException("iIndex");
|
||||
|
||||
m_lWindowAssocs.RemoveAt(iIndex);
|
||||
}
|
||||
}
|
||||
}
|
173
ModernKeePassLib/Collections/ProtectedBinaryDictionary.cs
Normal file
173
ModernKeePassLib/Collections/ProtectedBinaryDictionary.cs
Normal file
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
|
||||
using ModernKeePassLib.Interfaces;
|
||||
using ModernKeePassLib.Security;
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
#if KeePassLibSD
|
||||
using ModernKeePassLibSD;
|
||||
#endif
|
||||
|
||||
namespace ModernKeePassLib.Collections
|
||||
{
|
||||
/// <summary>
|
||||
/// A list of <c>ProtectedBinary</c> objects (dictionary).
|
||||
/// </summary>
|
||||
public sealed class ProtectedBinaryDictionary :
|
||||
IDeepCloneable<ProtectedBinaryDictionary>,
|
||||
IEnumerable<KeyValuePair<string, ProtectedBinary>>
|
||||
{
|
||||
private SortedDictionary<string, ProtectedBinary> m_vBinaries =
|
||||
new SortedDictionary<string, ProtectedBinary>();
|
||||
|
||||
/// <summary>
|
||||
/// Get the number of binaries in this entry.
|
||||
/// </summary>
|
||||
public uint UCount
|
||||
{
|
||||
get { return (uint)m_vBinaries.Count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Construct a new list of protected binaries.
|
||||
/// </summary>
|
||||
public ProtectedBinaryDictionary()
|
||||
{
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return m_vBinaries.GetEnumerator();
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<string, ProtectedBinary>> GetEnumerator()
|
||||
{
|
||||
return m_vBinaries.GetEnumerator();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
m_vBinaries.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clone the current <c>ProtectedBinaryList</c> object, including all
|
||||
/// stored protected strings.
|
||||
/// </summary>
|
||||
/// <returns>New <c>ProtectedBinaryList</c> object.</returns>
|
||||
public ProtectedBinaryDictionary CloneDeep()
|
||||
{
|
||||
ProtectedBinaryDictionary plNew = new ProtectedBinaryDictionary();
|
||||
|
||||
foreach(KeyValuePair<string, ProtectedBinary> kvpBin in m_vBinaries)
|
||||
{
|
||||
// ProtectedBinary objects are immutable
|
||||
plNew.Set(kvpBin.Key, kvpBin.Value);
|
||||
}
|
||||
|
||||
return plNew;
|
||||
}
|
||||
|
||||
public bool EqualsDictionary(ProtectedBinaryDictionary dict)
|
||||
{
|
||||
if(dict == null) { Debug.Assert(false); return false; }
|
||||
|
||||
if(m_vBinaries.Count != dict.m_vBinaries.Count) return false;
|
||||
|
||||
foreach(KeyValuePair<string, ProtectedBinary> kvp in m_vBinaries)
|
||||
{
|
||||
ProtectedBinary pb = dict.Get(kvp.Key);
|
||||
if(pb == null) return false;
|
||||
if(!pb.Equals(kvp.Value)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get one of the stored binaries.
|
||||
/// </summary>
|
||||
/// <param name="strName">Binary identifier.</param>
|
||||
/// <returns>Protected binary. If the binary identified by
|
||||
/// <paramref name="strName" /> cannot be found, the function
|
||||
/// returns <c>null</c>.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">Thrown if the input
|
||||
/// parameter is <c>null</c>.</exception>
|
||||
public ProtectedBinary Get(string strName)
|
||||
{
|
||||
Debug.Assert(strName != null); if(strName == null) throw new ArgumentNullException("strName");
|
||||
|
||||
ProtectedBinary pb;
|
||||
if(m_vBinaries.TryGetValue(strName, out pb)) return pb;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a binary object.
|
||||
/// </summary>
|
||||
/// <param name="strField">Identifier of the binary field to modify.</param>
|
||||
/// <param name="pbNewValue">New value. This parameter must not be <c>null</c>.</param>
|
||||
/// <exception cref="System.ArgumentNullException">Thrown if any of the input
|
||||
/// parameters is <c>null</c>.</exception>
|
||||
public void Set(string strField, ProtectedBinary pbNewValue)
|
||||
{
|
||||
Debug.Assert(strField != null); if(strField == null) throw new ArgumentNullException("strField");
|
||||
Debug.Assert(pbNewValue != null); if(pbNewValue == null) throw new ArgumentNullException("pbNewValue");
|
||||
|
||||
m_vBinaries[strField] = pbNewValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a binary object.
|
||||
/// </summary>
|
||||
/// <param name="strField">Identifier of the binary field to remove.</param>
|
||||
/// <returns>Returns <c>true</c> if the object has been successfully
|
||||
/// removed, otherwise <c>false</c>.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">Thrown if the input parameter
|
||||
/// is <c>null</c>.</exception>
|
||||
public bool Remove(string strField)
|
||||
{
|
||||
Debug.Assert(strField != null); if(strField == null) throw new ArgumentNullException("strField");
|
||||
|
||||
return m_vBinaries.Remove(strField);
|
||||
}
|
||||
|
||||
public string KeysToString()
|
||||
{
|
||||
if(m_vBinaries.Count == 0) return string.Empty;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach(KeyValuePair<string, ProtectedBinary> kvp in m_vBinaries)
|
||||
{
|
||||
if(sb.Length > 0) sb.Append(", ");
|
||||
sb.Append(kvp.Key);
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
306
ModernKeePassLib/Collections/ProtectedStringDictionary.cs
Normal file
306
ModernKeePassLib/Collections/ProtectedStringDictionary.cs
Normal file
@@ -0,0 +1,306 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
using ModernKeePassLib.Interfaces;
|
||||
using ModernKeePassLib.Security;
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
#if KeePassLibSD
|
||||
using ModernKeePassLibSD;
|
||||
#endif
|
||||
|
||||
namespace ModernKeePassLib.Collections
|
||||
{
|
||||
/// <summary>
|
||||
/// A list of <c>ProtectedString</c> objects (dictionary).
|
||||
/// </summary>
|
||||
public sealed class ProtectedStringDictionary :
|
||||
IDeepCloneable<ProtectedStringDictionary>,
|
||||
IEnumerable<KeyValuePair<string, ProtectedString>>
|
||||
{
|
||||
private SortedDictionary<string, ProtectedString> m_vStrings =
|
||||
new SortedDictionary<string, ProtectedString>();
|
||||
|
||||
/// <summary>
|
||||
/// Get the number of strings in this entry.
|
||||
/// </summary>
|
||||
public uint UCount
|
||||
{
|
||||
get { return (uint)m_vStrings.Count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Construct a new list of protected strings.
|
||||
/// </summary>
|
||||
public ProtectedStringDictionary()
|
||||
{
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return m_vStrings.GetEnumerator();
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<string, ProtectedString>> GetEnumerator()
|
||||
{
|
||||
return m_vStrings.GetEnumerator();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
m_vStrings.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clone the current <c>ProtectedStringList</c> object, including all
|
||||
/// stored protected strings.
|
||||
/// </summary>
|
||||
/// <returns>New <c>ProtectedStringList</c> object.</returns>
|
||||
public ProtectedStringDictionary CloneDeep()
|
||||
{
|
||||
ProtectedStringDictionary plNew = new ProtectedStringDictionary();
|
||||
|
||||
foreach(KeyValuePair<string, ProtectedString> kvpStr in m_vStrings)
|
||||
{
|
||||
// ProtectedString objects are immutable
|
||||
plNew.Set(kvpStr.Key, kvpStr.Value);
|
||||
}
|
||||
|
||||
return plNew;
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public bool EqualsDictionary(ProtectedStringDictionary dict)
|
||||
{
|
||||
return EqualsDictionary(dict, PwCompareOptions.None, MemProtCmpMode.None);
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public bool EqualsDictionary(ProtectedStringDictionary dict,
|
||||
MemProtCmpMode mpCompare)
|
||||
{
|
||||
return EqualsDictionary(dict, PwCompareOptions.None, mpCompare);
|
||||
}
|
||||
|
||||
public bool EqualsDictionary(ProtectedStringDictionary dict,
|
||||
PwCompareOptions pwOpt, MemProtCmpMode mpCompare)
|
||||
{
|
||||
if(dict == null) { Debug.Assert(false); return false; }
|
||||
|
||||
bool bNeEqStd = ((pwOpt & PwCompareOptions.NullEmptyEquivStd) !=
|
||||
PwCompareOptions.None);
|
||||
if(!bNeEqStd)
|
||||
{
|
||||
if(m_vStrings.Count != dict.m_vStrings.Count) return false;
|
||||
}
|
||||
|
||||
foreach(KeyValuePair<string, ProtectedString> kvp in m_vStrings)
|
||||
{
|
||||
bool bStdField = PwDefs.IsStandardField(kvp.Key);
|
||||
ProtectedString ps = dict.Get(kvp.Key);
|
||||
|
||||
if(bNeEqStd && (ps == null) && bStdField)
|
||||
ps = ProtectedString.Empty;
|
||||
|
||||
if(ps == null) return false;
|
||||
|
||||
if(mpCompare == MemProtCmpMode.Full)
|
||||
{
|
||||
if(ps.IsProtected != kvp.Value.IsProtected) return false;
|
||||
}
|
||||
else if(mpCompare == MemProtCmpMode.CustomOnly)
|
||||
{
|
||||
if(!bStdField && (ps.IsProtected != kvp.Value.IsProtected))
|
||||
return false;
|
||||
}
|
||||
|
||||
if(ps.ReadString() != kvp.Value.ReadString()) return false;
|
||||
}
|
||||
|
||||
if(bNeEqStd)
|
||||
{
|
||||
foreach(KeyValuePair<string, ProtectedString> kvp in dict.m_vStrings)
|
||||
{
|
||||
ProtectedString ps = Get(kvp.Key);
|
||||
|
||||
if(ps != null) continue; // Compared previously
|
||||
if(!PwDefs.IsStandardField(kvp.Key)) return false;
|
||||
if(!kvp.Value.IsEmpty) return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get one of the protected strings.
|
||||
/// </summary>
|
||||
/// <param name="strName">String identifier.</param>
|
||||
/// <returns>Protected string. If the string identified by
|
||||
/// <paramref name="strName" /> cannot be found, the function
|
||||
/// returns <c>null</c>.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">Thrown if the input parameter
|
||||
/// is <c>null</c>.</exception>
|
||||
public ProtectedString Get(string strName)
|
||||
{
|
||||
Debug.Assert(strName != null); if(strName == null) throw new ArgumentNullException("strName");
|
||||
|
||||
ProtectedString ps;
|
||||
if(m_vStrings.TryGetValue(strName, out ps)) return ps;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get one of the protected strings. The return value is never <c>null</c>.
|
||||
/// If the requested string cannot be found, an empty protected string
|
||||
/// object is returned.
|
||||
/// </summary>
|
||||
/// <param name="strName">String identifier.</param>
|
||||
/// <returns>Returns a protected string object. If the standard string
|
||||
/// has not been set yet, the return value is an empty string (<c>""</c>).</returns>
|
||||
/// <exception cref="System.ArgumentNullException">Thrown if the input
|
||||
/// parameter is <c>null</c>.</exception>
|
||||
public ProtectedString GetSafe(string strName)
|
||||
{
|
||||
Debug.Assert(strName != null); if(strName == null) throw new ArgumentNullException("strName");
|
||||
|
||||
ProtectedString ps;
|
||||
if(m_vStrings.TryGetValue(strName, out ps)) return ps;
|
||||
|
||||
return ProtectedString.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test if a named string exists.
|
||||
/// </summary>
|
||||
/// <param name="strName">Name of the string to try.</param>
|
||||
/// <returns>Returns <c>true</c> if the string exists, otherwise <c>false</c>.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">Thrown if
|
||||
/// <paramref name="strName" /> is <c>null</c>.</exception>
|
||||
public bool Exists(string strName)
|
||||
{
|
||||
Debug.Assert(strName != null); if(strName == null) throw new ArgumentNullException("strName");
|
||||
|
||||
return m_vStrings.ContainsKey(strName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get one of the protected strings. If the string doesn't exist, the
|
||||
/// return value is an empty string (<c>""</c>).
|
||||
/// </summary>
|
||||
/// <param name="strName">Name of the requested string.</param>
|
||||
/// <returns>Requested string value or an empty string, if the named
|
||||
/// string doesn't exist.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">Thrown if the input
|
||||
/// parameter is <c>null</c>.</exception>
|
||||
public string ReadSafe(string strName)
|
||||
{
|
||||
Debug.Assert(strName != null); if(strName == null) throw new ArgumentNullException("strName");
|
||||
|
||||
ProtectedString ps;
|
||||
if(m_vStrings.TryGetValue(strName, out ps))
|
||||
return ps.ReadString();
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get one of the entry strings. If the string doesn't exist, the
|
||||
/// return value is an empty string (<c>""</c>). If the string is
|
||||
/// in-memory protected, the return value is <c>PwDefs.HiddenPassword</c>.
|
||||
/// </summary>
|
||||
/// <param name="strName">Name of the requested string.</param>
|
||||
/// <returns>Returns the requested string in plain-text or
|
||||
/// <c>PwDefs.HiddenPassword</c> if the string cannot be found.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">Thrown if the input
|
||||
/// parameter is <c>null</c>.</exception>
|
||||
public string ReadSafeEx(string strName)
|
||||
{
|
||||
Debug.Assert(strName != null); if(strName == null) throw new ArgumentNullException("strName");
|
||||
|
||||
ProtectedString ps;
|
||||
if(m_vStrings.TryGetValue(strName, out ps))
|
||||
{
|
||||
if(ps.IsProtected) return PwDefs.HiddenPassword;
|
||||
return ps.ReadString();
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a string.
|
||||
/// </summary>
|
||||
/// <param name="strField">Identifier of the string field to modify.</param>
|
||||
/// <param name="psNewValue">New value. This parameter must not be <c>null</c>.</param>
|
||||
/// <exception cref="System.ArgumentNullException">Thrown if one of the input
|
||||
/// parameters is <c>null</c>.</exception>
|
||||
public void Set(string strField, ProtectedString psNewValue)
|
||||
{
|
||||
Debug.Assert(strField != null); if(strField == null) throw new ArgumentNullException("strField");
|
||||
Debug.Assert(psNewValue != null); if(psNewValue == null) throw new ArgumentNullException("psNewValue");
|
||||
|
||||
m_vStrings[strField] = psNewValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete a string.
|
||||
/// </summary>
|
||||
/// <param name="strField">Name of the string field to delete.</param>
|
||||
/// <returns>Returns <c>true</c> if the field has been successfully
|
||||
/// removed, otherwise the return value is <c>false</c>.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">Thrown if the input
|
||||
/// parameter is <c>null</c>.</exception>
|
||||
public bool Remove(string strField)
|
||||
{
|
||||
Debug.Assert(strField != null); if(strField == null) throw new ArgumentNullException("strField");
|
||||
|
||||
return m_vStrings.Remove(strField);
|
||||
}
|
||||
|
||||
public List<string> GetKeys()
|
||||
{
|
||||
List<string> v = new List<string>();
|
||||
|
||||
foreach(string strKey in m_vStrings.Keys) v.Add(strKey);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public void EnableProtection(string strField, bool bProtect)
|
||||
{
|
||||
ProtectedString ps = Get(strField);
|
||||
if(ps == null) return; // Nothing to do, no assert
|
||||
|
||||
if(ps.IsProtected != bProtect)
|
||||
{
|
||||
byte[] pbData = ps.ReadUtf8();
|
||||
Set(strField, new ProtectedString(bProtect, pbData));
|
||||
MemUtil.ZeroByteArray(pbData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
303
ModernKeePassLib/Collections/PwObjectList.cs
Normal file
303
ModernKeePassLib/Collections/PwObjectList.cs
Normal file
@@ -0,0 +1,303 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
using ModernKeePassLib.Interfaces;
|
||||
|
||||
namespace ModernKeePassLib.Collections
|
||||
{
|
||||
/// <summary>
|
||||
/// List of objects that implement <c>IDeepCloneable</c>,
|
||||
/// and cannot be <c>null</c>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type specifier.</typeparam>
|
||||
public sealed class PwObjectList<T> : IEnumerable<T>
|
||||
where T : class, IDeepCloneable<T>
|
||||
{
|
||||
private List<T> m_vObjects = new List<T>();
|
||||
|
||||
/// <summary>
|
||||
/// Get number of objects in this list.
|
||||
/// </summary>
|
||||
public uint UCount
|
||||
{
|
||||
get { return (uint)m_vObjects.Count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Construct a new list of objects.
|
||||
/// </summary>
|
||||
public PwObjectList()
|
||||
{
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return m_vObjects.GetEnumerator();
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
return m_vObjects.GetEnumerator();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
// Do not destroy contained objects!
|
||||
m_vObjects.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clone the current <c>PwObjectList</c>, including all
|
||||
/// stored objects (deep copy).
|
||||
/// </summary>
|
||||
/// <returns>New <c>PwObjectList</c>.</returns>
|
||||
public PwObjectList<T> CloneDeep()
|
||||
{
|
||||
PwObjectList<T> pl = new PwObjectList<T>();
|
||||
|
||||
foreach(T po in m_vObjects)
|
||||
pl.Add(po.CloneDeep());
|
||||
|
||||
return pl;
|
||||
}
|
||||
|
||||
public PwObjectList<T> CloneShallow()
|
||||
{
|
||||
PwObjectList<T> tNew = new PwObjectList<T>();
|
||||
|
||||
foreach(T po in m_vObjects) tNew.Add(po);
|
||||
|
||||
return tNew;
|
||||
}
|
||||
|
||||
public List<T> CloneShallowToList()
|
||||
{
|
||||
PwObjectList<T> tNew = CloneShallow();
|
||||
return tNew.m_vObjects;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add an object to this list.
|
||||
/// </summary>
|
||||
/// <param name="pwObject">Object to be added.</param>
|
||||
/// <exception cref="System.ArgumentNullException">Thrown if the input
|
||||
/// parameter is <c>null</c>.</exception>
|
||||
public void Add(T pwObject)
|
||||
{
|
||||
Debug.Assert(pwObject != null);
|
||||
if(pwObject == null) throw new ArgumentNullException("pwObject");
|
||||
|
||||
m_vObjects.Add(pwObject);
|
||||
}
|
||||
|
||||
public void Add(PwObjectList<T> vObjects)
|
||||
{
|
||||
Debug.Assert(vObjects != null);
|
||||
if(vObjects == null) throw new ArgumentNullException("vObjects");
|
||||
|
||||
foreach(T po in vObjects)
|
||||
{
|
||||
m_vObjects.Add(po);
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(List<T> vObjects)
|
||||
{
|
||||
Debug.Assert(vObjects != null);
|
||||
if(vObjects == null) throw new ArgumentNullException("vObjects");
|
||||
|
||||
foreach(T po in vObjects)
|
||||
{
|
||||
m_vObjects.Add(po);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get an object of the list.
|
||||
/// </summary>
|
||||
/// <param name="uIndex">Index of the object to get. Must be valid, otherwise an
|
||||
/// exception is thrown.</param>
|
||||
/// <returns>Reference to an existing <c>T</c> object. Is never <c>null</c>.</returns>
|
||||
public T GetAt(uint uIndex)
|
||||
{
|
||||
Debug.Assert(uIndex < m_vObjects.Count);
|
||||
if(uIndex >= m_vObjects.Count) throw new ArgumentOutOfRangeException("uIndex");
|
||||
|
||||
return m_vObjects[(int)uIndex];
|
||||
}
|
||||
|
||||
public void SetAt(uint uIndex, T pwObject)
|
||||
{
|
||||
Debug.Assert(pwObject != null);
|
||||
if(pwObject == null) throw new ArgumentNullException("pwObject");
|
||||
if(uIndex >= (uint)m_vObjects.Count)
|
||||
throw new ArgumentOutOfRangeException("uIndex");
|
||||
|
||||
m_vObjects[(int)uIndex] = pwObject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a range of objects.
|
||||
/// </summary>
|
||||
/// <param name="uStartIndexIncl">Index of the first object to be
|
||||
/// returned (inclusive).</param>
|
||||
/// <param name="uEndIndexIncl">Index of the last object to be
|
||||
/// returned (inclusive).</param>
|
||||
/// <returns></returns>
|
||||
public List<T> GetRange(uint uStartIndexIncl, uint uEndIndexIncl)
|
||||
{
|
||||
if(uStartIndexIncl >= (uint)m_vObjects.Count)
|
||||
throw new ArgumentOutOfRangeException("uStartIndexIncl");
|
||||
if(uEndIndexIncl >= (uint)m_vObjects.Count)
|
||||
throw new ArgumentOutOfRangeException("uEndIndexIncl");
|
||||
if(uStartIndexIncl > uEndIndexIncl)
|
||||
throw new ArgumentException();
|
||||
|
||||
List<T> list = new List<T>((int)(uEndIndexIncl - uStartIndexIncl) + 1);
|
||||
for(uint u = uStartIndexIncl; u <= uEndIndexIncl; ++u)
|
||||
{
|
||||
list.Add(m_vObjects[(int)u]);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public int IndexOf(T pwReference)
|
||||
{
|
||||
Debug.Assert(pwReference != null); if(pwReference == null) throw new ArgumentNullException("pwReference");
|
||||
|
||||
return m_vObjects.IndexOf(pwReference);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete an object of this list. The object to be deleted is identified
|
||||
/// by a reference handle.
|
||||
/// </summary>
|
||||
/// <param name="pwReference">Reference of the object to be deleted.</param>
|
||||
/// <returns>Returns <c>true</c> if the object was deleted, <c>false</c> if
|
||||
/// the object wasn't found in this list.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">Thrown if the input
|
||||
/// parameter is <c>null</c>.</exception>
|
||||
public bool Remove(T pwReference)
|
||||
{
|
||||
Debug.Assert(pwReference != null); if(pwReference == null) throw new ArgumentNullException("pwReference");
|
||||
|
||||
return m_vObjects.Remove(pwReference);
|
||||
}
|
||||
|
||||
public void RemoveAt(uint uIndex)
|
||||
{
|
||||
m_vObjects.RemoveAt((int)uIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move an object up or down.
|
||||
/// </summary>
|
||||
/// <param name="tObject">The object to be moved.</param>
|
||||
/// <param name="bUp">Move one up. If <c>false</c>, move one down.</param>
|
||||
public void MoveOne(T tObject, bool bUp)
|
||||
{
|
||||
Debug.Assert(tObject != null);
|
||||
if(tObject == null) throw new ArgumentNullException("tObject");
|
||||
|
||||
int nCount = m_vObjects.Count;
|
||||
if(nCount <= 1) return;
|
||||
|
||||
int nIndex = m_vObjects.IndexOf(tObject);
|
||||
Debug.Assert(nIndex >= 0);
|
||||
|
||||
if(bUp && (nIndex > 0)) // No assert for top item
|
||||
{
|
||||
T tTemp = m_vObjects[nIndex - 1];
|
||||
m_vObjects[nIndex - 1] = m_vObjects[nIndex];
|
||||
m_vObjects[nIndex] = tTemp;
|
||||
}
|
||||
else if(!bUp && (nIndex != (nCount - 1))) // No assert for bottom item
|
||||
{
|
||||
T tTemp = m_vObjects[nIndex + 1];
|
||||
m_vObjects[nIndex + 1] = m_vObjects[nIndex];
|
||||
m_vObjects[nIndex] = tTemp;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move some of the objects in this list to the top/bottom.
|
||||
/// </summary>
|
||||
/// <param name="vObjects">List of objects to be moved.</param>
|
||||
/// <param name="bTop">Move to top. If <c>false</c>, move to bottom.</param>
|
||||
public void MoveTopBottom(T[] vObjects, bool bTop)
|
||||
{
|
||||
Debug.Assert(vObjects != null);
|
||||
if(vObjects == null) throw new ArgumentNullException("vObjects");
|
||||
|
||||
if(vObjects.Length == 0) return;
|
||||
|
||||
int nCount = m_vObjects.Count;
|
||||
foreach(T t in vObjects) m_vObjects.Remove(t);
|
||||
|
||||
if(bTop)
|
||||
{
|
||||
int nPos = 0;
|
||||
foreach(T t in vObjects)
|
||||
{
|
||||
m_vObjects.Insert(nPos, t);
|
||||
++nPos;
|
||||
}
|
||||
}
|
||||
else // Move to bottom
|
||||
{
|
||||
foreach(T t in vObjects) m_vObjects.Add(t);
|
||||
}
|
||||
|
||||
Debug.Assert(nCount == m_vObjects.Count);
|
||||
if(nCount != m_vObjects.Count)
|
||||
throw new ArgumentException("At least one of the T objects in the vObjects list doesn't exist!");
|
||||
}
|
||||
|
||||
public void Sort(IComparer<T> tComparer)
|
||||
{
|
||||
if(tComparer == null) throw new ArgumentNullException("tComparer");
|
||||
|
||||
m_vObjects.Sort(tComparer);
|
||||
}
|
||||
|
||||
public static PwObjectList<T> FromArray(T[] tArray)
|
||||
{
|
||||
if(tArray == null) throw new ArgumentNullException("tArray");
|
||||
|
||||
PwObjectList<T> l = new PwObjectList<T>();
|
||||
foreach(T t in tArray) { l.Add(t); }
|
||||
return l;
|
||||
}
|
||||
|
||||
public static PwObjectList<T> FromList(List<T> tList)
|
||||
{
|
||||
if(tList == null) throw new ArgumentNullException("tList");
|
||||
|
||||
PwObjectList<T> l = new PwObjectList<T>();
|
||||
l.Add(tList);
|
||||
return l;
|
||||
}
|
||||
}
|
||||
}
|
80
ModernKeePassLib/Collections/PwObjectPool.cs
Normal file
80
ModernKeePassLib/Collections/PwObjectPool.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
|
||||
using ModernKeePassLib.Delegates;
|
||||
using ModernKeePassLib.Interfaces;
|
||||
|
||||
#if KeePassLibSD
|
||||
using ModernKeePassLibSD;
|
||||
#endif
|
||||
|
||||
namespace ModernKeePassLib.Collections
|
||||
{
|
||||
public sealed class PwObjectPool
|
||||
{
|
||||
private SortedDictionary<PwUuidComparable, IStructureItem> m_dict =
|
||||
new SortedDictionary<PwUuidComparable, IStructureItem>();
|
||||
|
||||
public static PwObjectPool FromGroupRecursive(PwGroup pgRoot, bool bEntries)
|
||||
{
|
||||
if(pgRoot == null) throw new ArgumentNullException("pgRoot");
|
||||
|
||||
PwObjectPool p = new PwObjectPool();
|
||||
|
||||
if(!bEntries) p.m_dict[new PwUuidComparable(pgRoot.Uuid)] = pgRoot;
|
||||
GroupHandler gh = delegate(PwGroup pg)
|
||||
{
|
||||
p.m_dict[new PwUuidComparable(pg.Uuid)] = pg;
|
||||
return true;
|
||||
};
|
||||
|
||||
EntryHandler eh = delegate(PwEntry pe)
|
||||
{
|
||||
p.m_dict[new PwUuidComparable(pe.Uuid)] = pe;
|
||||
return true;
|
||||
};
|
||||
|
||||
pgRoot.TraverseTree(TraversalMethod.PreOrder, bEntries ? null : gh,
|
||||
bEntries ? eh : null);
|
||||
return p;
|
||||
}
|
||||
|
||||
public IStructureItem Get(PwUuid pwUuid)
|
||||
{
|
||||
IStructureItem pItem;
|
||||
m_dict.TryGetValue(new PwUuidComparable(pwUuid), out pItem);
|
||||
return pItem;
|
||||
}
|
||||
|
||||
public bool ContainsOnlyType(Type t)
|
||||
{
|
||||
foreach(KeyValuePair<PwUuidComparable, IStructureItem> kvp in m_dict)
|
||||
{
|
||||
if(kvp.Value.GetType() != t) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
116
ModernKeePassLib/Collections/StringDictionaryEx.cs
Normal file
116
ModernKeePassLib/Collections/StringDictionaryEx.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
|
||||
using ModernKeePassLib.Interfaces;
|
||||
|
||||
#if KeePassLibSD
|
||||
using ModernKeePassLibSD;
|
||||
#endif
|
||||
|
||||
namespace ModernKeePassLib.Collections
|
||||
{
|
||||
public sealed class StringDictionaryEx : IDeepCloneable<StringDictionaryEx>,
|
||||
IEnumerable<KeyValuePair<string, string>>
|
||||
{
|
||||
private SortedDictionary<string, string> m_vDict =
|
||||
new SortedDictionary<string, string>();
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return m_vDict.Count; }
|
||||
}
|
||||
|
||||
public StringDictionaryEx()
|
||||
{
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return m_vDict.GetEnumerator();
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
|
||||
{
|
||||
return m_vDict.GetEnumerator();
|
||||
}
|
||||
|
||||
public StringDictionaryEx CloneDeep()
|
||||
{
|
||||
StringDictionaryEx plNew = new StringDictionaryEx();
|
||||
|
||||
foreach(KeyValuePair<string, string> kvpStr in m_vDict)
|
||||
plNew.Set(kvpStr.Key, kvpStr.Value);
|
||||
|
||||
return plNew;
|
||||
}
|
||||
|
||||
public string Get(string strName)
|
||||
{
|
||||
Debug.Assert(strName != null); if(strName == null) throw new ArgumentNullException("strName");
|
||||
|
||||
string s;
|
||||
if(m_vDict.TryGetValue(strName, out s)) return s;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool Exists(string strName)
|
||||
{
|
||||
Debug.Assert(strName != null); if(strName == null) throw new ArgumentNullException("strName");
|
||||
|
||||
return m_vDict.ContainsKey(strName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a string.
|
||||
/// </summary>
|
||||
/// <param name="strField">Identifier of the string field to modify.</param>
|
||||
/// <param name="strNewValue">New value. This parameter must not be <c>null</c>.</param>
|
||||
/// <exception cref="System.ArgumentNullException">Thrown if one of the input
|
||||
/// parameters is <c>null</c>.</exception>
|
||||
public void Set(string strField, string strNewValue)
|
||||
{
|
||||
Debug.Assert(strField != null); if(strField == null) throw new ArgumentNullException("strField");
|
||||
Debug.Assert(strNewValue != null); if(strNewValue == null) throw new ArgumentNullException("strNewValue");
|
||||
|
||||
m_vDict[strField] = strNewValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete a string.
|
||||
/// </summary>
|
||||
/// <param name="strField">Name of the string field to delete.</param>
|
||||
/// <returns>Returns <c>true</c> if the field has been successfully
|
||||
/// removed, otherwise the return value is <c>false</c>.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">Thrown if the input
|
||||
/// parameter is <c>null</c>.</exception>
|
||||
public bool Remove(string strField)
|
||||
{
|
||||
Debug.Assert(strField != null); if(strField == null) throw new ArgumentNullException("strField");
|
||||
|
||||
return m_vDict.Remove(strField);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user