properties

Can't Set Property's Property

I am having trouble with, as I said, setting a property's property. Let's say I have a class that represents a transaction. In my class I have a property that represents another class, such as this: Public Class PersonRecord _myPerson = new Person() Public Property MyPerson as Person Get _myPerson = Person.GetApp...

C# splitting property get and set between classes. Why doesn't it work?

I'm trying to provide two classes to my users - one that is read-only and one that is writable. The r/o will only have getters, while the writable will inherit from it and add the setters. I was under the impression that C# should be able to handle it, but the compiler disagreed. Why doesn't this work? Any workarounds? class A { pr...

Dynamic primitive type property setting in Objective C

I am trying to write a library so that it is generic enough that its useful. The problem is that it needs to update properties of other classes, both the property and class should be dynamic. Now I can do it using public variables no problem, I just pass a pointer to the variable I want to update. However it would also be incredibly use...

Name property of UserControl or Control

What is special about the Name property of a Control or UserControl that causes it to be displayed as "(Name)" inside the property grid within Visual Studio? ...

Load java properties inside static intializer block

I have a static util class that does some string manipulation on a bit sensetive data. Prior to use of this class I need to initialize certain static variables with values, such as usernames/password, that I prefer to store in .properties file. I am not very familiar with how loading of .properties file work in Java, especially outside o...

Preferred method to set the value of a get only Property: constructor vs backing field

Edit: Though I've accepted David's answer, Jon's answer should be considered as well. Which method is preferred for setting the value of a read only (get only?) Property: using a backing field or using the constructor? Assume the design is for a Property and not a Field (in the future, there may be an update that requires the Property t...

Should I Use self Keyword (Properties) In The Implementation?

Hey guys. I believe I understand properties for the most part. My question is, if I have a property for an instance variable, and I am setting or retrieving it from within a method in my implementation file, should I use self.myProperty or just myProperty? I know either one works, but I have seen mixed conventions, sometimes code accesse...

Using NSMethodSignature on iPhone (with Obj-C 2.0 properties)

Hey guys, I'm running the following code on my phone, where 'object' is a Cat, which is a subclass of Animal. Animal has a property 'color': NSLog(@"Object: %@", object); NSLog(@"Color: %@", [object color]); NSMethodSignature *signature = [[object class] instanceMethodSignatureForSelector:@selector(color)]; NSInvocation *invocation = [...

Change DisplayName attribute for a property

I am looking for a way to change the value of the DisplayName attribute of a property at run-time. Is this even possible in Windows Forms? ...

Is hierachical databinding with properties possible?

Is it possible to bind to a property of a property? Here is what I have: [Bindable(true)] public class DataClass { private string DescriptionValue = null; private Content DataContent Value = new Content(); .... [Bindable(true)] public Content DataContent { get { r...

Is there an Attribute I can use in my class to tell DataGridView not to create a column for it when bound to a List<MyClass>

I have a class like this: private class MyClass { [DisplayName("Foo/Bar")] public string FooBar { get; private set; } public string Baz { get; private set; } public bool Enabled; } When I create a List<MyClass> and assign it to the DataSource of a DataGridView, the grid shows me two columns, "Foo/Bar" and "Baz". This is ...

Sorting javascript by property value

If I have a javascript object such as: var list = { 'you': 100, 'me': 75, 'foo': 116, 'bar: 15}; is there a way to sort the properties based on value? So that I end up with list = { 'bar':15, 'me': 75, 'you': 100, 'foo': 116 }; I'm having a real brain-dead moment regarding this. ...

deleting a window property in IE

Hi, I can't find any information on this issue; why doesn't the following code work in IE? window.x = 45; delete window.x; // or delete window['x']; IE reports an "object doesn't support this action" error. Does it have anything to do with that iterating over window properties in IE issue? Thanks and best regards ...

Do you use Data Members or Public Properties from within the Class itself?

If I have a simple class setup like this: class MyClass { private string _myName = string.Empty; public string MyName { get { return _myName; } } public void DoSomething() { // Get the name... string name = string.Empty; name = _myName; // OR...

Can't get the data from the properties file

Here's the class package db; import java.io.File; import java.io.FileInputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author Oshadha Gunawardena */ public class DBFacade { pri...

Buttons Enabled Property not Working Properly

Hi all, I am creating an Windows Application. I have two buttons. I have written the following code snippet. frmRb obj = new frmrb(); private void btnPd_Click(object sender, EventArgs e) { btnCancel.Enabled = true; obj.btnRtn.Enabled = true; } private void btnCancel_Click(object sender, Ev...

Why use a public property instead of a function to expose a custom collection<T>

During a code review I looked at set of repository classes (in vb.net). I am used to seeing these repository classes full of functions that return collections (among other things) of your domain objects. However, this repository had 1 public property and 1 private variable that looked something like this: Private _item as Collection (of...

Is there an Attribute I can use on a property to tell DataGridView how to format the column?

Following on a bit from this question, if I have this class: private class MyClass { [DisplayName("Foo/Bar")] public string FooBar { get; private set; } public decimal Baz { get; private set; } } And I want to display a List<MyClass> in a DataGridView (with autogenerated columns), what's the easiest way to make the Baz column di...

How to set order for dependency properties Callback change methods?

Hi! I have many dependency properties in my WPF usercontrol and many of them are set directly in XAML. Among these are ItemsSource and Value (my custom properties). The problem is that initial Value selects a concrete item in ItemSource. But to achieve this, ItemsSource must be set first. While debugging I realized that ValueChangeCallb...

How do you use the IS operator with a Type on the left side?

I have a method I'm writing that uses reflection to list a class's static properties, but I'm only interested in those that are of a particular type (in my case, the property must be of a type derived from DataTable). What I would like is something like the if() statement in the following (which presently always returns true): PropertyI...