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 Answers
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.
3 Comments
Powerslave
Lazy whan't do the job, can u offer some library that will create proxy for me?
Powerslave
sorry but can u offer something else, coz castle didn't match my needs&
Powerslave
Problem solved, but problem was that, I needed to create proxy for class that have non virtual methods that needed to be intercepted!
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.
Finderattribute?