readonly

How to set some field in model as readonly when a condition is met?

I have models like this: class Person has_many :phones ... end class Phone belongs_to :person end I want to forbid changing phones associated to person when some condition is met. Forbidden field is set to disabled in html form. When I added a custom validation to check it, it caused save error even when phone doesn't change. I...

Readonly connections with ADO.NET, SQLite and TSQL

My code reads via one connection and writes via another. I dont want to accidentally write with the read connection. How can i make the connection readonly? I am using SQLite ATM and will convert sections of code to tsql when the prototype is over. ...

Read/Write Python Closures

Closures are an incredibly useful language feature. They let us do clever things that would otherwise take a lot of code, and often enable us to write code that is more elegant and more clear. In Python, closures are read-only affairs; that is, a function defined inside another lexical scope cannot change variables outside of its local...

What's the correct way to ship static (read-only) data in Core Data persistent store?

I want to ship static read-only data for use in my Core Data model. The problem is that there are obviously different persistent store types and I don't know if the format of those types is supposed to be opaque or if I'm supposed to be able to construct them by hand. Right now I just have a plist and it's very small (maybe 30 entries t...

How can a readonly static field be null?

So here's an excerpt from one of my classes: [ThreadStatic] readonly static private AccountManager _instance = new AccountManager(); private AccountManager() { } static public AccountManager Instance { get { return _instance; } } As you can see, it's a singleton-per-thread - i.e. the instance ...

How can I make a property "Write Once Read Many" in VB.NET?

What is the best way to make a class property "Write Once, Read Many" such that you can only set the property once? I know that I could pass all the properties in the constructor and make them ReadOnly, but in cases with a lot of properties I don't want a constructor that has 20+ arguments. Also, I realize I can "roll my own" setters, ...

Greasemonkey to Change Readonly from True to Flase

trying to change a websites text entry field that is currently set to read only to false. The reason being it has an 'Upload" button where you browse to the file on your computer then hit upload. I just want to set the path in a script but since the text field is read only i cannot. Any other ideas would be appreciated. thanks ...

How do I set the FCKEditor to be readonly?

I am using FCKEditor ASP.NET control 2.65 in my WebForms application. How can I set it to be readonly (preferably from the serverside)? I am not seeing either Enabled or Readonly properties. Am I missing something really simple? ...

How to lock/unlock a field at runtime in C#?

Can I lock/unlock fields or objects at runtime against writing? In other words something like changing objects to read-only temporarily at runtime... For example: int x = 5; // x is 5 LockObject(x); x = 7; // no change UnlockObject(x); x = 10; // x is 10 if not can you give me some possible solutions? ...

Compiler-Implemented Immutability in .Net

Given this class... public class Test { private long _id; public Test(long id) { _id = id; } } Will the .Net compiler actually compile it as... public class Test { private readonly long _id; public Test(long id) { _id = id; } } In other words, does it understand that _id is only ever set from the construct...

Why is there no IArray(T) interface in .NET?

Question (in short): I asked why .NET has IList<T>, which implements ICollection<T> and therefore provides methods to modify the list (Add, Remove, etc.), but doesn't offer any in-between interface such as IArray<T> to provide random access by index without any list modification. EDIT 2010-Jan-21 2:22 PM EST: In a comment to Jon Skeet...

What's the best way of creating a readonly array in C#?

I've got the extremely unlikely and original situation of wanting to return a readonly array from my property. So far I'm only aware of one way of doing it - through the System.Collections.ObjectModel.ReadOnlyCollection<T>. But that seems somehow awkward to me, not to mention that this class loses the ability to access array elements by ...

Regarding C# Static Readonly members

I have the following situation. There is some very common class in my application that contains a static readonly field called "BinDirectory" that holds the path to the bin directory. Other fields in this class, which are static readonly too, use this value to as a base to their value. On the current version BinDirectory is initialized t...

How to Refresh ReadOnly property bound to a DataGrid

Hi All, A have an Order class with a ReadOnly TotalPrice property that calcutaltes from other properties of the class. Throught an ObservableCollection I make a binding to a DataGrid. The code is below. Order Class public class Order { public String Name { get; set; } public Double Price { get; set; } public Int32 Quantity...

Immutable readonly reference types & FXCop Violation: Do not declare read only mutable reference types

I have been trying to wrap my head around this FXCop violation "DoNotDeclareReadOnlyMutableReferenceTypes" MSDN: http://msdn.microsoft.com/en-us/library/ms182302%28VS.80%29.aspx Code from MSDN which would cause this violation: namespace SecurityLibrary { public class MutableReferenceTypes { static protected readonly St...

UITypeEditor and readonly reference type properties in .Net, WinForms

I thought I had type editors and converters nailed until I tried to persist a Readonly Reference type property after editing it in a UITypeEditor. In my UITypeEditor, because I'm working with a read only property, I'm careful to pass back the original value (after updating the relevant sub property). This change is reflected immediatel...

Readonly PropertyGrid

I'm using a PropertyGrid in an application I am writing to allow users to view and sometimes edit instances of my objects. Sometimes the user may have a file open in read/write mode where they can make changes to the file through the property grid. In other cases they may have a file open in read only mode, and should not be able to make...

Remove readonly of Folder from c#

How can i programatically remove the readonly attribute of folder from c# code ? ...

SqlAlchemy optimizations for read-only object models.

I have a complex network of objects being spawned from a sqlite database using sqlalchemy ORM mappings. I have quite a few deeply nested: for parent in owner.collection: for child in parent.collection: for foo in child.collection: do lots of calcs with foo.property My profiling is showing me that the sqlalc...

C#: Can parameters be constant?

I'm looking for the C# equivalent of Java's final. Does it exist? Does C# have anything like the following: public Foo(final int bar); In the above example, bar is a read only variable and cannot be changed by Foo(). Is there any way to do this in C#? For instance, maybe I have a long method that will be working with x, y, and z coo...