Questions tagged [readonly-attribute]
99 questions
125
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
- 197,032
- 96
- 389
- 477
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
{
…
BART
- 1,168
- 7
- 15
23
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
- 20,455
- 32
- 134
- 223
22
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
- 33,993
- 56
- 155
- 263
21
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
- 251
- 1
- 3
- 8
19
votes
2 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
- 2,749
- 6
- 14
- 17
18
votes
6 answers
Is there a difference between readonly and { get; }
Do these statements mean the same thing?
int x { get; }
readonly int x;
Bob
- 207
- 1
- 4
- 10
17
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
- 429
- 12
- 25
16
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,232
- 1
- 12
- 19
16
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
- 17,763
- 14
- 122
- 177
13
votes
3 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
- 393
- 1
- 5
- 14
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…
John Ding
- 1,283
- 3
- 16
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
8
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,407
- 3
- 14
- 26
7
votes
4 answers
readonly properties and ngOnInit
Readonly properties can only be assigned in the constructor, but in angular it is discouraged and sometimes impossible to use the constructor for certain initialization and instead the angular hook ngOnInit is used.
Is there any way to mark ngOnInit…
Simon Hirsig
- 73
- 5