I have two identical classes in different namespaces:
namespace NP1 {
public class AAA {
public int A {get; set;}
public int B {get; set;}
}
}
namespace NP2 {
public class AAA {
public int A {get; set;}
public int B {get; set;}
}
}
They are in different files and they are autogenerated. I can't modify them.
Then I have two other files:
using NP1;
public class N1Helper {
(...)
var sth = new AAA(A: some_value, B: some_other_value);
(...)
}
and
using NP2;
public class N2Helper {
(...)
var sth = new AAA(A: some_value, B: some_other_value);
(...)
}
The skipped parts of these helpers are identical.
I'd like to simplify these two files and write the code only once. If the classes in these namespaces would implement an interface, I could do it.
Is there a way I can solve this problem...
- Using generics?
- Telling somewhere a posteriori that
NP1.AAAandNP2.AAAimplement a common interface? Something like using partial classes and appending the interface information in a latter stage, but I can't modify the autogenerated files. - ...?