Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Finding the property setter class

Posted on 2003-11-19
3
Medium Priority
?
243 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 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
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…

670 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