setter

Data verifications in Getter/Setter or elsewhere ?

I'm wondering if it's a good idea to make verifications in getters and setters or elsewhere in the code. This might surprise you be when it comes to optimizations and speed-ing up the code, I think you should not made verifications in getters and setters but in the code where your're updating your files or database. Am I wrong ?...

How to generate getters and setters in Visual Studio?

By "generate", I mean auto-generation of the code necessary for a particuliar selected (set of) variable(s). But any more explicit explication or comment on good practice is welcome. ...

Setter Methods

Is it necessary for setter methods to have one argument? Usually setter methods accept one argument as the value of a certain property of an Object. What if I want to test first the validity which depends on another argument which is a boolean, if true, validate first, else just set the value. I am getting the values from clients throug...

Modifying setter argument - is it hack or not?

Is it normal to modify setter arguments? Let's imagine that we have setString method. And we really want to keep a trimmed form of the string. So a string with trailing spaces is invalid, but we don't want to throw an exception. What's the best solution? To trim the value in the setter e.g. public void setString(String string) { th...

Rhino Mocks - Verify Property Set when Property has no Get

If you have a property: public class Fred { public string UserName { set { userName=value; } } } how do you use Rhino Mocks to check that fred= new Fred(); fred.UserName="Jim"; is called. Expect.Call(mockFred.UserName).SetPropertyWithArgument("Jim"); does not compile. ...

Is it possible to have class.property = x return something other than x?

Let's say I have a Ruby class: class MyClass def self.property return "someVal" end def self.property=(newVal) # do something to set "property" success = true return success # success is a boolean end end If I try and do MyClass.property=x, the return value of the whole statement is always x. It is a convention i...

WPF - Is there a good reason that Setter.Value isn't a ContentProperty?

Every time I write out a setter whose Value property value isn't describable inline, I curse the fact that the API doesn't mark the Setter class with [ContentProperty("Value")], which would allow this: <Setter Property="BitmapEffect"> <Setter.Value> <OuterGlowBitmapEffect GlowColor="#AAC" Opacity="0.2" GlowSize="1.25" /> </Sette...

Overriding an attribute in Rails and getting at the underlying value.

For the life of me, I can't figure out how to do this. I have a model for which the stored value is a path to a resource on the file system. I'd like the model to write and fetch the resource from the file system, so I naturally want to override the getter and setters to do this. How do I then get at the underlying value that's in the db...

getter and setter for class in class c#

Hello. I a little problem. Assuming we have a class InnerClass with attributes and getter/setter. We also have a class OuterClass containing the InnerClass. e.g. class InnerClass { private int m_a; private int m_b; public int M_A { get { return m_a; } set { ...

Data Binding and throwing exception in setter

Hello, Let's say I have a simple class public class Person { public string Name { get; set; } private int _age; public int Age { get { return _age; } set { if(value < 0 || value > 150) throw new ValidationException("Person age is incorrect"); _age = value; } } } Then I want to setup a bi...

Objective-C Setter Memory Management

Still a little confused about Objective-C memory management. I think my confusion stems from what exactly the autorelease means. NSString *theBackendResponse = [[NSString alloc] initWithData:receivedData encoding:NSASCIIStringEncoding]; NSDictionary *accountDictionary = [theBackendResponse propertyList]; [viewController setAccountDictio...

How do I modify the set method signature that Eclipse auto generates?

My current project has the coding convention that instance variables are never referred to with the this. prefix and that parameters should never hide instance variables. This results in setters that look like: public void setFoo(final Foo aFoo) { foo = aFoo; } Unfortunately eclipse won't generate that for me by default. I've found...

How to compare values of two controls with a trigger?

I have to buttons, named btnOK and btnSave. I want that the IsEnabled of btnSave should be the same as the btnOK's value, i.e. if btnOK goes disabled, btnSave should do the same. I actually need something like (pseudu): <Button TabIndex="3" Name="btnOK"> <Button.Triggers> <Trigger Property="IsEnabled"> <Setter ...

Reflection: How to find from a property info object if that property has a Non Public (Private / Protected) Setter?

Hi Friends, I searched on the forum / Internet for the solution how a PropetryInfo object (of a Public property) can reveal if it has a Private \ Protected Setter ... it was all in vain .... all help I found was about how to "Set" value of a public property having a Private Setter... I would like to know if I have a PropertyInfo objec...

Getter Sequence Of Events?

I am trying to understand what is happening in the getter below, this is what I understand so far: (1) the getter returns a pointer to an NSString object. (2) the NSString object is retained, possibly because we have just given away a pointer to it. (3) autorelease? when does that activate, when the PlanetClass instance is deallocated (...

Referencing getter/setter functions in actionscript 3

How does one get a reference the the getter and setter functions in actionscript 3? if a method is defined on the calls, e.g. public function blah():String { ...} I can get a reference to it by just saying blah or this.blah How do get a reference to public function get blah2():String {} public function set blah2(b:String):void {} ...

Setter.Value instead of Setter in Silverlight

I know I can write a Setter in Silverlight like this: <Setter Property="Background" Value="{StaticResource MyBrush}" /> However, due to other considerations, I have to write the setter in the format: <Setter Property="Background"> <Setter.Value> ????? static resource </Setter.Value> </Setter> Any examples I've seen have t...

Simple C# registry object with Getters and Setters.

Hi, How would I achieve something like this in C#? object Registry; Registry = MyProj.Registry.Instance; int Value; Value = 15; Registry.Value = Value; /* Sets it to 15 */ Value = 25; Value = Registry.Value; /* Returns the 15 */ So far I have this object: namespace MyProj { internal sealed class Registry { static re...

Flex + Cairngrom + getter setter on a bound VO

I feel like this should be a simple thing, but here I am asking the question after a good amount of frustration. Ok I have a project I'm doing in Cairngorm in Flex 3. In one of the components I have a tile list that's bound to a VO in a Model Locator. I want to run a function once that VO contains some data that basically adds sums a ...

Getter and setter, pointers or references, and good syntax to use in c++?

Hi, I would like to know a good syntax for C++ getters and setters. private: YourClass *pMember; the setter is easy I guess: void Member(YourClass *value){ this->pMember = value; // forget about deleting etc } and the getter? should I use references or const pointers? example: YourClass &Member(){ return *this->pMember; } ...