本文整理汇总了C#中System.Collections.Specialized.NameValueCollection.GetKey方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Specialized.NameValueCollection.GetKey方法的具体用法?C# System.Collections.Specialized.NameValueCollection.GetKey怎么用?C# System.Collections.Specialized.NameValueCollection.GetKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Specialized.NameValueCollection
的用法示例。
在下文中一共展示了System.Collections.Specialized.NameValueCollection.GetKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Member
private static void Member(JsonTextWriter writer, string name, NameValueCollection collection)
{
Debug.Assert(writer != null);
Debug.AssertStringNotEmpty(name);
//
// Bail out early if the collection is null or empty.
//
if (collection == null || collection.Count == 0)
return;
//
// Save the depth, which we'll use to lazily emit the collection.
// That is, if we find that there is nothing useful in it, then
// we could simply avoid emitting anything.
//
var depth = writer.Depth;
//
// For each key, we get all associated values and loop through
// twice. The first time round, we count strings that are
// neither null nor empty. If none are found then the key is
// skipped. Otherwise, second time round, we encode
// strings that are neither null nor empty. If only such string
// exists for a key then it is written directly, otherwise
// multiple strings are naturally wrapped in an array.
//
var items = from i in Enumerable.Range(0, collection.Count)
let values = collection.GetValues(i)
where values != null && values.Length > 0
let some = // Neither null nor empty
from v in values
where !string.IsNullOrEmpty(v)
select v
let nom = some.Take(2).Count()
where nom > 0
select new
{
Key = collection.GetKey(i),
IsArray = nom > 1,
Values = some,
};
foreach (var item in items)
{
//
// There is at least one value so now we emit the key.
// Before doing that, we check if the collection member
// was ever started. If not, this would be a good time.
//
if (depth == writer.Depth)
{
writer.Member(name);
writer.Object();
}
writer.Member(item.Key ?? string.Empty);
if (item.IsArray)
writer.Array(); // Wrap multiples in an array
foreach (var value in item.Values)
writer.String(value);
if (item.IsArray)
writer.Pop(); // Close multiples array
}
//
// If we are deeper than when we began then the collection was
// started so we terminate it here.
//
if (writer.Depth > depth)
writer.Pop();
}
示例2: InitSavedOptionsCollection
/// <summary>
/// load collection with saved options from the xml config file
/// </summary>
private void InitSavedOptionsCollection(ref string ErrorMessage)
{
IEnumerable<System.Xml.Linq.XElement> SavedOptions;
m_SaveOptionCollection = new System.Collections.Specialized.NameValueCollection();
m_SaveOptionCollection.Add("RememberLastSurveyID", "");
m_SaveOptionCollection.Add("TransectTotal", "");
m_SaveOptionCollection.Add("StartX", "");
m_SaveOptionCollection.Add("StartY", "");
m_SaveOptionCollection.Add("MaxTransLineLength", "");
m_SaveOptionCollection.Add("BlindAreaBuffer", "");
m_SaveOptionCollection.Add("BufferDistance", "");
m_SaveOptionCollection.Add("BufferFCName", "");
m_SaveOptionCollection.Add("MinTransLineLength", "");
m_SaveOptionCollection.Add("MaxElevation", "");
m_SaveOptionCollection.Add("MaxSlope", "");
m_SaveOptionCollection.Add("MinSlope", "");
m_SaveOptionCollection.Add("ImportDataPath", "");
m_SaveOptionCollection.Add("ExportDataPath", "");
m_SaveOptionCollection.Add("GridPointSpacing", "");
m_SaveOptionCollection.Add("TotalRandomPoints", "");
m_SaveOptionCollection.Add("SurveyID", "");
m_SaveOptionCollection.Add("DemFileLocation", "");
SavedOptions = m_XMLConfig.Descendants("NPSConfig");
foreach (System.Xml.Linq.XElement ThisOption in SavedOptions)
{
for (int Index = 0; Index < m_SaveOptionCollection.Keys.Count; Index++)
{
if (m_SaveOptionCollection.GetKey(Index).ToLower() == ThisOption.Name.LocalName.ToLower())
m_SaveOptionCollection[m_SaveOptionCollection.GetKey(Index)] = ThisOption.Value;
}
}
SavedOptions = m_XMLConfig.Descendants("StoredOptions");
foreach (System.Xml.Linq.XElement ThisOption in SavedOptions)
{
for (int Index = 0; Index < m_SaveOptionCollection.Keys.Count; Index++)
{
if (m_SaveOptionCollection.GetKey(Index).ToLower() == ThisOption.Name.LocalName.ToLower())
m_SaveOptionCollection[m_SaveOptionCollection.GetKey(Index)] = ThisOption.Value;
}
}
}