c# - Is it possible to create an extension method that is called when the object is created? -


i cannot modify object working , need method want called when object created. thinking extension method here, don't know if possible but, if is, how?

edited:

my static class has main object supposed create:

ecuversion ecu; 

i call method class:

ecu = convertautodetect.convert(rawdata, ecu, response); 

and platform looking ecu object.

my method return ecuversion object. object contains collection besides lot of other things , working respective collection is:

icollection<autodetectstep> autodetectsteps { get; set; } 

autodetectstep class has 4 childs , on 1 of it's childs needed extension method called when child created.

i have create many childs , add them collection, also, never instantiated object because static in there.

so suitable use factory pattern ?

no, not possible. if unreliable because depend on whether included relevant extension using or not. that's general problem of extension methods here it's worse never cause compile time error.

the best way how implement using factory pattern indirectly construct object , inject factory in code. still doesn't solve problem of existing code though.


Comments

Popular posts from this blog

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - SSE Emitter : Manage timeouts and complete() -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -