properties

ConfigurationManager.AppSettings Performance Concerns

I plan to be storing all my config settings in my application's app.config section (using the ConfigurationManager.AppSettings class). As the user changes settings using the app's UI (clicking checkboxes, choosing radio buttons, etc.), I plan to be writing those changes out to the AppSettings. At the same time, while the program is runni...

C# eval equivalent?

I can do an eval("something()"); to execute the code dynamically in JavaScript. Is there a way for me to do the same thing in C#? What I am exactly trying to do is that I have an integer variable (say i) and I have multiple properties by the names: "Property1","Property2","Property3" etc. Now, I want to perform some operations on the " ...

Best way to use a property to reference a Key-Value pair in a dictionary

This is a fairly trivial matter, but I'm curious to hear people's opinions on it. If I have a Dictionary which I'm access through properties, which of these formats would you prefer for the property? /// <summary> /// This class's FirstProperty property /// </summary> [DefaultValue("myValue")] public string FirstProperty { get { ...

Class definition, using { get; set;}

In the past we declared classses like: public class MyClass { private int _age; public int Age { get{ return _age; } set{ _age = value; } } } Now we can do: public class MyClass { public int Age {get; set;} } My question is, how can I access the private variable that is created automatical...

c# properties with repeated code

I have a class with a bunch of properties that look like this: public string Name { get { return _name; } set { IsDirty = true; _name = value; } } It would be a lot easier if I could rely on C# 3.0 to generate the backing store for these, but is there any way to factor out the IsDirty=true; so that I can write my properties so...

Set a UserControl Property to Not Show Up in VS Properties Window

I have a UserControl in my Asp.net project that has a public property. I do not want this property to show up in the Visual Studio Property Window when a user highlights an instance of the UserControl in the IDE. What attribute (or other method) should I use to prevent it from showing up? class MyControl : System.Web.UI.UserControl { ...

How to programmatically make a Query in MS Access default to landscape when printed

How can I programmatically make a query in MS Access default to landscape when printed, specifically when viewing it as a PivotChart? I'm currently attempting this in MS Access 2003, but would like to see a solution for any version. ...

Why is it impossible to override a getter-only property and add a setter?

Why do you think (or, why is it good that) Microsoft chose not to allow: public abstract class BaseClass { public abstract int Bar { get;} } public class ConcreteClass : BaseClass { public override int Bar { get { return 0; } set {} } } ...

How do I enumerate the properties of a javascript object?

I actually want to list all the defined variables and their values, but I've learned that defining a variable actually creates a property of the window object. ...

Avoiding double-thunking with C++/CLI properties

I've read (in Nish Sivakumar's book C++/CLI In Action among other places) that you should use the __clrcall decorator on function calls to avoid double-thunking, in cases where you know that the method will never be called from unmanaged code. Nish also says that if the method signature contains any CLR types, then the JIT compiler will ...

Are "proxy properties" good style?

I have a class with a string property that's actually several strings joined with a separator. I'm wondering if it is good form to have a proxy property like this: public string ActualProperty { get { return actualProperty; } set { actualProperty = value; } } public string[] IndividualStrings { get { return ActualProperty....

Auto-implemented getters and setters vs. public fields

I see a lot of example code for C# classes that does this: public class Point { public int x { get; set; } public int y { get; set; } } Or, in older code, the same with an explicit private backing value and without the new auto-implemented properties: public class Point { private int _x; private int _y; public in...

C# 3.0 Auto-Properties - Is it possible to add custom behaviour?

I'd like to know if there is any way to add custom behaviour to the auto property get/set methods. An obvious case I can think of is wanting every set property method to call on any PropertyChanged event handlers as part of a System.ComponentModel.INotifyPropertyChanged implementation. This would allow a class to have numerous properti...

Can you suggest something a little more advanced than java.util.Properties?

Do you know any libraries similar to java.util.Properties that support more advanced features like grouping properties, storing arrays, etc? I am not looking for some heavy super-advanced solution, just something light and useful for any project. Thanks. ...

Why doesn't VB.NET 9 have Automatic Properties like C# 3??

Would having a nice little feature that makes it quicker to write code like Automatic Properties fit very nicely with the mantra of VB.NET? Something like this would work perfect: Public Property FirstName() As String Get Set End Property UPDATE: VB.NET 10 (coming with Visual Studio 2010 and .NET 4.0) will have Automatic Prop...

How to efficiently count the number of keys/properties of an object in JavaScript?

What's the fastest way to count the number of keys/properties of an object? It it possible to do this without iterating over the object? i.e. without doing var count = 0; for (k in myobj) if (myobj.hasOwnProperty(k)) count++; Firefox provides a magic __count__ property, but this isn't available in other implementations. ...

Same property, different types.

Let's say you have a class with a Uri property. Is there any way to get that property to accept both a string value and a Uri? How would you build it? I'd like to be able to do something like one of the following, but neither are supported (using VB, since it lets you specify type in the Set declaration for the 2nd one): Class MyClas...

Changing the DefaultValue of a property on an inherited .net control

In .net, I have an inherited control: public CustomComboBox : ComboBox I simply want to change the default value of DropDownStyle property, to another value (ComboBoxStyle.DropDownList) besides the default one specified in the base class (ComboBoxStyle.DropDown). One might think that you can just add the constructor: public CustomCo...

Learning about Auto-Implemented Properties

I have the simple class using auto-implemented properies: Public Class foo { public foo() { } public string BarName {get; set;} } I obviously use the variable BarName throughout my class and now need to add logic when the property value is set (it must be all upper case, go figure). Does this mean that I need to now crea...

Do Javascript properties calculate on each call?

Since length is a Javascript property, does it matter whether I use for( var i = 0; i < myArray.length; i++ ) OR var myArrayLength = myArray.length; for( var i = 0; i < myArrayLength ; i++ ) Thank you. ...