accessor

How do I get the value of a JSObject property from C?

In SpiderMonkey, how do I get the value of a property of a JSObject from within my C code? static JSBool JSD_getter(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { jsval js_id; JS_GetProperty(cx, obj, "id", // js_id has JavaScript type int c_id; JS_ValueToInt32(cx, js_id, // Now, c_id contains th...

Is there a way to simulate the C++ 'friend' concept in Java?

I would like to be able to write a Java class in one package which can access non-public methods of a class in another package without having to make it a subclass of the other class. Is this possible? ...

Is there a way for Ruby accessors to return something other than the set variable?

I want to do some checking in a writer accessor. My first idea was returning a boolean. class MyClass def var=(var) @var = var # some checking return true end end m = MyClass.new retval = (m.var = 'foo') => "foo" Can I set a return value in a writer accessor? If yes, how can I get this value? ...

What is the best way to access properties from the same class, via accessors or directly?

This is something I'm not much consistent about and always curious about what other people do. How do you access internal properties (private or public)? For example you've got this property : Private _Name As String Public Property Name() As String Get Return _Name End Get Set(ByVal value As String) _Nam...

"Read only" Property Accessor in C#

I have the following class: class SampleClass { private ArrayList mMyList; SampleClass() { // Initialize mMyList } public ArrayList MyList { get { return mMyList;} } } I want users to be able to get mMyList which is why i exposed the "get" via a property however i don't want changes they make to th...

SkinID on custom control not working (asp.net)

I am deriving a control from syste.web.ui.webcontrols.button. I am then calling it buttonv2. I am then adding an arbitrary property to this new class, "int abc", accessing it via a get/set accessor that stores it's value in the viewstate (it also returns 0 if the viewstate value is null, i.e. i've tried to access it without setting it)....

Getters/setters in Java

I'm new to Java, but have some OOP experience with ActionScript 3, so I'm trying to migrate relying on stuff I know. In ActionScript 3 you can create getters and setters using the get and set keywords, meaning you create a method in the class and access data through a property of an instance of that class. I might sound complicated, but...

Accessor with different set and get types?

Simple question, hopefully a simple answer: I'd like to do the following: private DateTime m_internalDateTime; public var DateTimeProperty { get { return m_internalDateTime.ToString(); } // Return a string set { m_internalDateTime = value; } // here value is of type DateTime } The above is just an example of what I'm trying to ...

In migrating from Java to C# what should I know about accessor classes

I am a Java programming now also writing in C#. I have seen Accessor classes generated by the VS test generating software (to give access from Tests to private members or functions). Should I be creating Accessors deliberately and if so why ...

Best practice: Accessor properties or parameterless methods?

Which is the better practice and why? bool IsTodayMonday { get { return DateTime.Now.DayOfWeek == DayOfWeek.Monday; } } Or bool IsTodayMonday() { return DateTime.Now.DayOfWeek == DayOfWeek.Monday; } ...

"Forward-unbreakable" accessor class templates [C++]

Hi, Unless I am thoroughly mistaken, the getter/setter pattern is a common pattern used for two things: To make a private variable so that it can be used, but never modified, by only providing a getVariable method (or, more rarely, only modifiable, by only providing a setVariable method). To make sure that, in the future, if you happe...

C# set accessor accessible to all types in assembly, and get assessor only to derivated types. How to?

This property in a type with no access modifier (thus internal access): class SomeType { private int length; internal int Length { get { return length; } set length = value; } } } allows all types within the assembly of SomeType to use get and set accessors. Problem: how to restrict the access to set to onl...

Objective-C :: using a method to change an object

I have a class called "CardSet", containing an NSMutableArray* cardSet to hold "cards", which I extend to make "DeckCards". I'd like "CardSet" to have a method called "(void)addCard:(Card*)" (and similarly a method "removeCard"). I'd like "addCard" to some how have access to and set cardSet. Even better I'd like to use the "addCard" meth...

Generate accessors in Visual C++ 2008

Hi, I'm trying to generate the accessors and mutators for my variables automatically, but just can't find a way. I tried the right-click/refactor... solution, but the refactor item doesn't appear. I'm not in the mood right now to learn how to write a macro to do this, and I don't have the money to buy a commercial solution (internship s...

Please help with C++ syntax for const accessor by reference.

Right now my implementation returns the thing by value. The member m_MyObj itself is not const - it's value changes depending on what the user selects with a Combo Box. I am no C++ guru, but I want to do this right. If I simply stick a & in front of GetChosenSourceSystem in both decl. and impl., I get one sort of compiler error. If I do ...

Accessing object property as string and setting its value

Hello there, I have an object in csharp from the class Account each account have a owner, reference, etc. One way I can access an accounts properties is through accessors like account.Reference; but I would like to be able to access it using dynamic string selectors like: account["PropertyName"]; just like in javascript. so I wou...

How to avoid GeneratedSerializationConstructorAccessor problems?

We have a Java App that receives SOAP requests, and after a lot of requests we notice that the GC stops the world to unload a lot of GeneratedSerializationConstructorAccessor classes. This is a big performance impact. Does anyone know how to avoid this or at least significantly reduce the count of GeneratedSerializationConstructorAccess...

PHP's _get & _set or unique get and set functions for each variable?

PHP has _get and _set functions built in. Is it better to write my own get and set functions for each variable or use the built in functions with a ton of if else if? What are the pros and cons of each method? ...

Get-Set Accessor functionality differs on existence of get-set keyword.

I'm currently implementing a poor-man's version of the RSA Algorithm and I wanted the prime numbers d, e, m, and n to be read-only as they will be automatically generated within ithe constructor body. However, I get two different results when I type: class RSA { public RSA() { n = 4; } private long n { get; pri...

Do methods which return Reference Types return references or cloned copy?

I've been learning Java these days and what I've read just is "Be careful not to write accessor methods that return references to mutable objects" which is really interesting. And now I am wondering whether it is same for Properties and Accessor methods in C#? Or C# already returns cloned copies automatically? Thanks. ...