0

I have my own attribute [Finder] for fields and properties, and I have a kind of factory that initializing all fields and properties as I want. Question: I want to do kind of lazy initialization(object be created only when I calling some methods of this object) for objects that i'm initializing. Note: properties and fields could be different types.

2
  • What does your factory do with the Finder attribute? Commented Jul 20, 2011 at 9:14
  • it just extracting 2 fields from it(selectors) that helps to find html elements on web page Commented Jul 20, 2011 at 9:16

2 Answers 2

1

Depending on how the initialization happens, you can use the new Lazy<T> type. Another possibility would be to return a automatically created subclass of your class - a proxy - that checks the state of the initialization at every method call and executed the initialization if necessary.

Sign up to request clarification or add additional context in comments.

3 Comments

Lazy whan't do the job, can u offer some library that will create proxy for me?
sorry but can u offer something else, coz castle didn't match my needs&
Problem solved, but problem was that, I needed to create proxy for class that have non virtual methods that needed to be intercepted!
1

You might be able to make use of System.Lazy<T>. Otherwise, you'll have to implement logic to keep track of what properties/fields have been initialized yourself.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.