本文整理汇总了C#中System.Collections.DictionaryEntry类的典型用法代码示例。如果您正苦于以下问题:C# DictionaryEntry类的具体用法?C# DictionaryEntry怎么用?C# DictionaryEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DictionaryEntry类属于System.Collections命名空间,在下文中一共展示了DictionaryEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildSerializer
public override ValueSerializer BuildSerializer(Serializer serializer, Type type,
ConcurrentDictionary<Type, ValueSerializer> typeMapping)
{
var ser = new ObjectSerializer(type);
typeMapping.TryAdd(type, ser);
var elementSerializer = serializer.GetSerializerByType(typeof (DictionaryEntry));
ValueReader reader = (stream, session) =>
{
var count = stream.ReadInt32(session);
var entries = new DictionaryEntry[count];
for (var i = 0; i < count; i++)
{
var entry = (DictionaryEntry) stream.ReadObject(session);
entries[i] = entry;
}
return null;
};
ValueWriter writer = (stream, obj, session) =>
{
var dict = obj as IDictionary;
// ReSharper disable once PossibleNullReferenceException
stream.WriteInt32(dict.Count);
foreach (var item in dict)
{
stream.WriteObject(item, typeof (DictionaryEntry), elementSerializer,
serializer.Options.PreserveObjectReferences, session);
// elementSerializer.WriteValue(stream,item,session);
}
};
ser.Initialize(reader, writer);
return ser;
}
示例2: SetSessionStateItem
internal override void SetSessionStateItem(string path, object value, bool writeItem)
{
Path name = PathIntrinsics.RemoveDriveName(path);
path = name.TrimStartSlash();
if (value == null)
{
Environment.SetEnvironmentVariable(path, null);
}
else
{
if (value is DictionaryEntry)
{
value = ((DictionaryEntry)value).Value;
}
string str = value as string;
if (str == null)
{
str = PSObject.AsPSObject(value).ToString();
}
Environment.SetEnvironmentVariable(path, str);
DictionaryEntry item = new DictionaryEntry(path, str);
if (writeItem)
{
WriteItemObject(item, path, false);
}
}
}
示例3: BasicTests
private void BasicTests (ListDictionary ld)
{
Assert.AreEqual (0, ld.Count, "Count");
Assert.IsFalse (ld.IsFixedSize, "IsFixedSize");
Assert.IsFalse (ld.IsReadOnly, "IsReadOnly");
Assert.IsFalse (ld.IsSynchronized, "IsSynchronized");
Assert.AreEqual (0, ld.Keys.Count, "Keys");
Assert.AreEqual (0, ld.Values.Count, "Values");
Assert.IsNotNull (ld.SyncRoot, "SyncRoot");
Assert.IsNotNull (ld.GetEnumerator (), "GetEnumerator");
Assert.IsNotNull ((ld as IEnumerable).GetEnumerator (), "IEnumerable.GetEnumerator");
ld.Add ("a", "1");
Assert.AreEqual (1, ld.Count, "Count-1");
Assert.IsTrue (ld.Contains ("a"), "Contains(a)");
Assert.IsFalse (ld.Contains ("1"), "Contains(1)");
ld.Add ("b", null);
Assert.AreEqual (2, ld.Count, "Count-2");
Assert.IsNull (ld["b"], "this[b]");
DictionaryEntry[] entries = new DictionaryEntry[2];
ld.CopyTo (entries, 0);
ld["b"] = "2";
Assert.AreEqual ("2", ld["b"], "this[b]2");
ld.Remove ("b");
Assert.AreEqual (1, ld.Count, "Count-3");
ld.Clear ();
Assert.AreEqual (0, ld.Count, "Count-4");
}
示例4: ChangeProviderFactory
private void ChangeProviderFactory(DictionaryEntry i)
{
var valueField = i.Value.GetType().GetField("_value", BindingFlags.NonPublic | BindingFlags.Instance);
if (valueField != null)
{
var value = valueField.GetValue(i.Value);
var workspaceField = value.GetType().GetField("_workspace", BindingFlags.NonPublic | BindingFlags.Instance);
if (workspaceField != null)
{
var workspace = workspaceField.GetValue(value);
var metadataWorkspaceField = workspace.GetType().GetField("_metadataWorkspace", BindingFlags.NonPublic | BindingFlags.Instance);
if (metadataWorkspaceField != null)
{
var metadataWorkspace = metadataWorkspaceField.GetValue(workspace);
var itemsSSpaceField = metadataWorkspace.GetType().GetField("_itemsSSpace", BindingFlags.NonPublic | BindingFlags.Instance);
if (itemsSSpaceField != null)
{
var itemsSSpace = itemsSSpaceField.GetValue(metadataWorkspace);
var providerFactoryField = itemsSSpace.GetType().GetField("_providerFactory", BindingFlags.NonPublic | BindingFlags.Instance);
if (providerFactoryField != null)
{
var providerFactory = providerFactoryField.GetValue(itemsSSpace);
providerFactoryField.SetValue(itemsSSpace, Activator.CreateInstance(GetProxyTypeForProvider(providerFactory.GetType())));
}
}
}
}
}
}
示例5: ReadDictionaryEventArgs
/// <summary>
/// 实例化
/// </summary>
/// <param name="value">对象</param>
/// <param name="keyType">键类型</param>
/// <param name="valueType">值类型</param>
/// <param name="index"></param>
/// <param name="callback"></param>
public ReadDictionaryEventArgs(DictionaryEntry value, Type keyType,Type valueType, Int32 index, ReadObjectCallback callback)
: base(index, callback)
{
Value = value;
KeyType = keyType;
ValueType = valueType;
}
示例6: AddressChangedCallback
private static void AddressChangedCallback(object stateObject, bool signaled)
{
lock (s_callerArray)
{
s_isPending = false;
if (s_isListening)
{
s_isListening = false;
DictionaryEntry[] array = new DictionaryEntry[s_callerArray.Count];
s_callerArray.CopyTo(array, 0);
StartHelper(null, false, (StartIPOptions) stateObject);
for (int i = 0; i < array.Length; i++)
{
NetworkAddressChangedEventHandler key = (NetworkAddressChangedEventHandler) array[i].Key;
ExecutionContext context = (ExecutionContext) array[i].Value;
if (context == null)
{
key(null, EventArgs.Empty);
}
else
{
ExecutionContext.Run(context.CreateCopy(), s_runHandlerCallback, key);
}
}
}
}
}
示例7: nextEntry
internal DictionaryEntry nextEntry() {
DictionaryEntry cEntry = entry;
hasMore = enum_Renamed.MoveNext();
if (hasMore)
entry = enum_Renamed.Entry;
return cEntry;
}
示例8: Ctor
public void Ctor () {
DictionaryEntry d = new DictionaryEntry (1, "something");
AssertNotNull (d);
AssertEquals ("#01", d.Key, 1);
AssertEquals ("#02", d.Value, "something");
}
示例9: foreach
public object this[object key]
{
get {
if (_extraData == null) return null;
foreach (DictionaryEntry entry in _extraData)
if (entry.Key.Equals (key)) return entry.Value;
return null;
}
set {
if (_extraData == null)
{
_extraData = new DictionaryEntry [] { new DictionaryEntry (key, value) };
}
else
{
DictionaryEntry[] tmpData = new DictionaryEntry [_extraData.Length + 1];
_extraData.CopyTo (tmpData, 0);
tmpData [_extraData.Length] = new DictionaryEntry (key, value);
_extraData = tmpData;
}
}
}
示例10: GetPages
public CascadingDropDownNameValue[] GetPages(string knownCategoryValues, string category)
{
AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext();
StringDictionary knownCatagories = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
DictionaryEntry[] CatagoryArray = new DictionaryEntry[knownCatagories.Count];
knownCatagories.CopyTo(CatagoryArray, 0);
String SelectedSection = "Error 1";
foreach (DictionaryEntry theEntry in CatagoryArray)
{
if (theEntry.Key.ToString().Equals("section"))
{
SelectedSection = theEntry.Value.ToString();
}
}
IQueryable<AnswerApp.Models.Page> retrieved = from theAnswers in db.Pages
where theAnswers.Section_Title.Equals(SelectedSection)//Textbook_Title)
select theAnswers;
AnswerApp.Models.Page[] results = retrieved.ToArray<AnswerApp.Models.Page>();
List<CascadingDropDownNameValue> theList = new List<CascadingDropDownNameValue>();
foreach (AnswerApp.Models.Page thePage in results)
{
theList.Add(new CascadingDropDownNameValue(thePage.Page_Number, thePage.Page_Number));
}
return theList.ToArray();
}
示例11: All
public void All ()
{
HybridDictionary dict = new HybridDictionary (true);
dict.Add ("CCC", "ccc");
dict.Add ("BBB", "bbb");
dict.Add ("fff", "fff");
dict ["EEE"] = "eee";
dict ["ddd"] = "ddd";
Assert.AreEqual (5, dict.Count, "#1");
Assert.AreEqual ("eee", dict["eee"], "#2");
dict.Add ("CCC2", "ccc");
dict.Add ("BBB2", "bbb");
dict.Add ("fff2", "fff");
dict ["EEE2"] = "eee";
dict ["ddd2"] = "ddd";
dict ["xxx"] = "xxx";
dict ["yyy"] = "yyy";
Assert.AreEqual (12, dict.Count, "#3");
Assert.AreEqual ("eee", dict["eee"], "#4");
dict.Remove ("eee");
Assert.AreEqual (11, dict.Count, "Removed/Count");
Assert.IsFalse (dict.Contains ("eee"), "Removed/Contains(xxx)");
DictionaryEntry[] entries = new DictionaryEntry [11];
dict.CopyTo (entries, 0);
Assert.IsTrue (dict.Contains ("xxx"), "Contains(xxx)");
dict.Clear ();
Assert.AreEqual (0, dict.Count, "Cleared/Count");
Assert.IsFalse (dict.Contains ("xxx"), "Cleared/Contains(xxx)");
}
示例12: button1_Click
private void button1_Click(object sender, EventArgs e)
{
List<DictionaryEntry> list = new List<DictionaryEntry>();
DataSet dsData = new DataSet();
dsData.ReadXml(@"..\..\..\..\..\..\Data\Orders.xml");
//Create word document
Document document = new Document();
document.LoadFromFile(@"..\..\..\..\..\..\Data\Invoice.doc");
DictionaryEntry dictionaryEntry = new DictionaryEntry("Customer", string.Empty);
list.Add(dictionaryEntry);
dictionaryEntry = new DictionaryEntry("Order", "Customer_Id = %Customer.Customer_Id%");
list.Add(dictionaryEntry);
document.MailMerge.ExecuteWidthNestedRegion(dsData, list);
//Save doc file.
document.SaveToFile("Sample.doc", FileFormat.Doc);
//Launching the MS Word file.
WordDocViewer("Sample.doc");
}
示例13: Add
public void Add(object key, object value)
{
// Add the new key/value pair even if this key already exists in the dictionary.
if (ItemsInUse == items.Length)
throw new InvalidOperationException("The dictionary cannot hold any more items.");
items[ItemsInUse++] = new DictionaryEntry(key, value);
}
示例14: SetSessionStateItem
internal override void SetSessionStateItem(string name, object value, bool writeItem)
{
if (value == null)
{
Environment.SetEnvironmentVariable(name, null);
}
else
{
if (value is DictionaryEntry)
{
value = ((DictionaryEntry)value).Value;
}
string str = value as string;
if (str == null)
{
str = PSObject.AsPSObject(value).ToString();
}
Environment.SetEnvironmentVariable(name, str);
DictionaryEntry item = new DictionaryEntry(name, str);
if (writeItem)
{
WriteItemObject(item, name, false);
}
}
}
示例15: Ctor
public void Ctor () {
DictionaryEntry d = new DictionaryEntry (1, "something");
Assert.IsNotNull (d);
Assert.AreEqual (1, d.Key, "#01");
Assert.AreEqual ("something", d.Value, "#02");
}