本文整理汇总了C#中System.Collections.Dictionary.ConvertMap方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.ConvertMap方法的具体用法?C# Dictionary.ConvertMap怎么用?C# Dictionary.ConvertMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Dictionary
的用法示例。
在下文中一共展示了Dictionary.ConvertMap方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
serializer.NullValueHandling = NullValueHandling.Ignore;
if (IsMapType(objectType))
{
IDictionary list = new Dictionary<Object, Object>();
serializer.Populate(reader, list);
return list.ConvertMap(objectType);
}
else if (IsException(objectType))
{
Object exceptionObject = Activator.CreateInstance(HelpMethods.ImplementTypeDynamicly(objectType, typeof(IJavaException)));
serializer.Populate(reader, exceptionObject);
return exceptionObject;
}
Type typeWithIOpenEngSBModel;
if (alreadyExtendedTypes.ContainsKey(objectType.Name))
{
typeWithIOpenEngSBModel = alreadyExtendedTypes[objectType.Name];
}
else
{
typeWithIOpenEngSBModel = HelpMethods.ImplementTypeDynamicly(objectType, typeof(IOpenEngSBModel));
alreadyExtendedTypes.Add(objectType.Name, typeWithIOpenEngSBModel);
}
Object modelWithOpenEngsbModelTail = Activator.CreateInstance(typeWithIOpenEngSBModel);
serializer.Populate(reader, modelWithOpenEngsbModelTail);
return modelWithOpenEngsbModelTail;
}
示例2: TestIfMapIsRecognizedAndIfVariablesAreDetectedCorrectlyAndCorrectConvertedFromJsonToObject
public void TestIfMapIsRecognizedAndIfVariablesAreDetectedCorrectlyAndCorrectConvertedFromJsonToObject()
{
IDictionary result = new Dictionary<String, String>();
Entry1[] entry = new Entry1[]
{
new Entry1()
{
key = "Test", value = 123
}
};
result.Add("123", new JsonMarshaller().MarshallObject(entry));
EntryWithEntryParameter[] arrays = (EntryWithEntryParameter[])result.ConvertMap(typeof(EntryWithEntryParameter));
Assert.IsTrue(arrays[0].key.Equals("123"));
Assert.IsTrue(arrays[0].value[0].key.Equals("Test"));
}
示例3: TestConvertingWithExtendedMethodDictionaryToEntry1WhereTheReturnTypeIsIndicatedAsType
public void TestConvertingWithExtendedMethodDictionaryToEntry1WhereTheReturnTypeIsIndicatedAsType()
{
Dictionary<Object, Object> test = new Dictionary<Object, Object>();
test.Add("1", 11);
test.Add("21", 111);
Entry1[] result = (Entry1[])test.ConvertMap(typeof(Entry1));
foreach (Entry1 e1 in result)
{
Assert.IsTrue(test.ContainsKey(e1.key));
Assert.AreEqual(test[e1.key], e1.value);
}
}
示例4: TestConvertingWithExtendedMethodDictionaryToEntry1
public void TestConvertingWithExtendedMethodDictionaryToEntry1()
{
Dictionary<Object, Object> test = new Dictionary<Object, Object>();
test.Add("1", 11);
test.Add("21", 111);
Entry1[] result = test.ConvertMap<Entry1>();
foreach (Entry1 e1 in result)
{
Assert.IsTrue(test.ContainsKey(e1.key));
Assert.AreEqual<Object>(test[e1.key], e1.value);
}
}
示例5: TestConvertIDictionaryToMap
public void TestConvertIDictionaryToMap()
{
IDictionary result = new Dictionary<String, int>();
result.Add("Test", 123);
Entry1[] arrays = (Entry1[])result.ConvertMap(typeof(Entry1[]));
}
示例6: TestConvertDictionaryToEntry1WithParameterTypeAreEntry1AndInJsonFormat
public void TestConvertDictionaryToEntry1WithParameterTypeAreEntry1AndInJsonFormat()
{
// This Test case checks if an object that is not an array is not recognized as Map and converted correctly
IDictionary result = new Dictionary<String, String>();
Entry1 keyEntry = new Entry1 { key = "Test", value = 123 };
Entry1 valueEntry = new Entry1 { key = "ValueTest", value = 111 };
result.Add(marshaller.MarshallObject(keyEntry), marshaller.MarshallObject(valueEntry));
EntryWithAllEntryParameter[] arrays = (EntryWithAllEntryParameter[])result.ConvertMap(typeof(EntryWithAllEntryParameter));
Assert.AreEqual<String>(arrays[0].key.key, keyEntry.key);
Assert.AreEqual<int>(arrays[0].key.value, keyEntry.value);
Assert.AreEqual<String>(arrays[0].value.key, valueEntry.key);
Assert.AreEqual<int>(arrays[0].value.value, valueEntry.value);
}