getter

Rhino Mocks AssertWasCalled (multiple times) on property getter using AAA

試著忘記壹切 提交于 2019-11-30 07:48:46
I have a mocked object that is passed as a constructor argument to another object. How can I test that a mocked object's property has been called? This is code I am using currently: INewContactAttributes newContact = MockRepository.GenerateMock<INewContactAttributes>(); newContact.Stub(x => x.Forenames).Return("One Two Three"); someobject.ConsumeContact(newContact); newContact.AssertWasCalled(x => { var dummy = x.Forenames; }); This works except when within the "someobject" the getter on Forenames property is used multiple times. That's when I get "Rhino.Mocks.Exceptions

Javascript getters/setters in IE?

两盒软妹~` 提交于 2019-11-30 05:49:25
问题 For whatever reason, Javascript getters/setters for custom objects seem to work with any browser but IE. Does IE have any other non-standard mechanism for this? (As with many other features) If not, are there any workarounds to achieve the same functionality? 回答1: IE8 has it through defineProperty, but only for DOM objects. But supposedly, it'll eventually come for JavaScript objects as well. 回答2: Resig's post references his env.js implementation being the first time he uses the getters and

How to override a getter-only property with a setter in C#?

Deadly 提交于 2019-11-30 04:29:12
问题 Update : This question has been revised to make it clearer. The answers below seem to reflect that this method works well. Hopefully this question can help people who need to add a get or set to an existing property. Ran into a problem today where I needed to override a base class's get -only property with both a get and set . Current consensus seems to be that this is impossible, but I think that I found a method. The general idea is to make a new property instead of directly override ing

How does extending the prototype chain increase performance in this case?

馋奶兔 提交于 2019-11-30 03:25:15
问题 I've had a long-standing assumption that deep prototype chains resulted in performance deterioration for property accessors. I was trying to explain that on hide the getter or add in the proto Object when a quick benchmark I threw together resulted in quite the opposite outcome from what I was expecting. What is going on here? Am I missing something obvious, or does this outright demonstrate that my (and others') assumption about the performance of property accessors on the prototype chain

Java :Setter Getter and constructor

我的未来我决定 提交于 2019-11-30 03:05:42
I'm a bit confused about the use of getter/setters and constructors (see the below code for an example) public class ExampleClass { private int value = 0; public ExampleClass () { value = 0; } public ExampleClass (int i) { this.value = i; } public int getValue() { return value; } public void setValue(int val) { this.value = val; } public static void main(String[] args) { ExampleClass example = new ExampleClass (20); example.setValue(20); //Both lines above do same thing - why use constructor? System.out.println(example.getvalue()); } } All I've learned is that we need getters/setters for

Make a property that is read-only to the outside world, but my methods can still set

我是研究僧i 提交于 2019-11-30 02:08:33
In JavaScript (ES5+), I'm trying to achieve the following scenario: An object (of which there will be many separate instances) each with a read-only property .size that can be read from the outside via direct property read, but cannot be set from the outside. The .size property must be maintained/updated from some methods which are on the prototype (and should stay on the prototype). My API is already defined by a specification so I can't modify that (I'm working on a polyfill for an already-defined ES6 object). I'm mostly trying to prevent people from shooting themselves in the foot

Cross-browser Getter and Setter

别说谁变了你拦得住时间么 提交于 2019-11-29 21:49:04
This works in modern Chrome/Firefox/Opera but fails in IE8. Haven't tried it in IE9. How can I make this cross-browser compatible, including IE7+? (Fiddle here.) var foo = { get test(){ return 'Works'; } }; // foo.test should be 'Works' I've seen some usage with __defineGetter__ but that threw an 'unrecognized method' error in IE8. I don't believe you can. In IE8 and lower, property access is mere property access. There's no way to run function code without explicitly invoking the function. I think in IE8 you may be able to with DOM elements, but I don't believe it works for regular native

MVVM: Should a VM object expose an M object directly, or only through getters delegating to M's getters?

别等时光非礼了梦想. 提交于 2019-11-29 20:26:24
the best way to explain is with example so: this is the model public class Person { public int age; public string name; } this is the view model public class PersonVM { } my question is: should the vm expose the person to the data template or encapsulate the model properties with his own properties? The view model should declare its own properties and hide the specifics of the model from the view. This gives you the most flexibility, and helps keep view model-type issues from leaking into the model classes. Usually your view model classes encapsulate the model by delegation. For example, class

What is the difference between _name and self.name if name was a NSString

不想你离开。 提交于 2019-11-29 18:12:59
What is the defference if I called NSString *theNameToDisplay = _name; or NSString *theNameToDisplay = self.name; I know it might be a silly question but I see both versions used a lot and I don't spot a difference in the output? Thanks! Assume you have in your .m file this line (and don't have any overriden methods to direct access to _name) @synthesize name = _name; It mean that property name (self.name) will use variable _name when you try to access it. In this case self.name is equal to _name But if you have dynamic property for name, something like this : -(NSString)name{ return @"1234";

How to get Getter backing field from PropertyInfo?

試著忘記壹切 提交于 2019-11-29 17:05:12
I have a class as follows: class Foo : PropertyChangedBase { private int _property; public int Property { get { return _property; } set { OnAssignPropertyChanged("Property", () => _property, value); } } PropertyChangedBase implements INotifyPropertyChanged with the following methods: protected void OnAssignmentPropertyChanged<T>(string propertyName, Expression<Func<T>> fieldExpression, T value) { var get = fieldExpression.Compile(); if (get().Equals(value)) { return; } // invoke set property method SetProperty(fieldExpression, value); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs