properties

Best practices: throwing exceptions from properties

When is it appropriate to throw an exception from within a property getter or setter? When is it not appropriate? Why? Links to external documents on the subject would be helpful... Google turned up surprisingly little. ...

Override abstract readonly property to read/write property.

I would like to only force the implementation of a C# getter on a given property from a base abstract class. Derived classes might, if they want, also provide a setter for that property for public use of the statically bound type. Given the following abstract class: public abstract class Base { public abstract int Property { get; }...

C# Locking, Properties & Permissions

I've been using lock on value type properties when multi-threaded access is required. Also, I've been meaning to become more diligent about applying proper access modifiers, especially in my library code that is starting to become useful in multiple projects. I've written some code and would like to request comments on the various stra...

Recursive mocking with Rhino-Mocks

Hi I'm trying to unittest several MVP implementations and can't quite figure out the best way to mock the view. I'll try to boil it down. The view IView consists e.g. of a property of type IControl. interface IView { IControl Control1 { get; } IControl Control2 { get; } } interface IControl { bool Enabled { get; set; } ...

Specifying Java path for properties file

I have a Java Spring project, configured with Maven. As the amount of unit tests and their configuration files is adding up rapidly, I'm trying to centralize the test configurations to one properties file (the same one, which is used in building the project). The unit tests are located (relative to the project path, of course) in tree s...

For C# resources, why is Properties is undefined?

When I try try to access a string property in one of my C# project resources, I get the following error: 'ORG.PRJ.MOD.MyClass2' does not contain a definition for 'Properties' The code that produces the error is: string s = MyClass2.Properties.Resources.TestString2; The really bizarre thing is that another project in my solution (...

Set Window.DataContext to a declared property in the code-behind?

I want to achieve something like the following (Notice the DataContext property of the Window element): <Window x:Class="Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" DataContext="{Binding MyDataContext}"/> Class Window1 Public ReadOnly...

How can I find out where a ResourceBundle came from?

Given a ResourceBundle object, is there a way to get a URL or other indicator as to where it was found when it was looked up? The ResourceBundle is being created with: ResourceBundle rb = ResourceBundle.getBundle("filename"); And it is being loaded from a file subdir/filename.properties, in most cases. I'd like to be able to program...

Accessing Property Values of a Protocol?

Hey guys, I have a protocol which defines a number of ObjC-2.0 properties, like so: @protocol Repeatable <NSCoding> @required @property (nonatomic, retain) Date *startDate; @property (nonatomic, retain) Date *endDate; @end I have another class that implements the protocol: @interface AbstractRepeatable : NSObject <Repeatable> And f...

self "not a structure or a union" in a UIViewController class. Why?

I have spent a lot of time trying to figure out what the problem is... but with no success. My code is the following: ResultGoalViewController *resultGoalViewController = [[ResultGoalViewController alloc] initWithNibName:@"ResultGoalViewController" bundle:nil]; [self.goalNavigationController pushViewController:resultGoalViewController...

Why does a readonly property still allow writing with KVC

I'm working through the "Key Value Coding" chapter in "Programming for Mac OS X". I've built an interface with a slider and a label, both bound to fido, an int. If I set the property for fido to readonly, moving the slider still causes the label to change it's value. I had assumed that I'd get some sort of error for this. If the property...

iPhone properties getting set to nil

I set a property with this declaration: @property (nonatomic,retain) NSDictionary *itemData; to a dictionary with 1 key - val pair. The table view in my view then gets the one value for the dictionary fine as a section header. But when I go back to access that very same value, it is nil. Any suggestions? I have been working on this f...

Why we need Properties in C#

Can you tell me what is the exact usage of properties in C# i mean practical explanation in our project we are using properties like /// <summary> /// column order /// </summary> protected int m_order; /// <summary> /// Get/Set column order /// </summary> public int Order { get { return m_order; } set { m_order = value; } } ///...

Cloning a TStringGrid Component

Dear all, I am starting to learn Delphi. So I decided to write an application like MS Excel from scratch. In a new Form1, I did put a TPageControl component containing only 1 page. In that page, I did put a TAdvStringGrid and a TPanel with some buttons (button1, button2) and a Popup1 menu for defining some actions on the grid, like copy...

Cannot use parentheses when calling a Sub

Hi there, I have a Classic ASP page that contains the following code to attempt a parametised query; <% Set cmdEmail = Server.CreateObject("ADODB.Command") Set rsEmail = Server.CreateObject("ADODB.Recordset") cmdEmail.CommandText = "SELECT * FROM VWTenantPropertiesResults WHERE ContentID = ?" cmdEmail.CommandType = 1 cmdEmail.ActiveCon...

Saving Word 2007 Document Properties in C# 2.0

Hi all, I'm trying to modify some CustomDocumentProperties for a .docx document. So far I've been able to read the current value and modify it, but, for whatever reason, whenever I save the document the changes to the custom fields are lost. I have the following method within a DocAccessor class (which serves as an interface for my doc...

maven ${user.home} not being resolved correctly.

I've got the following line in my pom.xml: <updateRepositoryURL>file:/${user.home}/.m2/repository/repository.xml</updateRepositoryURL> and when I am attempting to use it within my program the resultant string is: file:/c:Documents and Settings<myusername>/.m2/repository/repository.xml where <myusername> is my user name funnily enou...

Spring: can ResourceBundleMessageSource be configured to load properties in xml format

As you may know, properties are usually written in files in key=value format but can also be written in XML format. The question is if (and how) can Spring's ResourceBundleMessageSource be configured to load properties in XML format. ...

How to restrict to add an item to List<T> ?

I have Class called Person containing to properties, Father and List of Children. I want every one to use only AddChild Method to add children, not the List.Add method , so how do I restrict use of it? public class Person { private List<Person> _children = new List<Person>(); public string Name { get; set; } public Person Father ...

Setting Properties In Once Class, Accessing From Another

Hi. My question is basically this: If I set dynamic data from one class, can I access that same data from another class? Below is the rough pseudocode of what I am trying to do: Public Class Person { public string ID { get; set; } public string Name { get; set; } } And, I do the below: Public Class SomeClass { private voi...