c# - One generic type parameter, different generic for return type? -


so 2 different namespaces, have class record. i'd return appropriate 1 based off type being passed in. try , this, i've attempted this, "t2" incorrect. how can achieve this?

public t2 getgeneratedtype<t1>(string name) t1 : class t2 : class {   var type = typeof(t1);   var generatedname = type.assemblyqualifiedname.replace(type.name, name);   return (t2)activator.createinstance(type.gettype(generatedname)); } 

i haven't tested (won't compile, obviously), how make work if pass namespace1.someclass in, namespace1.record , in case pass in namespace2.someotherclass, namespace2.record (so long name == "record").

i attempted t , didn't give error messages, want make sure input , output types allowed different types.

edit:

i may've not explained entirely.

i'm creating data annotation forked record (technically, 3 people need able assigned record @ given time due 3 distinct processes being performed on them. they're reconciled once 3 processes completed). namespace1 1 project (not in visual studio sense) , namespace2 another. in namespace1 have importedrecord1 , in namespace2 importedrecord2 (both separate projects seperate properties, though more or less serve same purpose). namespace1 , namespace2 both have record type relating importedrecord particular namespace fork 3 "subrecords" of different type (basically imported record of project field relates 1 of 3 processes).

all need set return type dynamic instead of t2. type determined @ runtime.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -