public void CopyTo()
        {
            IDictionary<string, string> dict = new Dictionary<string, string>();
            dict.Add("Key", "Value");
            dict.Add("OtherKey", "OtherValue");

            dict = dict.ToReadOnlyDictionary();

            var values = new KeyValuePair<string, string>[3];

            var expectedValues = new[]
            {
                KeyValuePair.Create("Key", "Value"),
                KeyValuePair.Create("OtherKey", "OtherValue"),
                default(KeyValuePair<string, string>)
            };

            dict.CopyTo(values, 0);
            Assert.IsTrue(values.SequenceEqual(expectedValues));

            dict.CopyTo(values, 1);

            expectedValues[2] = expectedValues[1];
            expectedValues[1] = expectedValues[0];

            Assert.IsTrue(values.SequenceEqual(expectedValues));
        }
示例#2
0
 internal static List<int> SortDictionaryKeys(Dictionary<int, string>.KeyCollection keys)
 {
     int[] tmp = new int[keys.Count];
     keys.CopyTo(tmp, 0);
     List<int> ret = new List<int>(tmp);
     ret.Sort();
     return ret;
 }
示例#3
0
 private Dictionary<string, bool> readUIDigitals(Dictionary<string, bool>.KeyCollection keys)
 {
     Dictionary<string, bool> digitals = new Dictionary<string,bool>();
     string[] keyArray = new string[keys.Count];
     keys.CopyTo(keyArray, 0);
     for (int i = 0; i < keys.Count; i++)
     {
         digitals[keyArray[i]] = controlWindow.ReadDigital(keyArray[i]);
     }
     return digitals;
 }
        public void GenericDictionarySource()
        {
            var source = new Dictionary<string, object>();

            // guid
            var guidValue = new Guid("21EC2020-3AEA-1069-A2DD-08002B30309D");
            source["GuidPty"] = guidValue;
            Assert.AreEqual(guidValue, source.CopyTo<TargetType>().GuidPty);

            source["GuidPty"] = guidValue.ToString();
            Assert.AreEqual(guidValue, source.CopyTo<TargetType>().GuidPty);

            source["GuidPty"] = guidValue.ToByteArray();
            Assert.AreEqual(guidValue, source.CopyTo<TargetType>().GuidPty);

            // int
            source["IntPty"] = 345;
            Assert.AreEqual(345, source.CopyTo<TargetType>().IntPty);

            source["IntPty"] = 345.ToString(CultureInfo.InvariantCulture);
            Assert.AreEqual(345, source.CopyTo<TargetType>().IntPty);

            source["IntPty"] = (long)345;
            Assert.AreEqual(345, source.CopyTo<TargetType>().IntPty);

            source["IntPty"] = int.MaxValue;
            Assert.AreEqual(int.MaxValue, source.CopyTo<TargetType>().IntPty);

            // enum pty
            source["EnumPty"] = TargetType.TestEnum.Three;
            Assert.AreEqual(TargetType.TestEnum.Three, source.CopyTo<TargetType>().EnumPty);

            source["EnumPty"] = TargetType.TestEnum.Three.ToString();
            Assert.AreEqual(TargetType.TestEnum.Three, source.CopyTo<TargetType>().EnumPty);

            source["EnumPty"] = (int)TargetType.TestEnum.Three;
            Assert.AreEqual(TargetType.TestEnum.Three, source.CopyTo<TargetType>().EnumPty);

            source["EnumPty"] = (byte)TargetType.TestEnum.Three;
            Assert.AreEqual(TargetType.TestEnum.Three, source.CopyTo<TargetType>().EnumPty);

            source["EnumPty"] = (long)TargetType.TestEnum.Three;
            Assert.AreEqual(TargetType.TestEnum.Three, source.CopyTo<TargetType>().EnumPty);

            // obj pty
            var obj = new object();
            source["ObjPty"] = obj;
            Assert.AreEqual(obj, source.CopyTo<TargetType>().ObjPty);
        }
示例#5
0
 private Dictionary<string, double> readUIAnalogs(Dictionary<string, double>.KeyCollection keys)
 {
     Dictionary<string, double> analogs = new Dictionary<string, double>();
     string[] keyArray = new string[keys.Count];
     keys.CopyTo(keyArray, 0);
     for (int i = 0; i < keys.Count; i++)
     {
         analogs[keyArray[i]] = controlWindow.ReadAnalog(keyArray[i]);
     }
     return analogs;
 }