readonly

Why is there no IsReadOnlyChanged event on TextBox controls?

喜你入骨 提交于 2019-12-07 22:52:28
I was adding some workaround code to fix the bug outlined in Is this a bug in DotNet 4 WPF Spell Checking? , (When a WPF TextBox changes Enabled, Visible or ReadOnly states, any SpellCheck custom dictionaries get dropped off until you disable and re-enable SpellCheck) and the simplest fix seemed to be to handle the IsVisibleChanged , IsEnabledChanged , and IsReadOnlyChanged events. Simple, right? Except there is no IsReadOnlyChanged event. Anybody know why and what the best way to trap a change to IsReadOnly in a WPF TextBox would be? Arsen Mkrtchyan You can always follow dependency property

How to access a selected Boundfield value from a GridView in code-behind

孤人 提交于 2019-12-07 09:33:42
问题 I have seen similar questions but none of the answers helped me to workout this problem. I have GridView with a ReadOnly field as follow. GridView: <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="projectID" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display." PageSize="5" OnRowUpdating="GridView1_RowUpdating"> <Columns> <asp:CommandField ShowDeleteButton="True" ShowEditButton="True"/> <asp:BoundField

How do I change the value of a static readonly field using reflection in c#?

白昼怎懂夜的黑 提交于 2019-12-07 06:44:46
问题 The SetFields method in the fieldInfo class takes objects as the first parameter. Is there a way to change the value of the static readonly fields using reflection in C#? So far I have var field = typeof(ClassName).GetField("FieldName",BindingFlags.Instance|BindingFlags.NonPublic); 回答1: If you want to get a static field then you should be using BindingFlags.Static instead of BindingFlags.Instance , as the latter is for instance fields. You can then use field.SetValue(null, newValue) to set

How do you create a unit-testing stub for an interface containing a read-only member?

无人久伴 提交于 2019-12-07 06:13:55
问题 I am writing some unit tests for an extension method I have written on IPrincipal . To assist, I have created a couple of helper classes (some code for not-implemented members of the interfaces has been omitted for brevity): public class IPrincipalStub : IPrincipal { private IIdentity identityStub = new IIdentityStub(); public IIdentity Identity { get { return identityStub; } set { identityStub = value; } } } public class IIdentityStub : IIdentity { public string Name { get; set; } // BZZZT!!

How to make bootstrap datepicker readonly?

≡放荡痞女 提交于 2019-12-07 02:10:45
问题 I'm struggling with creating embedded/inline datepicker which will not be clickable - it should only present dates, behave as readonly. What I'm doing is populating calendar with selected dates from model, then I try to make it un-clickable so user doesn't thin he can edit anything. I'm using eternicode-bootstrap-datepicker - to make it multidate. So far I've got this: <link rel="stylesheet" href="<c:url value="/resources/js/lib/eternicode-bootstrap-datepicker/css/datepicker3.css" />" />

Const correctness in C# with rich types

大城市里の小女人 提交于 2019-12-06 22:20:15
问题 Coming from a C++ background and trying to learn C#, one of the most frustrating language omissions that I've come across is an equivalent to the const keyword. So, I have been attempting to settle on a pattern that I can use to achieve const correctness in C#. This answer has an interesting suggestion: create a read only interface for all of your types. But as Matt Cruikshank pointed out in the comments, this becomes problematic if your class has collections or other rich types. Particularly

C#: Why do mutations on readonly structs not break?

故事扮演 提交于 2019-12-06 18:27:52
问题 In C#, if you have a struct like so: struct Counter { private int _count; public int Value { get { return _count; } } public int Increment() { return ++_count; } } And you have a program like so: static readonly Counter counter = new Counter(); static void Main() { // print the new value from the increment function Console.WriteLine(counter.Increment()); // print off the value stored in the item Console.WriteLine(counter.Value); } The output of the program will be: 1 0 This seems completely

Is there any run-time overhead to readonly?

依然范特西╮ 提交于 2019-12-06 17:04:18
问题 For some reason, I've always assumed that readonly fields have overhead associated with them, which I thought of as the CLR keeping track of whether or not a readonly field has been initialized or not. The overhead here would be some extra memory usage to keep track of the state and a check when assigning a value. Perhaps I assumed this because I didn't know a readonly field could only be initialized inside a constructor or within the field declaration itself and without a run-time check, you

Make a foreign key field in a django form read-only, and still enable the form to be submitted

独自空忆成欢 提交于 2019-12-06 06:58:07
问题 How do I make a foreign key field in a form read only but still allow this field to be recognized as valid once the form is submitted? According to W3C, disabled fields are left out once the form is submitted....using the code below, I can set the field as disabled, thus readonly, but my form doesn't go through def __init__(self, *args, **kwargs): super(IssuesForm, self).__init__(*args, **kwargs) self.fields['vehicle'].widget.attrs['readonly'] = True Ideas....? 回答1: I don't know the Django or

Modify private readonly member variable?

孤人 提交于 2019-12-06 04:47:14
I have the following code : public class MyClass { private readonly string name; public string Name { get { return name; } } public MyClass(string name) { this.name = name; } } class Program { static void Main(string[] args) { MyClass mc = new MyClass("SomeName"); } } Is there any way I can change the value of mc.name without modifying the class? You can only use reflection typeof(MyClass) .GetField("name",BindingFlags.Instance|BindingFlags.NonPublic) .SetValue(myclassInstance, 123); Adam Flanagan With reflection , yes ( Can I change a private readonly field in C# using reflection? ), but