コード例 #1
0
 private static bool AllValuesSame(IReadOnlyDictionary <string, List <string> > x, IReadOnlyDictionary <string, List <string> > y)
 {
     return(!x.Any(kvp =>
                   !y.ContainsKey(kvp.Key) ||
                   !AllValuesSame(kvp.Value, y[kvp.Key])
                   ) && y.All(kvp => x.ContainsKey(kvp.Key)));
 }
コード例 #2
0
        public MimeTypeProvider(IReadOnlyDictionary <string, string> mimeTypesByExtension)
        {
            if (!mimeTypesByExtension.All(x => x.Key.StartsWith(".")))
            {
                throw new Exception("The keys in the dictionary needs to all start with a '.'");
            }

            this.mimeTypesByExtension = mimeTypesByExtension.ToImmutableDictionary(StringComparer.OrdinalIgnoreCase);
        }
        public async Task GroupByBudgetAccountGroupAsync_WhenCalled_ReturnsReadOnlyDictionaryWhichContainsBudgetAccountCollectionMatchingEachBudgetAccountGroupFromBudgetAccountsInBudgetAccountCollection()
        {
            IBudgetAccountCollection sut = CreateSut();

            sut.Add(CreateBudgetAccountCollection());

            IReadOnlyDictionary <IBudgetAccountGroup, IBudgetAccountCollection> result = await sut.GroupByBudgetAccountGroupAsync();

            Assert.That(result.All(item => item.Value.All(budgetAccount => budgetAccount.BudgetAccountGroup.Number == item.Key.Number)), Is.True);
        }
コード例 #4
0
 private bool DictEquals <TKey, TValue>(
     IReadOnlyDictionary <TKey, TValue> dictA,
     IReadOnlyDictionary <TKey, TValue> dictB)
 {
     return(dictA.Count == dictB.Count &&
            dictA.All(kvpA =>
     {
         TValue valueB;
         return dictB.TryGetValue(kvpA.Key, out valueB) && Equals(kvpA.Value, valueB);
     }));
 }
コード例 #5
0
 public static bool DictionaryEqual <TKey, TVal>(this IReadOnlyDictionary <TKey, TVal> dictionary1, IReadOnlyDictionary <TKey, TVal> dictionary2)
 {
     if (dictionary1 == null)
     {
         throw new ArgumentNullException("dictionary1");
     }
     if (dictionary2 == null)
     {
         throw new ArgumentNullException("dictionary2");
     }
     return(dictionary1.Count == dictionary2.Count &&
            dictionary1.All(dictionary2.Contains));
 }
コード例 #6
0
        public ComposedPart(ComposablePartDefinition definition, IReadOnlyDictionary <ImportDefinitionBinding, IReadOnlyList <ExportDefinitionBinding> > satisfyingExports, IImmutableSet <string> requiredSharingBoundaries)
        {
            Requires.NotNull(definition, nameof(definition));
            Requires.NotNull(satisfyingExports, nameof(satisfyingExports));
            Requires.NotNull(requiredSharingBoundaries, nameof(requiredSharingBoundaries));

#if DEBUG   // These checks are expensive. Don't do them in production.
            // Make sure we have entries for every import.
            Requires.Argument(satisfyingExports.Count == definition.Imports.Count() && definition.Imports.All(d => satisfyingExports.ContainsKey(d)), "satisfyingExports", Strings.ExactlyOneEntryForEveryImport);
            Requires.Argument(satisfyingExports.All(kv => kv.Value != null), "satisfyingExports", Strings.AllValuesMustBeNonNull);
#endif

            this.Definition                = definition;
            this.SatisfyingExports         = satisfyingExports;
            this.RequiredSharingBoundaries = requiredSharingBoundaries;
        }
コード例 #7
0
 static public bool IsSubsetOf <TKey, TValue>(this IReadOnlyDictionary <TKey, TValue> _this, IReadOnlyDictionary <TKey, TValue> other, IEqualityComparer <TKey> keyComparer, IEqualityComparer <TValue> valueComparer)
 {
     return(_this.All
            (
                x =>
     {
         if (!other.ContainsKey(x.Key))
         {
             return false;
         }
         else
         {
             var otherVal = other[x.Key];
             return valueComparer.Equals(x.Value, otherVal);
         }
     }
            ));
 }
