Questions tagged [readonly-attribute]
126 questions
131
votes
7 answers
How to create a readonly textbox in ASP.NET MVC3 Razor
How do I create a readonly textbox in ASP.NET MVC3 with the Razor view engine?
Is there an HTMLHelper method available to do that?
Something like the following?
@Html.ReadOnlyTextBoxFor(m => m.userCode)

Shyju
- 214,206
- 104
- 411
- 497
32
votes
1 answer
Does the 'readonly' modifier create a hidden copy of a field?
The only difference between MutableSlab and ImmutableSlab implementations is the readonly modifier applied on the handle field:
using System;
using System.Runtime.InteropServices;
public class Program
{
class MutableSlab : IDisposable
{
…
user6440521
26
votes
4 answers
WTForms support for input readonly attribute?
Here they say it's not supported out of the box.
Do you know a way to make HTML input form fields use the 'readonly' attribute with WTForms?

casual
- 313
- 1
- 4
- 8
25
votes
5 answers
python, __slots__, and "attribute is read-only"
I want to create an object in python that has a few attributes and I want to protect myself from accidentally using the wrong attribute name. The code is as follows:
class MyClass( object ) :
m = None # my attribute
__slots__ = ( "m" ) #…

grigoryvp
- 40,413
- 64
- 174
- 277
25
votes
7 answers
How can I make a read only version of a class?
I have a class with various public properties which I allow users to edit through a property grid. For persistence this class is also serialized/deserialized to/from an XML file through DataContractSerializer.
Sometimes I want to user to be able to…

Eric Anastas
- 21,675
- 38
- 142
- 236
22
votes
3 answers
Autofixture and read only properties
Let's consider two version (one with read only properties) of the same very simple entity:
public class Client
{
public Guid Id { get; set; }
public string Name { get; set; }
}
vs
public class Client
{
public Client(Guid id, string…

Marcin Konrad Ceglarek
- 1,442
- 2
- 13
- 20
22
votes
2 answers
Set a Read-Only Attribute in Python?
Given how dynamic Python is, I'll be shocked if this isn't somehow possible:
I would like to change the implementation of sys.stdout.write.
I got the idea from this answer to another question of mine: https://stackoverflow.com/a/24492990/901641
I…

ArtOfWarfare
- 20,617
- 19
- 137
- 193
21
votes
3 answers
react bootstrap readonly input within formcontrol
I am using react bootstrap and this framework provides some nice FormControls.
But I would like to make the Input field that is generated within the FormControls to have a prop of readonly="readonly". This way, this field looks the same as my other…

user3611459
- 3,311
- 6
- 16
- 18
19
votes
7 answers
Is there a difference between readonly and { get; }
Do these statements mean the same thing?
int x { get; }
readonly int x;

Bob
- 217
- 1
- 4
- 11
18
votes
5 answers
Assign value to `readonly` properties from methods called by the constructor
I have a simple class, and I want to assign a value to a readonly property in a method initiated by the constructor, but it says [ts] Cannot assign to 'readOnlyProperty' because it is a constant or a read-only property.
Why can't I assign a value to…

Bill
- 553
- 1
- 7
- 19
18
votes
3 answers
Ace Editor: Lock or Readonly Code Segment
Using the Ace Code Editor can I lock or make readonly a segment of code but still allow other lines of code to be written or edited during a session?

Chris
- 469
- 12
- 25
12
votes
2 answers
How to Setup a readonly property with Moq?
I am trying to unit test using Moq. Here is the example code:
public class ConcreteClass
{
private readonly FirstPropery firstProperty;
private readonly SecondProperty secondProperty;
public ConcreteClass(firstProperty, secondProperty)
…

M.Tach
- 143
- 1
- 1
- 8
9
votes
2 answers
PropertyGrid readonly property on object-level
I want to display multiple instances of one class in my PropertyGrid. The class looks like this:
public class Parameter
{
[Description("the name")]
public string Name { get; set; }
[Description("the value"), ReadOnly(true)]
public…

reflective_mind
- 1,475
- 3
- 15
- 28
8
votes
1 answer
Can pointers be used to modify readonly field? But why?
I come from C++ and find a very different behavior between pointers in C++ and C#.
I surprisingly find this code compiles... And even... Works perfectly.
class C
{
private readonly int x = 0;
unsafe public void Edit()
{
fixed…

con ko
- 1,368
- 5
- 18
8
votes
1 answer
Android Studio : Unable to add a new class or any file to a project
My Android was working perfectly and was able to add a new xml,activity or any new file to my project. Until recently, it gives an error whenever I add a new class or any new file. It always says:
Unable to parse template "Class" Error message:…

Jaye
- 132
- 1
- 10