当前位置: 首页>>代码示例>>C#>>正文


C# Hashtable.GetObjectData方法代码示例

本文整理汇总了C#中Hashtable.GetObjectData方法的典型用法代码示例。如果您正苦于以下问题:C# Hashtable.GetObjectData方法的具体用法?C# Hashtable.GetObjectData怎么用?C# Hashtable.GetObjectData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Hashtable的用法示例。


在下文中一共展示了Hashtable.GetObjectData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: runTest

 public bool runTest()
 {
     Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     String strLoc = "Loc_000oo";
     Hashtable dic1;
     Int32 iNumberOfItems = 10;
     SerializationInfo ser1;
     Object[] serKeys;
     Object[] serValues;
     Hashtable hsh1;
     Hashtable hsh3;
     Hashtable hsh4;
     DictionaryEntry[] strValueArr;
     MemoryStream ms1;
     try 
     {
         do
         {
             strLoc = "Loc_8345vdfv";
             dic1 = new Hashtable();
             for(int i=0; i<iNumberOfItems; i++)
             {
                 dic1.Add(i, "String_" + i);
             }
             ser1 = new SerializationInfo(typeof(Hashtable), new FormatterConverter());
             dic1.GetObjectData(ser1, new StreamingContext());
             iCountTestcases++;
             if(ser1.GetSingle("LoadFactor") != 0.72f) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_748cdg! Expected value not returned, " + ser1.GetSingle("LoadFactor"));
             }
             if(ser1.GetInt32("Version") != 11) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_01823csdf! Expected value not returned, " + ser1.GetSingle("Version"));
             }
             if(ser1.GetSingle("HashSize") != 23) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_7132fgfg! Expected value not returned, " + ser1.GetSingle("LoadFactor"));
             }
             serKeys = (Object[])ser1.GetValue("Keys", typeof(Object[]));
                 serValues = (Object[])ser1.GetValue("Values", typeof(Object[]));
                     Array.Sort(serKeys);
             Array.Sort(serValues);
             for(int i=0; i<iNumberOfItems; i++)
             {
                 if((Int32)serKeys[i] != i) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_1nd342_" + i + "! Expected value not returned, " + i);
                 }
                 if(!((String)serValues[i]).Equals("String_" + i)) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_7539fdg_" + i + "! Expected value not returned, " + i);
                 }
             }
             try
             {
                 iCountTestcases++;
                 dic1.GetObjectData(null, new StreamingContext());
                 iCountErrors++;
                 Console.WriteLine("Err_7439dg! Exception not thrown");
             }
             catch(ArgumentNullException)
             {
             }
             catch(Exception ex)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_6572fdg! Unexpected exception thrown, " + ex);
             }
             iCountTestcases++;
             hsh1 = new Hashtable();
             for(int i=0; i<10; i++)
             {
                 hsh1.Add("Key_" + i, "Value_" + i);
             }
             BinaryFormatter formatter = new BinaryFormatter();
             ms1 = new MemoryStream();
             formatter.Serialize(ms1, hsh1);
             ms1.Position = 0;
             hsh4 = (Hashtable)formatter.Deserialize(ms1);
             if(hsh4.Count != hsh1.Count) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_072xsf! Expected value not returned, " + hsh4.Count);
             }				
             strValueArr = new DictionaryEntry[hsh4.Count];
             hsh4.CopyTo(strValueArr, 0);
             hsh3 = new Hashtable();
             for(int i=0; i<10; i++)
             {
                 if(!hsh4.Contains("Key_" + i)) 
                 {
                     iCountErrors++;
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co3949getobjectdata_sersc.cs


注:本文中的Hashtable.GetObjectData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。