Questions tagged [readonly-collection]

Represents a strongly-typed, read-only collection of elements.

Represents a strongly-typed, read-only collection of elements.

105 questions
1
vote
0 answers

Not desire behave of IWebElement List

I want to obtain the 'text' attribute of all the objects in a IWebElement list, when I create a loop to go throught that list extracting the text of each element, I obtain the text of a few. var synonymList = new List(); if…
Handresito
  • 11
  • 5
1
vote
4 answers

Is there an easy way to have a dictionary-like object that cannot be added to, but whose values can be modified?

Suppose I have a class Composite that is constructed from a dictionary of instruments and weights. public IReadOnlyDictionary Underlyings{ get; private set; } public Composite( Id id, Currency currency, …
Eric Hansen
  • 1,749
  • 2
  • 19
  • 39
1
vote
3 answers

FxCop CA2227 warning and ReadOnlyCollection

In my VS2008 SP1, .NET 3.5 SP1 project, I have different classes that contain different properties. I use C#3.0 auto properties a lot. Some of these properties need to be collections. Since I want to make it simple, I use ReadOnlyCollection for…
1
vote
2 answers

Return an ICollection as IReadOnlyCollection?

I have a field of type ICollection. Is there a simple way to make it read only? Note, the ReadOnlyCollection class takes an IList, I'm looking for a way to invert an ICollection and ensure user cannot alter the collection. Using…
Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
1
vote
4 answers

Add to a readonly collection in a constructor?

Is there a c# language construct that will allow me to add items to a readonly collection property in a constructor? I want to do something like this: public class Node{ public IList Children {get; protected set;} public Node(){ …
Jeremy Holovacs
  • 22,480
  • 33
  • 117
  • 254
1
vote
3 answers

Retrieved Dictionary Key Not Found

I have a SortedDictionary declared like such: SortedDictionary dict = new SortedDictionary(); When its populated with values, if I grab any key from the dictionary and then try to reference it…
Joel B
  • 12,082
  • 10
  • 61
  • 69
1
vote
2 answers

HashSet vs HashedSet (Iesi): strange behavior

Today I was testing a couple of things on my domain model and I have realized the behavior wasn't what I expected. I have tried to isolate the problem creating a simple Customers-Orders model. This is my mapping. Customer:
LeftyX
  • 35,328
  • 21
  • 132
  • 193
1
vote
2 answers

How do I configure my collection as not read-only using FluentNhibernate?

I've tried everything I can think of here and I'm just stuck. I have a User that has many Invitations but when I try to add an Invitation to the invitations field of the User by calling AddInvitation() a NotSupported exception is thrown because the…
0
votes
0 answers

Why does C# `List` implements `IReadOnlyCollection`?

By looking at the documentation, between .NET Framework v4.0 and v4.5 the List started implementing the IReadOnlyCollection interface. The documentation of IReadOnlyCollection says: Represents a strongly-typed, read-only collection of…
alelom
  • 2,130
  • 3
  • 26
  • 38
0
votes
1 answer

Hibernate readonly collection mapping

I'm taking the following many-to-many mapping example from this Hibernate Mapping Cheat Sheet: ...
BenMorel
  • 34,448
  • 50
  • 182
  • 322
0
votes
0 answers

Getting ObjectModel.ReadOnlyCollection for foreach

I want to get the values and keys of the Object. First I cast it and then put it on the foreach loop to get keys and values. object itemAttributes = web.javaScriptExecutor().ExecuteScript($"return window.INITIAL_STATE.items.itemAttributes") …
D.JCode
  • 386
  • 2
  • 12
0
votes
2 answers

How to use ExceptWith with the type of HashSet> in C#?

HashSet> test1 = new HashSet> (); for (int i = 0; i < 10; i++) { List temp = new List (); for (int j = 1; j < 2; j++) { temp.Add (i); temp.Add (j); } test1.Add…
lynkewsw
  • 5
  • 3
0
votes
1 answer

Creating an immutable collection structure from existing hierarchical structure

I have an object that stores hierarchical data. I have successfully been able to create the structure I need from a flat structure, but this required me to use List<> which isn't immutable (I want to use IReadOnlyList). Now I can't really get my…
silkfire
  • 24,585
  • 15
  • 82
  • 105
0
votes
1 answer

Fluent NHibernate Correctly map readonly property from base class

I want to create a base class for some of my entities, since they all share a Event list property. I want also to make the Event list a readonly property. So I created a base EventRelatedEntity class and then derived it on each of my entity class…
Cheshire Cat
  • 1,941
  • 6
  • 36
  • 69
0
votes
2 answers

c# - How to count the number of occurences of a string in a ReadOnlyCollection field

I have a ReadOnlyCollection of a Smartcard type from Microsoft.Clm.Shared.Smartcards namespace. one of the fields/parameters of the smartcard object is AssingnedUserName. I need to be able to count how many times a smartcard with the same username…
David Gidony
  • 1,243
  • 3
  • 16
  • 31