Solved

Finding the property setter class

Posted on 2003-11-19
3
234 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
Comment Utility
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
Comment Utility
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 65 total points
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now