Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Finding the property setter class

Posted on 2003-11-19
3
Medium Priority
?
245 Views
Last Modified: 2010-04-16
Hi

Is it possible to find which is object is setting a particular property?

For ex: I have a class in which TestValue is a property that sets its int m_iTestValue. And many other may classes set this TestValue property. In the class which holds this property, I want to find the class which is setting the value to this property.

Is this possible?

Regards
Murali
0
Comment
Question by:bmmohan
  • 2
3 Comments
 
LVL 6

Expert Comment

by:purpleblob
ID: 9786072
Can I just try and get this clear in my head. You have a class with a property (TestValue) - let's say it's ina class called MyClass for clarity.

Now you have code such as

MyClass obj = new MyClass();
obj.TextValue = 10;

And you wish to find what class called this method ?

If this is the case I very much doubt it's possible/simple as the instance of MyClass (in this example) would need to have a reference to the object that called the property and really this could only be achieved by passing a reference of the object to your property/method. i.e.

MyClass obj = new MyClass();
obj.SetTextValue(this, 10);

Now I suppose one could attempt the trace through the stack to discover who's called this property but I doubt it'd be worth the effort.

If this isn't what you mean't then sorry about the rambling, please can you clarify, maybe with a snippet of code, what you're after :-)
0
 

Author Comment

by:bmmohan
ID: 9786526
Hi purpleblob

Thanks for the reply. I should have been more clear on my query.

Actually I am creating a user Control which is a Scrollable Control. This inturn will have a Graph Control. This Graph Control will be increasing gradually in its size. So when the size of the graph control is more than the Scrollable Control, the scroll bars have to be shown.

Here I am manually doing some calculations to find out whether the scroll bars are required or not. If the scroll bars are required, then I set the Autoscroll property to True, and also set the AutoscrollPosition.

For this, when this control is added to a form, the Autoscroll and AutoscrollPosition property of the Scrollable Control should not be allowed to be set. So I want t restrict the form to set these properties. Only the scrollable control must be able to these properties, no other control or form.

I was trying out lot of options and thought of overriding these properties. At that I thought, if I can find any other class is setting these peoperties, I can just reset back to their default properties. But I was unable to restrict the form from setting these peoperties OR unabl to find whether the property was set by the control or form.

Can you please tell me how to achieve this? Can I do this using ShouldSerialize and Reset ?

Please help me as this is little urgent for me.

Regards
Murali
0
 
LVL 6

Accepted Solution

by:
purpleblob earned 195 total points
ID: 9786740
You cannot restrict a property to a specific class (again unless you pass a reference to that class to your object and then you could use the is operator to see whether it's a certain type of class, but this would stop someone creating a new class derived from the object you allow access... anyway I think I'm going of track :-) )

You can change the visibility of a property to only available to classes within the same assembly (i.e. DLL or EXE) by using the internal keyword, i.e.

instead of

public int TestValue
{
}

have

internal int TestValue
{
}

Now only objects which are within your assembly can interact with this property.

Anyway short answer - you cannot restrict access to your properties to a single instance of a single class without doing something like I mentioned previously, i.e. passing a reference to the object altering the property and then checking to see whether this is an instance or a type that is allowed to alter the property.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question