Lazy initialization for objects that initializing by reflection
I have my own attribute [Finder]
for fields and p开发者_开发问答roperties, 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.
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.
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.
精彩评论