c# - Customizing autogenerated partial classes -
i have autogenerated partial classes like:
public partial class myentity { ... }
i use myentity.partial.cs
file extend partial class. want avoid situation autogenerated myentity disappears or renamed customized myentity.partial.cs stays , compiles without errors.
how ensure can extend existing partial classes?
i not sure there exists good solution this.
here a solution.
have auto-generated classes contain following:
partial void compiletimecheckthatautogeneratedpartexists();
then write in each of hand-written extensions:
partial void compiletimecheckthatautogeneratedpartexists() { }
note: body in auto-generated part semicolon ;
while body in extension part empty block { }
.
when ever auto-generated part disappears, renamed or moved namespace
, compile-time error occur.
Comments
Post a Comment