Solved

Finding the property setter class

Posted on 2003-11-19
3
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 65 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

617 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