properties

How to list all class properties

I have class SomeClass with properties. For example id and name: class SomeClass(object): def __init__(self): self.__id = None self.__name = None def get_id(self): return self.__id def set_id(self, value): self.__id = value def get_name(self): return self.__name def set_nam...

Property attribute "retain" doesn't seem to be working?

I've implemented a bit of code from one of the many Apple code examples, but I'm having a bit of trouble, because the retain attribute of one of the properties doesn't appear to be working. Here's the property declaration: @property (nonatomic, retain) EditingViewController *editingViewController; And here's the code: - (EditingViewC...

Access fields or properties from within the declaring class

Public Class FooBar { private int _foo; public int Foo { get { return _foo; } set { _foo = value; } } public void DoStuff() { _foo++; // Do this? Foo++; // Or this? } } Is there a more accepted practice to either access fields or properties (if one exists) in a class? I've alwa...

Properties Expansion Languages (DSLs) - Do any exist?

Here's my problem: We have N applications running in M different environments (qa/prod/etc.) with P servers per environment. Multiplied out, the number of unique configurations is in the hundreds. Each of these applications has a set of environment-specific properties (public hostname, listening port, max memory, etc.). Multiplied ou...

Is it bad practice to put a lot of code in the get function of a property which wraps PInvoke stuff?

A confusing title I know. Let me explain. I have to marshal an array of structs, which then get converted to an array of classes (legacy compatibility). For instance public class InnerClass {} public class OuterClass { private InnerClass[] innerClasses; } public struct InnerStruct { // Data } private static buildInnerClass( Inne...

When is my C# property initialized?

I'm a little confused about when exactly my Property is being initialized. Suppose I have a property declared like this: private Dictionary<string, Dictionary<string,string>> MessageLookup { get { return messages ?? doSomething(); } } The doSomething method populates the messages Dictionary ...

Why can I not add a set accessor to an overriden property?

In a base class I have this property: public virtual string Text { get { return text; } } I want to override that and return a different text, but I would also like to be able to set the text, so I did this: public override string Text { get { return differentText; } set { differentText = value; } } This however does n...

Best practices for loading Properties

I have several classes that need to load some properties files, and I was wondering what are the best practices to accomplish this. I thought of two basic approaches: Hardcode the properties file name in each class, and then use the Properties class to load from a FileInputStream, which can be problematic if someone decides to change t...

NullReferenceException when accessing a property outside of the constructor

In this class, I am setting elp to ElType in the constructor. I can access properties of elp fine when in the constructor (the // ... bit is where I'm accessing elp's properties), but when I try to access elp in another method - ucp() - my program crashes with NullReferenceException. I can't figure out what I'm doing wrong here, althou...

VS2008: Where is the Startup Project setting stored for a solution?

When I right-click my solution in the Solution Explorer and choose Properties I get a dialog where I can select the Startup Project. I sometimes select Current selection (If it is an experimental solution with lots of projects I jump between), but most often it is a Single startup project selected, which would usually be the main WinFor...

Is there a better way to write this line of C# code in C#3.0?

I have a property declared as follows: public decimal? MyProperty { get; set; } I am needing to pass this value to another method as a string and so the only way I see to do so is as follows: MyProperty == null ? null : MyProperty.ToString() This looks very messy when you have a number of similar properties being passed into a meth...

How to define a property with same name on two different types in ROWLEX?

If I have those two classes that have two different properties but with the same name: [RdfSerializable] public class Type1 { [RdfProperty(true), Name = "title"] public string Title { get; set; } } [RdfSerializable] public class Type2 { [RdfProperty(true), Name = "title"] public string Title { get; set; } } and try to...

Using external properties files in weblogic

I am working on deploying a J2ee application that I have previously been deploying in JBOSS into Weblogic 10.3.1.0. I am running into an issue with external properties files. In Jboss I can just put the properties files into $JBOSS_HOME/server/default/conf, and they are loaded onto the system classpath and I can access them without any...

How to enumerate an object's properties in Python?

I C# we do it through reflection. In Javascript it is simple as: for(var propertyName in objectName) var currentPropertyValue = objectName[propertyName]; How to do it in Python? ...

WPF/XAML: Set a style with a different TargetType?

I have an external style resource in a resource dictionary I'm referencing with x:Key. It has an x:TargetType specifying a target (TextBlock). Is it possible to apply this to a control containing a TextBlock and have all TextBlock elements within that control have the style applied? Thanks, Robert ...

Property(with no extra processing) vs public field

Whenever there is question about credibility of Properties, I see that most of the discussion happens around functions/methods vs properties. But I would also like to know the compelling reason to use property with associated private field vs public field directly itself, incase of most common get/set behaviors with no other processing, ...

How to return a new instance of an object in C# Automatic Properties

Is it possible, using C# Automatic Properties, to create a new instance of an object? in C# I love how I can do this: public string ShortProp {get; set;} is it possible to do this for objects like List that first need to be instantiated? ie: List<string> LongProp = new List<string>(); public List<string> LongProp { get { ...

Should I use public properties and private fields or public fields for data?

In much of the code I have seen (on SO, thecodeproject.com and I tend to do this in my own code), I have seen public properties being created for every single private field that a class contains, even if they are the most basic type of get; set; like: private int myInt; public int MyInt { get { return myInt; } set { myInt = v...

DataBinding to a readonly property

Is it possible to bind a field (textbox) to a Property that doesn't implement a set? For instance I have an object that implements INotifyPropertyChanged with 3 fields: public decimal SubTotal { get { return this.subTotal; } set { this.subTotal = value; this.NotifyPropertyChanged("SubTotal"); this.N...

Valid use of accessors in init and dealloc methods?

I've heard now from several sources (stackoverflow.com, cocoa-dev, the documentation, blogs, etc) that it is "wrong" to use accessors and settings (foo, setFoo:) in your init and dealloc methods. I understand that there is there is a remote possibility of confusing other objects that are observing the property if you do so. (a simple e...