Questions tagged [readonly-collection]

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

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

105 questions
2
votes
1 answer

Expose IList or ReadOnlyCollection for Read-Only Property?

I realize that since .NET 4.5 that the ReadOnlyCollection class implements the new interface IReadOnlyCollection but I am constrained to an older version of the library which doesn't have this. I would like to know which of the better is…
Lea Hayes
  • 62,536
  • 16
  • 62
  • 111
2
votes
1 answer

Serialize read-only collection without implementing IXmlSerializable

I have a class : [Serializable] public class Profile { [XmlAttribute] private string[] permissions; public string[] Permissions { get { return permissions; } set { permissions = value; } } } I want to serialize…
Peekyou
  • 471
  • 1
  • 5
  • 21
1
vote
1 answer

Issue when using only a getter and issue with List in c#

I'm working on an application that uses a list to handle previous guesses from the user. Below is the (private) list and the property for accessing the list. To prevent privacy leak i'm using a ReadOnlyCollection, which is also the reason for me…
holyredbeard
  • 19,619
  • 32
  • 105
  • 171
1
vote
2 answers

Can ReadOnlyDictionary be used when only the values are changing?

I know ReadOnlyDictionary is "thread-safe" when accessing from multiple threads as long as the collection isn't changing. But what if the collection isn't changing (no keys are ever added/removed) and values are thread-safe by themselves, meaning,…
1
vote
2 answers

Typesafe effectively read only java collections?

I'm searching for a java library for collections with no methods that allow for mutations. effectively immutable read only collections. By that I mean, NO METHODS. Not like the usual Java immutable collections that have methods like add or remove…
caeus
  • 3,084
  • 1
  • 22
  • 36
1
vote
0 answers

Clicking IOS "Update Contact" (Name and Photo from texts) breaks radicale read only client connection

Goal: To have a single radicale account that is read only and distributed to approximately 500 users. Server is on Debian 10 behind Apache2 Users having issues are on IOS 13 or 14 Results: After referencing JSzaszvari in the radicale github I have…
Neib
  • 11
  • 2
1
vote
5 answers

object[] from ReadOnlyCollection

I have an object that I ended up with via a reflection call: object readOnlyCollectionObject = propertyInfo.GetValue(someEntity, null); I know this object is a generic ReadOnlycollection. It could be a ReadOnlyCollection,…
hkdk3107
  • 13
  • 2
  • 7
1
vote
2 answers

List.of() — Why offer an empty list of elements that can't be add/removed/edited?

One of the Java 9 features I've tested is the List.of() to create an unmodifiable list. I wonder - What is the purpose of this method if it returns an empty list of elements that can't be add / removed / edited? The only thing that i was able to…
Fima Taf
  • 929
  • 9
  • 22
1
vote
1 answer

Is it possible to modify a ReadOnlyCollection using reflection

I'm dealing with an SDK that keeps references to every object it creates, as long as the main connection object is in scope. Creating a new connection object periodically results in other resource issues, and is not an option. To do what I need to…
user467384
  • 1,137
  • 4
  • 22
  • 38
1
vote
7 answers

A ReadOnlyCollection isn't readonly. How do i create a true ReadOnlyCollection?

I'm aware that readonly collection prevents adding/removing from a list but why doesn't it prevent the setting of properties of objects in the collection. System.Collections.ObjectModel.ReadOnlyCollection ReadOnlyPhoneNumbers =…
Al Polden
  • 890
  • 11
  • 25
1
vote
1 answer

C# convert ReadOnlyCollection to byte[] array

Given a read only collection of ints, how do I convert it to a byte array? ReadOnlyCollection collection = new List { 118,48,46,56,46,50 }.AsReadOnly(); //v0.8.2 What will an elegant way to convert 'collection' to byte[] ?
Rotem Varon
  • 1,597
  • 1
  • 15
  • 32
1
vote
3 answers

IList> to IReadonlyCollection>

I have a list of string array and I would like to make both collection read-only. So I have this code: public XmlPatternTree(IList nodeNames, IList> attributeNames, IList> attributeValues) : this() { …
Toto
  • 736
  • 9
  • 33
1
vote
1 answer

NHibernate: use of IEnumerable as collection type results in error

I have a class which uses an ISet as a collection type as below: public class Client { private ISet _contacts = new HashedSet(); public virtual ISet Contacts { get { return _contacts; } } } I don't want the…
David
  • 15,750
  • 22
  • 90
  • 150
1
vote
1 answer

Difference between ReadOnlyDictionary and Lookup in .Net

I'm still learning much about immutability and when to use such objects and have started incorporating more Lookups into my coding for the fact that I knew them to be immutable and, hence, often better to use than Dictionaries that could be changed…
John Bustos
  • 19,036
  • 17
  • 89
  • 151
1
vote
1 answer

Why does List.AsReadOnly return a ReadOnlyCollection but Dictionary.AsReadOnly returns an IReadOnlyDictionary?

I ran into a case where the fact that List.AsReadOnly() returns a ReadOnlyCollection instead of an IReadOnlyCollection made things hard for me. Since the returned collection was the Value of a Dictionary, it could not be automatically upcast to an…
ErikE
  • 48,881
  • 23
  • 151
  • 196