Here's what I'd like to do.
I want to write POCO classes like this:
[AutoExtended]
public partial class Foo {
public int Bar;
public string Baz;
}
preferably in arbitrary files in my solution (the [AutoExtend]
attribute is something I just made up to identify the classes of interes).
I want the build process to start by (a) looking for these AutoExtend
classes in my source code and (b) automatically generate extensions like this:
public partial class Foo {
public static SomeType<int> Bar(Foo x) { ... };
public static SomeOtherType<string> Baz(Foo x) { ... };
}
before compiling the solution.
Does anyone know how best to do this? I imagine Roslyn is the way to go, but I'm open to advice. Ideally, I'd like a solution which requires zero extra "plumbing" on the part of the user other than the AutoExtend
attribute.
(In case anyone is interested, I'm writing a domain specific language in terms of C# classes with overloaded operators and the above would make the DSL substantially more comfortable to use.)