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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jodi
    New Member
    • Feb 2007
    • 5

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

    Hi!

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

    example:

    Code:
    public class Fluffers{
      public FooBar Foo{
      get{
        if (pFoo == null)
          StaticFunction.Link((pFoo = new FooBar()));
    
        return pFoo;
      }
      set{
        StaticFunction.ReLink(value, pFoo);
        pFoo = value;
      }
      }
      private FooBar pFoo = null;
    }
    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 OwnerObjectOfTh eProperty

    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:

    Code:
      public FooBar Foo{
      get{
        if (pFoo == null)
          StaticFunction.Link((pFoo = new FooBar()), "Foo", this);
    
        return pFoo;
      }
      set{
        StaticFunction.ReLink(value, pFoo);
        pFoo = value;
      }
      }
      private FooBar pFoo = null;
    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
Working...