本文整理汇总了C#中SerializableDictionary.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# SerializableDictionary.GetType方法的具体用法?C# SerializableDictionary.GetType怎么用?C# SerializableDictionary.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SerializableDictionary
的用法示例。
在下文中一共展示了SerializableDictionary.GetType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetShopListByUserID
public List<int> GetShopListByUserID(int userID)
{
//模拟从MemCache中读取索引
SerializableDictionary<int, List<int>> dic = new SerializableDictionary<int, List<int>>();
byte[] bytes = Encoding.UTF8.GetBytes(File.ReadAllText("F://1.txt", Encoding.UTF8));
var memoryStream = new MemoryStream();
memoryStream.Write(bytes, 0, bytes.Count());
memoryStream.Seek(0, SeekOrigin.Begin);
XmlSerializer xml = new XmlSerializer(dic.GetType());
var obj = xml.Deserialize(memoryStream) as Dictionary<int, List<int>>;
return obj[userID];
}
示例2: Main
static void Main(string[] args)
{
//模拟从数据库加载索引到内存中,形成内存中的数据库
//这里的 "Dictionary" 用来表达“一个用户注册过多少店铺“,即UserID与ShopID的一对多关系
SerializableDictionary<int, List<int>> dic = new SerializableDictionary<int, List<int>>();
List<int> shopIDList = new List<int>();
for (int shopID = 300000; shopID < 300050; shopID++)
shopIDList.Add(shopID);
int UserID = 15;
//假设这里已经维护好了UserID与ShopID的关系
dic.Add(UserID, shopIDList);
XmlSerializer xml = new XmlSerializer(dic.GetType());
var memoryStream = new MemoryStream();
xml.Serialize(memoryStream, dic);
memoryStream.Seek(0, SeekOrigin.Begin);
//将Dictionary持久化,相当于模拟保存在Mencache里面
File.AppendAllText("F://1.txt", Encoding.UTF8.GetString(memoryStream.ToArray()));
Console.WriteLine("数据加载成功!");
Console.Read();
}
示例3: UnitTestSerialize
public void UnitTestSerialize()
{
SerializableDictionary<string, string> dictionary = new SerializableDictionary<string, string>();
dictionary.Add("myKey", "myValue");
XmlSerializer xmlSerializer = new XmlSerializer(dictionary.GetType());
string xml;
using (MemoryStream memoryStream = new MemoryStream())
{
using (XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8))
{
using (StreamReader streamReader = new StreamReader(memoryStream, Encoding.UTF8))
{
xmlSerializer.Serialize(xmlTextWriter, dictionary);
memoryStream.Position = 0;
xml = streamReader.ReadToEnd();
streamReader.Close();
}
}
}
Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-8\"?><Dictionary><item><key><string>myKey</string></key><value><string>myValue</string></value></item></Dictionary>", xml, "The XML representing the serialized dictionary was not as expected.");
}
示例4: ShouldIgnorePrivateClassExtension
public void ShouldIgnorePrivateClassExtension()
{
var dictionary = new SerializableDictionary<string, object>();
dictionary.Add("foo", new PrivateClass());
var serializer = new XmlSerializer(dictionary.GetType());
using (var writer = XmlWriter.Create(Console.Out, new XmlWriterSettings { Indent = true }))
{
serializer.Serialize(writer, dictionary);
}
var mem = new MemoryStream();
serializer.Serialize(mem, dictionary);
mem.Position = 0;
var deserialized = (Dictionary<string, object>)serializer.Deserialize(mem);
Assert.AreEqual(0, deserialized.Count);
}
示例5: ShouldRoundtripXml
public void ShouldRoundtripXml()
{
var dictionary = new SerializableDictionary<string, object>();
dictionary.Add("foo", new Foo
{
Name = "name",
Bar = new Bar
{
Value = "value",
},
});
var serializer = new XmlSerializer(dictionary.GetType());
using (var writer = XmlWriter.Create(Console.Out, new XmlWriterSettings { Indent = true }))
{
serializer.Serialize(writer, dictionary);
}
var mem = new MemoryStream();
serializer.Serialize(mem, dictionary);
mem.Position = 0;
var deserialized = (Dictionary<string, object>)serializer.Deserialize(mem);
Assert.AreEqual(dictionary.Count, deserialized.Count);
}