readonly

How to get around lack of covariance with IReadOnlyDictionary?

天大地大妈咪最大 提交于 2019-11-26 17:47:52
问题 I'm trying to expose a read-only dictionary that holds objects with a read-only interface. Internally, the dictionary is write-able, and so are the objects within (see below example code). My problem is that IReadOnlyDictionary doesn't support covariant conversions because of the reason outlined in the question here. This means I can't just expose my internal dictionary as a read only one. So my question is, is there an efficient way to convert my internal dictionary to an IReadOnlyDictionary

Connection to a Microsoft SQL Database via VBA (ADODB) with the lowest risk to harm the database

你离开我真会死。 提交于 2019-11-26 17:26:40
问题 im currently looking for a way to connect to a Microsoft SQL Server Database via VBA (ADODB) with the focus on a minimal risk in harming, block and change the structure of the database. Therefor the access is readonly. My attemp is the following: Set DBConn = New ADODB.Connection Set TmpRecset = New Recordset DBConn.ConnectionString = pConnStr DBConn.Open On Error GoTo TermConnection With TmpRecset .ActiveConnection = DBConn .Source = pQuery .LockType = adLockReadOnly .CursorType =

How do I delete a directory with read-only files in C#?

家住魔仙堡 提交于 2019-11-26 17:25:50
I need to delete a directory that contains read-only files. Which approach is better: Using DirectoryInfo.Delete() , or, ManagementObject.InvokeMethod("Delete") ? With DirectoryInfo.Delete() , I have to manually turn off the read-only attribute for each file, but ManagementObject.InvokeMethod("Delete") doesn't appear to need to. Is there any situation where one is more preferable to the other? Sample code (test.txt is read only). First way: DirectoryInfo dir = new DirectoryInfo(@"C:\Users\David\Desktop\"); dir.CreateSubdirectory("Test"); DirectoryInfo test = new DirectoryInfo(@"C:\Users\David

Declare a const array

故事扮演 提交于 2019-11-26 17:07:19
Is it possible to write something similar to the following? public const string[] Titles = { "German", "Spanish", "Corrects", "Wrongs" }; Yes, but you need to declare it readonly instead of const : public static readonly string[] Titles = { "German", "Spanish", "Corrects", "Wrongs" }; The reason is that const can only be applied to a field whose value is known at compile-time. The array initializer you've shown is not a constant expression in C#, so it produces a compiler error. Declaring it readonly solves that problem because the value is not initialized until run-time (although it's

HTML: cursor showing in readonly input text?

时间秒杀一切 提交于 2019-11-26 16:49:27
问题 Let's say we have a textbox that's readonly, like so: <input type="text" readonly /> In IE 9 and FF 4, when I click on this field, a (non-blinking) cursor appears in the field. In Chrome, however, the cursor does not show. (See for yourself at http://jsfiddle.net/hqBsW/.) I suppose I understand why IE/FF opt to show the cursor—so the user knows he or she can still select the value in the field. Nonetheless, it's evidently confusing our users and we would like to change IE/FF to not show the

How do I open an already opened file with a .net StreamReader?

懵懂的女人 提交于 2019-11-26 16:05:30
I have some .csv files which I'm using as part of a test bench. I can open them and read them without any problems unless I've already got the file open in Excel in which case I get an IOException : System.IO.IOException : The process cannot access the file 'TestData.csv' because it is being used by another process. This is a snippet from the test bench: using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(fullFilePath, FileMode.Open, FileAccess.Read)), false)) { // Process the file } Is this a limitation of StreamReader? I can open the file in other applications (Notepad++ for

Which is better between a readonly modifier and a private setter?

送分小仙女□ 提交于 2019-11-26 15:25:49
问题 I've been working on creating a class and suddenly a thought came to my mind of what is the difference between the two codes: public readonly string ProductLocation; AND public string ProductLocation { get; private set; } Can you guys give me idea when to use the following better. thanks. 回答1: The first one is a read-only field, while the second one gets compiled as a pair of methods (and all reads of the property ProductLocation gets compiled into calls to the corresponding get method and

OneWayToSource binding from readonly property in XAML

大兔子大兔子 提交于 2019-11-26 14:28:18
I'm trying to bind to a Readonly property with OneWayToSource as mode, but it seems this cannot be done in XAML: <controls:FlagThingy IsModified="{Binding FlagIsModified, ElementName=container, Mode=OneWayToSource}" /> I get: The property 'FlagThingy.IsModified' cannot be set because it does not have an accessible set accessor. IsModified is a readonly DependencyProperty on FlagThingy . I want to bind that value to the FlagIsModified property on the container. To be clear: FlagThingy.IsModified --> container.FlagIsModified ------ READONLY ----- ----- READWRITE -------- Is this possible using

What is the correct readonly attribute syntax for input text elements?

冷暖自知 提交于 2019-11-26 14:18:19
问题 As Most, I am familiar with the readonly attribute for text input , But while reading code from other websites (a nasty habit of mine ) I saw more than one implementation for this attribute: <input type="text" value="myvalue" class="class anotherclass" readonly > and <input type="text" value="myvalue" class="class anotherclass" readonly="readonly" > and I have even seen <input type="text" value="myvalue" class="class anotherclass" readonly="true" > .. And I believe I saw even more, but can

Remove readonly attribute from directory

余生颓废 提交于 2019-11-26 13:09:23
问题 How can I programatically remove the readonly attribute from a directory in C#? 回答1: var di = new DirectoryInfo("SomeFolder"); di.Attributes &= ~FileAttributes.ReadOnly; 回答2: Here's a good link to examples of modifying file attributes using c# http://www.csharp-examples.net/file-attributes/ based on their example, you can remove the Read Only attribute like this (I haven't tested this): File.SetAttributes(filePath, File.GetAttributes(filePath) & ~FileAttributes.ReadOnly); 回答3: Using the -=