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

Popular posts from this blog

xml - Extract substrings with XSLT -

math - "ELO Rating" and how does "TSR Rating" work? -

How can do a tuple comparison in coffeescript similar to that in python? -