When should an attribute be private and made a read-only property? [closed]

Just my two cents, Silas Ray is on the right track, however I felt like adding an example. 😉 Python is a type-unsafe language and thus you’ll always have to trust the users of your code to use the code like a reasonable (sensible) person. Per PEP 8: Use one leading underscore only for non-public … Read more

Why does C# disallow readonly local variables? [closed]

I think it’s a poor judgement on part of C# architects. readonly modifier on local variables helps maintain program correctness (just like asserts) and can potentially help the compiler optimize code (at least in the case of other languages). The fact that it’s disallowed in C# right now, is another argument that some of the … Read more

Pushing read-only GUI properties back into ViewModel

Yes, I’ve done this in the past with the ActualWidth and ActualHeight properties, both of which are read-only. I created an attached behavior that has ObservedWidth and ObservedHeight attached properties. It also has an Observe property that is used to do the initial hook-up. Usage looks like this: <UserControl … SizeObserver.Observe=”True” SizeObserver.ObservedWidth=”{Binding Width, Mode=OneWayToSource}” SizeObserver.ObservedHeight=”{Binding … Read more

mysql – How to grant read only permissions to a user?

If there is any single privilege that stands for ALL READ operations on database. It depends on how you define “all read.” “Reading” from tables and views is the SELECT privilege. If that’s what you mean by “all read” then yes: GRANT SELECT ON *.* TO ‘username’@’host_or_wildcard’ IDENTIFIED BY ‘password’; However, it sounds like you … Read more

How to make Entity Framework Data Context Readonly

In addition to connecting with a read-only user, there are a few other things you can do to your DbContext. public class MyReadOnlyContext : DbContext { // Use ReadOnlyConnectionString from App/Web.config public MyContext() : base(“Name=ReadOnlyConnectionString”) { } // Don’t expose Add(), Remove(), etc. public DbQuery<Customer> Customers { get { // Don’t track changes to query … Read more

Docker, mount volumes as readonly

You can specify that a volume should be read-only by appending :ro to the -v switch: docker run -v volume-name:/path/in/container:ro my/image Note that the folder is then read-only in the container and read-write on the host. 2018 Edit According to the Use volumes documentation, there is now another way to mount volumes by using the … Read more

Is there a read-only generic dictionary available in .NET?

.NET 4.5 The .NET Framework 4.5 BCL introduces ReadOnlyDictionary<TKey, TValue> (source). As the .NET Framework 4.5 BCL doesn’t include an AsReadOnly for dictionaries, you will need to write your own (if you want it). It would be something like the following, the simplicity of which perhaps highlights why it wasn’t a priority for .NET 4.5. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)