コード例 #8
0
ファイル: TagHelper.cs プロジェクト: alanta/azure_scheduler
 public static bool HasTags(this IResource resource, IReadOnlyDictionary <string, string> tags)
 {
     return(tags.All(t => resource.HasTag(t.Key, t.Value)));
 }
コード例 #9
0
 public static bool KeysEquals <TK, TV>(this IReadOnlyDictionary <TK, TV> first, IReadOnlyDictionary <TK, TV> second) => first.All(kvp => second.ContainsKey(kvp.Key)) && second.All(kvp => first.ContainsKey(kvp.Key));
コード例 #10
0
 public static bool Equals <TK, TV>(this IReadOnlyDictionary <TK, TV> first, IReadOnlyDictionary <TK, TV> second) => first.All(kvp => second.ContainsKey(kvp.Key) && second[kvp.Key].Equals(kvp.Value)) && second.All(kvp => first.ContainsKey(kvp.Key) && first[kvp.Key].Equals(kvp.Value));
コード例 #11
0
        public static ParserResult Parse(string file)
        {
            ParserResult result = new();
            var          lines  = File.ReadAllLines(file);

            for (var index = 0; index < lines.Length; index++)
            {
                var line = lines[index];
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                if (line.StartsWith("КОММЕНТАРИЙ:"))
                {
                    continue;
                }
                if (InstructionTypes.All(i => !line.StartsWith(i.Key)))
                {
                    Program.WriteError($"\nfile: {file}\nline {index + 1}: unknown instruction.");
                    Environment.Exit(1);
                }
                else
                {
                    var name = InstructionTypes.First(i => line.StartsWith(i.Key));
                    var ins  = (Instruction)Activator.CreateInstance(name.Value) !;
                    ins.Parameters = line.Split(" ").Skip(1).ToList();
                    ins.Line       = index;
                    ins.PrepareForExecution();
                    var check = ins.CheckValid(line);
                    if (check == "valid")
                    {
                        result.Instructions.Add(ins);
                    }
                    else
                    {
                        Program.WriteError($"\nfile: {file}\nline {index + 1}: {check}");
                        Environment.Exit(1);
                    }
                }
            }

            foreach (var variable in from instruction in result.Instructions.ToList() where instruction is Create && instruction.Parameters[0] == "ПЕРЕМЕННУЮ" select _parseVariable(ref result.Instructions, instruction) into variable where variable != null select variable)
            {
                if (variable != null)
                {
                    result.Variables.Add(variable);
                }
            }
            foreach (var method in from instruction in result.Instructions.ToList()
                     where instruction is Create && instruction.Parameters[0] == "МЕТОД"
                     select _parseMethod(ref result.Instructions, instruction)
                     into method
                     where method != null
                     select method)
            {
                if (method != null)
                {
                    result.Methods.Add(method);
                }
            }
            foreach (var @class in from instruction in result.Instructions.ToList()
                     where instruction is Create && instruction.Parameters[0] == "КЛАСС"
                     select new AnatoliyClass())
            {
                var createLine = result.Instructions.First(i => i is Create && i.Parameters[0] == "КЛАСС");
                var end        = result.Instructions.First(i => i.Line > createLine.Line && i is End);
                foreach (var m in result.Methods)
                {
                    @class.Methods.Add(m.Name, m);
                }
                @class.Namespace = createLine.Parameters[2];
                @class.Name      = createLine.Parameters[1];
                result.Classes.Add(@class);
                var endIndex = end.Line == result.Instructions.Count ? end.Line : end.Line + 1;
                _removeInstructionFrom(ref result.Instructions, createLine.Line, endIndex);
            }

            return(result);
        }
コード例 #12
0
ファイル: MimeTypeProvider.cs プロジェクト: Jark/restup
        public MimeTypeProvider(IReadOnlyDictionary<string, string> mimeTypesByExtension)
        {
            if (!mimeTypesByExtension.All(x => x.Key.StartsWith(".")))
                throw new Exception("The keys in the dictionary needs to all start with a '.'");

            this.mimeTypesByExtension = mimeTypesByExtension.ToImmutableDictionary(StringComparer.OrdinalIgnoreCase);
        }