473,387 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

C#-WEB How can I get a property to use the set accessor?

5
Hi!

I need to get a property or anyway to set my private variable that is used within the property's accessor.

example:

Expand|Select|Wrap|Line Numbers
  1. public class Fluffers{
  2.   public FooBar Foo{
  3.   get{
  4.     if (pFoo == null)
  5.       StaticFunction.Link((pFoo = new FooBar()));
  6.  
  7.     return pFoo;
  8.   }
  9.   set{
  10.     StaticFunction.ReLink(value, pFoo);
  11.     pFoo = value;
  12.   }
  13.   }
  14.   private FooBar pFoo = null;
  15. }
  16.  
inside the Link function, I put the pFoo in an array so I can use it on other stuff, like logging
but, now I need to set pFoo on other parts of the software, I just can't get a good way to do this in an easy way

the way I thought is:
change the Link(var)
to Link(var, string PropertyName, object OwnerObjectOfTheProperty

and through reflection use PropertyInfo to set it with SetValue
that may work, but I wouldn't like to have to type the property name everytime, its a little lame, see:

Expand|Select|Wrap|Line Numbers
  1.   public FooBar Foo{
  2.   get{
  3.     if (pFoo == null)
  4.       StaticFunction.Link((pFoo = new FooBar()), "Foo", this);
  5.  
  6.     return pFoo;
  7.   }
  8.   set{
  9.     StaticFunction.ReLink(value, pFoo);
  10.     pFoo = value;
  11.   }
  12.   }
  13.   private FooBar pFoo = null;
  14.  
and because some other developers will use this, I would like to know if there is a better to do it
maybe passing Foo as a propertyinfo, or delegate or whatever

any help plz?
( a preprocessor macro would do this so easy, wouldn't it =[ )

Thanks!
Joe
Aug 20 '08 #1
0 641

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: TS | last post by:
Hello, I am trying to have a member of a class declared as an arrayList to have get & set property accessors, but I can't get it to compile. This member variable can't be a simple array because I...
4
by: TS | last post by:
what would be the scenario that you would want to declare a variable of a class in that fashion instead of a public property accessor?
4
by: Leon | last post by:
Why this code is not working? I think the problem is in the business class code. ****My Business Class------------ ' Private variables '- - - - - - - - - - - - - - - - - - - - - - - - - - - - -...
7
by: Jaimi McEntire | last post by:
Given a property define like this: public decimal ControlAmount { get { return mControlAmount; } set { mControlAmount = value; } } I expected (under release mode) that when used as a...
5
by: TS | last post by:
is it preferred to access member variables directly in code, on the page that declared them, versus going thru a property accessor? I would think that since theres no security concerns or anything...
5
by: turnitup | last post by:
Hi, I need to access the innerHTML property of a div using the dot notation, eg document.body.div, rather than the GetElementbyID. So far I have not found the correct way to do it. I would be...
2
by: slawrence | last post by:
Hi I am getting an error "Code generation for property 'SubCategoryId' failed. Error was 'Property accessor 'SubCategoryId' on object 'yyy.zzz' threw the following exception: 'Object reference...
0
by: slawrence | last post by:
Hi I am getting an error "Code generation for property 'SubCategoryId' failed. Error was 'Property accessor 'SubCategoryId' on object 'yyy.zzz' threw the following exception: 'Object reference...
3
by: martin | last post by:
just wondering.... Say i have a class with 3 nonstatic properties P1, P2 and P3. Now somebody creates an instance of my class and calls any of them (instance1.P2) Is it possible to execute some...
7
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I access a property of an object using a string?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.