Reputation: 42266
I am generating value objects and I want to switch my approach from templates to CodeDom approach.
I want my types to implement one or two self-referencing generic interfaces (namely IEquatable<MyValueObject>
and IComparable<MyValueObject>
).
I have been able to get the desired result by doing string manipulation and calling the equivalent of CodeTypeDeclaration.Members.Add("IEquatable<MyValueObject")
, but I would rather use the object model if this is possible. Is there a better way or are strings going to be my best bet?
Upvotes: 3
Views: 1217
Reputation: 244968
You can do something like:
var type = new CodeTypeDeclaration("MyValueObject");
var iequatable = new CodeTypeReference(
"IEquatable", new CodeTypeReference(type.Name));
type.BaseTypes.Add(iequatable);
Upvotes: 3