public static Expression RestoreSnapshot(KeyValuePair<string, List<Type>>[] SnapshotData)
 {
     if (SnapshotData.SequenceEqual(CurrentScope.OnDateType)) return null;
     var Ret = Expression.Block(
         SnapshotData.Except(CurrentScope.OnDateType)
         .SelectMany(x => x.Value.Select(y => CurrentScope.GetVarCached(x.Key, y)))
     );
     SnapshotData = null;
     return Ret;
 }
Пример #2
0
        public void CopyTo_ShouldBehaveTheSameWay()
        {
            // Arrange
            Dictionary <int, string> dictionary = new(SampleDictionary);
            Fictionary <int, string, GenericEqualityComparer <int> > fictionary = SampleDictionary.ToFictionary();

            var dictionaryArray = new KeyValuePair <int, string> [dictionary.Count];
            var fictionaryArray = new KeyValuePair <int, string> [fictionary.Count];

            // Act
            ((ICollection <KeyValuePair <int, string> >)dictionary).CopyTo(dictionaryArray, 0);
            ((ICollection <KeyValuePair <int, string> >)fictionary).CopyTo(fictionaryArray, 0);

            // Assert
            Assert.Empty(dictionaryArray.Except(fictionaryArray));
            Assert.Empty(fictionaryArray.Except(dictionaryArray));
        }
Пример #3
0
        public void ToArray_FromDictionary()
        {
            var expectedItems  = new KeyValuePair <int, int>[] { new KeyValuePair <int, int>(1, 7), new KeyValuePair <int, int>(2, 6), new KeyValuePair <int, int>(3, 5), new KeyValuePair <int, int>(4, 4), new KeyValuePair <int, int>(5, 3), new KeyValuePair <int, int>(6, 2), new KeyValuePair <int, int>(7, 1) };
            var expectedKeys   = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            var expectedValues = new int[] { 7, 6, 5, 4, 3, 2, 1 };

            var dictionary = new Dictionary <int, int>
            {
                [1] = 7, [2] = 6, [3] = 5, [4] = 4, [5] = 3, [6] = 2, [7] = 1,
            };

            var actualItems  = dictionary.ToArray();
            var actualKeys   = dictionary.Keys.ToArray();
            var actualValues = dictionary.Values.ToArray();

            Assert.True(expectedItems.Length == actualItems.Length && !expectedItems.Except(actualItems).Any());
            Assert.True(expectedKeys.Length == actualKeys.Length && !expectedKeys.Except(actualKeys).Any());
            Assert.True(expectedValues.Length == actualValues.Length && !expectedValues.Except(actualValues).Any());

            var expectedItems2  = new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("1", "8"), new KeyValuePair <string, string>("2", "7"), new KeyValuePair <string, string>("3", "6"), new KeyValuePair <string, string>("4", "5"), new KeyValuePair <string, string>("5", "4"), new KeyValuePair <string, string>("6", "3"), new KeyValuePair <string, string>("7", "2"), new KeyValuePair <string, string>("8", "1") };
            var expectedKeys2   = new string[] { "1", "2", "3", "4", "5", "6", "7", "8" };
            var expectedValues2 = new string[] { "8", "7", "6", "5", "4", "3", "2", "1" };

            var dictionary2 = new Dictionary <string, string>
            {
                ["1"] = "8", ["2"] = "7", ["3"] = "6", ["4"] = "5", ["5"] = "4", ["6"] = "3", ["7"] = "2", ["8"] = "1",
            };

            var actualItems2  = dictionary2.ToArray();
            var actualKeys2   = dictionary2.Keys.ToArray();
            var actualValues2 = dictionary2.Values.ToArray();

            Assert.True(expectedItems2.Length == actualItems2.Length && !expectedItems2.Except(actualItems2).Any());
            Assert.True(expectedKeys2.Length == actualKeys2.Length && !expectedKeys2.Except(actualKeys2).Any());
            Assert.True(expectedValues2.Length == actualValues2.Length && !expectedValues2.Except(actualValues2).Any());
        }
Пример #4
0
        private static void WriteConstants(StringBuilder outputString, HashSet<string> usedConstants, ref KeyValuePair<string,string>[] remainingConstants, string prefix, string constantsName = null, Func<string, bool> additionalAcceptanceConstantFilter = null, Func<string, bool> additionalRejectConstantFilter = null)
        {
            if (string.IsNullOrEmpty(constantsName))
                constantsName = FormatEnumName(prefix, "");

            var constants = remainingConstants.Where(k => (k.Key.StartsWith(prefix) || (additionalAcceptanceConstantFilter != null && additionalAcceptanceConstantFilter(k.Key))) && (additionalRejectConstantFilter == null || additionalRejectConstantFilter(k.Key))).ToArray();
            remainingConstants = remainingConstants.Except(constants).ToArray();

            outputString.AppendLine("    enum " + constantsName);
            outputString.AppendLine("    {");
            foreach (var c in constants)
            {
                string cname = FormatEnumName(c.Key, prefix);

                while (usedConstants.Contains(cname))
                    cname += "_";
                usedConstants.Add(cname);

                outputString.AppendFormat("        {0} = {1},", cname, c.Value);
                outputString.AppendLine();
            }

            outputString.AppendLine("    };");
        }