public override bool Equals(object obj) { if (ReferenceEquals(this, obj)) { return(true); } var proxyGenerationOptions = obj as ProxyGenerationOptions; if (ReferenceEquals(proxyGenerationOptions, null)) { return(false); } // ensure initialization before accessing MixinData Initialize(); proxyGenerationOptions.Initialize(); if (!Equals(Hook, proxyGenerationOptions.Hook)) { return(false); } if (!Equals(Selector == null, proxyGenerationOptions.Selector == null)) { return(false); } if (!Equals(MixinData, proxyGenerationOptions.MixinData)) { return(false); } return(BaseTypeForInterfaceProxy == proxyGenerationOptions.BaseTypeForInterfaceProxy && CollectionExtensions.AreEquivalent(AdditionalAttributes, proxyGenerationOptions.AdditionalAttributes)); }
static void DoPropagate(ILVariable v, ILInstruction copiedExpr, Block block, ref int i, ILTransformContext context) { context.Step($"Copy propagate {v.Name}", copiedExpr); // un-inline the arguments of the ldArg instruction ILVariable[] uninlinedArgs = new ILVariable[copiedExpr.Children.Count]; for (int j = 0; j < uninlinedArgs.Length; j++) { var arg = copiedExpr.Children[j]; var type = context.TypeSystem.Compilation.FindType(arg.ResultType.ToKnownTypeCode()); uninlinedArgs[j] = new ILVariable(VariableKind.StackSlot, type, arg.ResultType, arg.ILRange.Start) { Name = "C_" + arg.ILRange.Start }; block.Instructions.Insert(i++, new StLoc(uninlinedArgs[j], arg)); } CollectionExtensions.AddRange(v.Function.Variables, uninlinedArgs); // perform copy propagation: foreach (var expr in v.LoadInstructions.ToArray()) { var clone = copiedExpr.Clone(); for (int j = 0; j < uninlinedArgs.Length; j++) { clone.Children[j].ReplaceWith(new LdLoc(uninlinedArgs[j])); } expr.ReplaceWith(clone); } block.Instructions.RemoveAt(i); int c = ILInlining.InlineInto(block, i, InliningOptions.None, context: context); i -= c + 1; }
public async static Task <TagInformation> CreateTagInfoForCD(int drive, int track) { var title = CollectionExtensions.GetValueOrFallback(CDInfoProvider.CdData, $"TITLE{track + 1}", "Unknown song"); var artist = CollectionExtensions.GetValueOrFallback(CDInfoProvider.CdData, $"PERFORMER{track + 1}", "Unknown artist"); var album = CollectionExtensions.GetValueOrFallback(CDInfoProvider.CdData, $"PERFORMER{0}", "Unknown"); album += " - " + CollectionExtensions.GetValueOrFallback(CDInfoProvider.CdData, $"TITLE{0}", ""); var ret = new TagInformation { FileName = $"CD track {track + 1}, on Drive: {drive}", Title = title, Artist = artist, Year = "unknown", Album = album }; if (title != "Unknown song") { var bytes = await iTunesCoverDownloader.GetCoverFor($"{artist} - {title}"); if (bytes != null) { ret.Cover = iTunesCoverDownloader.CreateBitmap(bytes); } } else { ret.Cover = new BitmapImage(ResourceLocator.GetIcon(IconCategories.Big, "icons8-cd-540.png")); } return(ret); }
public void GroupIf_NullGroupPredicate_ThrowsArgumentNullException() { IEnumerable <int> collection = Enumerable.Range(0, 10); Func <int, int, bool> groupPredicate = null; Assert.Throws <ArgumentNullException>(() => CollectionExtensions.GroupIf(collection, groupPredicate)); }
public void GetEnumerator_CollectionWithGroups_ReturnsCorrectResults() { var collection = new[] { 1, 2, 3, 4, 5, 7, 10, 11, 13, 15, 17, 18, 19 }; var output = CollectionExtensions.AggregateIf(collection, (prev, current) => current == prev + 1, () => string.Empty, (aggregator, element) => (aggregator + ", " + element).TrimStart(',', ' '), aggregator => aggregator).ToList(); CollectionAssert.AreEqual(new[] { "1, 2, 3, 4, 5", "7", "10, 11", "13", "15", "17, 18, 19" }, output); }
public void GroupIf_NullCollection_ThrowsArgumentNullException() { IEnumerable <int> collection = null; Func <int, int, bool> groupPredicate = (i1, i2) => i2 == i1 + 1; Assert.Throws <ArgumentNullException>(() => CollectionExtensions.GroupIf(collection, groupPredicate)); }
private void ResolveIssuers(X509Certificate2 certificate, X509Certificate2Collection issuers, int chainLength) { // // only look at simpleNames because intermediates are always going to be org-level, not email, certs // string issuerName = certificate.GetNameInfo(X509NameType.SimpleName, true); // true == "for issuer" // // If the issuer name matches the Cert name, we have a self-signed cert // if (certificate.MatchName(issuerName)) { return; } // // If the issuer is already known, then we are good // if (issuers.FindByName(issuerName) != null) { return; } if (chainLength == m_maxIssuerChainLength) { // // Chain too long. Ignore... // return; } // // Retrieve the issuer's certificate // X509Certificate2Collection issuerCertificates = IssuerResolver.SafeGetCertificates(certificate.ExtractEmailNameOrName(true)); if (CollectionExtensions.IsNullOrEmpty(issuerCertificates)) { return; } // // Recursively fetch the issuers who issued this set of certificates // foreach (X509Certificate2 issuerCertificate in issuerCertificates) { if (issuerCertificate.MatchName(issuerName) && !issuers.ContainsThumbprint(issuerCertificate.Thumbprint)) { // // New issuer // issuers.Add(issuerCertificate); // // And keep working up the chain // this.ResolveIssuers(issuerCertificate, issuers, chainLength + 1); } } }
public void MultipleActionsWithoutSuspendingNotifications() { var counter = 0; var fastCollection = new FastObservableCollection <int>(); fastCollection.AutomaticallyDispatchChangeNotifications = false; fastCollection.CollectionChanged += (sender, e) => counter++; fastCollection.Add(0); fastCollection.Add(1); fastCollection.Remove(0); fastCollection.Remove(1); CollectionExtensions.AddRange(((ICollection <int>)fastCollection), new[] { 1, 2 }); fastCollection[0] = 5; fastCollection.Move(0, 1); fastCollection.Clear(); Assert.AreEqual(9, counter); }
public async Task <NLogItemEntity> UpsertAsync(object item) { var bucket = await _provider.GetBucketAsync(_options.Bucket); NLogItemEntity nLogItemEntity; try { var configContent = await CollectionExtensions.GetAsync(bucket.DefaultCollection(), _options.ConfigId); nLogItemEntity = configContent.ContentAs <NLogItemEntity>(); } catch (DocumentNotFoundException e) { nLogItemEntity = new NLogItemEntity(); nLogItemEntity.CreationDate = DateTime.UtcNow; } nLogItemEntity.LastModifiedDate = DateTime.Now; nLogItemEntity.Config = item; await bucket.DefaultCollection().UpsertAsync(_options.ConfigId, nLogItemEntity); return(nLogItemEntity); }
private dynamic LoadTable(dynamic table) { if (table is IList <object> list) { var result = new List <dynamic>(list.Count); foreach (var item in list) { result.Add(LoadValue(item)); } return(result.ToArray()); } else if (table is IDictionary <string, object> obj) { var result = new ExpandoObject(); foreach (var pair in obj) { var key = pair.Key; if (key != null) { CollectionExtensions.TryAdd(result, key, LoadValue(pair.Value)); } } return(result); } else { throw new InvalidCastException("Invalid dynamic type"); } }
private dynamic LoadTable(Table table) { if (table.Keys.All(x => x.Type == DataType.Number)) { var result = new List <dynamic>(table.Length); foreach (var pair in table.Pairs) { if (pair.Value != null && pair.Value.Type != DataType.Nil) { result.Add(LoadValue(pair.Value)); } } return(result.ToArray()); } else { var result = new ExpandoObject(); foreach (var pair in table.Pairs) { if (!IsSerializable(pair.Value)) { continue; } if (pair.Key.Type != DataType.Number && pair.Key.Type != DataType.String) { continue; } var key = pair.Key.String ?? pair.Key.Number.ToString(CultureInfo.InvariantCulture); CollectionExtensions.TryAdd(result, key, LoadValue(pair.Value)); } return(result); } }
public void TestDictEquals() { var dic1 = new Dictionary <string, string> { { "linux", "good" }, { "macos", "bad" }, { "windows", "ugly" } }; var dic2 = new Dictionary <string, string> { { "linux", "good" }, { "freebsd", "correct" }, { "macos", "bad" }, { "windows", "ugly" } }; var dic3 = new Dictionary <string, string> { { "linux", "good" }, { "freebsd", "correct" }, { "windows", "ugly" } }; var dic4 = new Dictionary <string, string> { { "linux", "good" }, { "macos", "bad" }, { "windows", "awful" } }; var dic5 = new Dictionary <string, string> { { "linux", "good" }, { "macos", "bad" }, { "windows", null } }; var dic6 = new Dictionary <string, string> { { "linux", "good" }, { "macos", "bad" }, { "windows", "ugly" } }; Assert.True(CollectionExtensions.DictEquals((IDictionary <string, string>)null, (IDictionary <string, string>)null)); Assert.False(CollectionExtensions.DictEquals((IDictionary <string, string>)null, dic1)); Assert.False(dic1.DictEquals(null)); Assert.False(dic1.DictEquals(dic2)); Assert.False(dic1.DictEquals(dic3)); Assert.False(dic1.DictEquals(dic4)); Assert.False(dic1.DictEquals(dic5)); Assert.True(dic1.DictEquals(dic6)); }
public void BuildUp(FilterInfo filters) { CollectionExtensions.ForEach(filters.ActionFilters, Container.Kernel.InjectProperties); CollectionExtensions.ForEach(filters.AuthorizationFilters, Container.Kernel.InjectProperties); CollectionExtensions.ForEach(filters.ExceptionFilters, Container.Kernel.InjectProperties); CollectionExtensions.ForEach(filters.ResultFilters, Container.Kernel.InjectProperties); }
protected override void Execute() { var projectsFilter = new string[0]; if (projects.Count > 0) { Log.Debug("Loading projects..."); projectsFilter = Repository.Projects.FindByNames(projects.ToArray()).Select(p => p.Id).ToArray(); } var environmentsById = new Dictionary <string, string>(); if (environments.Count > 0) { Log.Debug("Loading environments..."); CollectionExtensions.AddRange(environmentsById, Repository.Environments.FindByNames(environments.ToArray()).Select(p => new KeyValuePair <string, string>(p.Id, p.Name))); } else { CollectionExtensions.AddRange(environmentsById, Repository.Environments.FindAll().Select(p => new KeyValuePair <string, string>(p.Id, p.Name))); } var deployments = Repository.Deployments.FindAll(projectsFilter, environments.Count > 0 ? environmentsById.Keys.ToArray() : new string[] {}); foreach (var deployment in deployments.Items) { LogDeploymentInfo(deployment, environmentsById); } }
public void Add(Player plr) { if (!CollectionExtensions.TryAdd(_players, plr.Account.Id, plr)) { throw new Exception("Player " + plr.Account.Id + "already exists"); } }
public void Leave(Player plr) { if (plr.Channel != this) { throw new ChannelException("Player is not in this channel"); } if (CollectionExtensions.Remove(_players, plr.Account.Id, out _)) { plr.Channel = null; try { if (Id > 0) { plr.SendAsync(new ServerResultAckMessage(ServerResult.ChannelLeave)); BroadcastLocationUpdate(plr); } } finally { Broadcast(new ChannelLeavePlayerAckMessage(plr.Account.Id)); OnPlayerLeft(new ChannelPlayerLeftEventArgs(this, plr)); } } }
void FillTreeList(ObservableCollection <LiteTreeViewItemViewModel> items, IList <LiteTreeViewItemViewModel> children, ref int myIndex) { if (items == null) { return; } ContainerList = items; if (children != null && children.Any()) { if (myIndex == -1) { myIndex = items.IndexOf(this); } if (IsOpen) { CollectionExtensions.InsertRange(items, myIndex + 1, children); foreach (var child in children) { ++myIndex; //items.Insert(myIndex, child); child.FillTreeList(items, ref myIndex); } } } }
public static void AddRange___Should_throw_ArgumentNullException___When_parameter_collection_is_null() { // Arrange var valuesToAdd = new List <int>(); // Act, Assert Assert.Throws <ArgumentNullException>(() => CollectionExtensions.AddRange(null, valuesToAdd)); }
public static void FirstOrNonePredicate_SourceNull_Throws(Func <int, bool> predicate) { var actual = Record.Exception(() => CollectionExtensions.FirstOrNone(null, predicate)); var ane = Assert.IsType <ArgumentNullException>(actual); Assert.Contains("source", ane.Message, Ordinal); }
public static void MapCat_NullValue_Throws(Func <int, Option <string> > mapper) { var actual = Record.Exception(() => CollectionExtensions.MapCat(null, mapper)); var ane = Assert.IsType <ArgumentNullException>(actual); Assert.Contains("enumerableValue", ane.Message, Ordinal); }
public static void FoldImplicit_NullValue_Throws(Func <int, int, int> folder) { var actual = Record.Exception(() => CollectionExtensions.Fold(null, folder)); var ane = Assert.IsType <ArgumentNullException>(actual); Assert.Contains("collection", ane.Message, Ordinal); }
public void NonNull_CollectionWithReferenceTypesButNoNullElements_ReturnsWholeCollection() { IEnumerable <string> collection = Enumerable.Range(0, 10).Select(idx => idx.ToString()).ToList(); var output = CollectionExtensions.NonNull(collection); CollectionAssert.AreEqual(collection, output); }
public void When_EmptyIfNull() { List <string> source = null; var expected = Enumerable.Empty <string>(); var actual = CollectionExtensions.EmptyIfNull(source); Assert.AreEqual(expected, actual); }
public void Append_NulladditionalElements_ThrowsArgumentNullException() { IEnumerable <int> collection = Enumerable.Range(0, 10); int[] additionalElements = null; Assert.Throws <ArgumentNullException>(() => CollectionExtensions.Append(collection, additionalElements)); }
private void dgvProjectUom_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { var headerText = dgvProjectUom.Columns[e.ColumnIndex].HeaderText; _projectUoms = CollectionExtensions.SortList(_projectUoms, projectUomColumnHeaderPropertyNameMap[headerText], ref _lastSortedAscendingBy); dgvProjectUom.Invalidate(); }
public void NonNull_CollectionWithValueTypes_ReturnsWholeCollection() { IEnumerable <int> collection = Enumerable.Range(0, 10).ToList(); var output = CollectionExtensions.NonNull(collection); CollectionAssert.AreEqual(collection, output); }
public void When_AddFluent_is_used_with_element_Then_element_is_added_and_collection_is_returned() { int element = 10; var list = new List <int>(); Assert.That(CollectionExtensions.Add(list, element), Is.EqualTo(list)); Assert.That(list.FirstOrDefault(), Is.EqualTo(element)); }
public void TestAddRange() { var people = new System.Collections.Generic.List <PersonProper>(); CollectionExtensions.AddRange <PersonProper>(people, base.personProperCollection.PickRandom(base.CollectionCount / 2), true); base.Consumer.Consume(people.Count); }
public void EqualRange_EmptyList(int value) { IReadOnlyList <Tuple <int> > list = new List <Tuple <int> >(); var range = CollectionExtensions.EqualRange( list, value, Compare); Assert.Equal(Enumerable.Empty <Tuple <int> >(), range); }
public void WeakPredecessor_EmptyList(int value, int expected) { IReadOnlyList <Tuple <int> > list = new List <Tuple <int> >(); int actual = CollectionExtensions.WeakPredecessor( list, value, Compare); Assert.Equal(expected, actual); }