[{"data":1,"prerenderedAt":1021},["ShallowReactive",2],{"blog:2007:partial-methods-in-net-35-overview-and-evolution":3,"blogMore-Development":975,"comments-partial-methods-in-net-35-overview-and-evolution":988},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"category":11,"tags":12,"excerpt":16,"body":31,"_type":967,"_id":968,"_source":969,"_file":970,"_stem":971,"_extension":972,"url":973,"wordCount":974,"minutes":107,"commentCount":64},"/blog/2007/partial-methods-in-net-35-overview-and-evolution","2007",false,"en","Partial methods in .NET 3.5, overview and evolution","One of the interesting new things in .NET 3.5 is partial methods which are now being used extensively by LINQ to SQL and no-doubt will be Microsoft’s corner-post of extensibility for generated classes. Here’s a quick overview:","2007-08-02T00:17:10+00:00","Development",[13,14,15],".NET","LINQ","C#",{"type":17,"children":18},"root",[19,26],{"type":20,"tag":21,"props":22,"children":23},"element","p",{},[24],{"type":25,"value":9},"text",{"type":20,"tag":21,"props":27,"children":28},{},[29],{"type":25,"value":30},"When inheriting from generated classed designers often provide virtual methods for you to override and extend at a cost of being forced to inherit from the generated class instead of one of your own choosing. e.g.",{"type":17,"children":32,"toc":961},[33,37,44,48,325,331,336,341,346,699,705,710,915,921,926,941,946,955],{"type":20,"tag":21,"props":34,"children":35},{},[36],{"type":25,"value":9},{"type":20,"tag":38,"props":39,"children":41},"h2",{"id":40},"extending-generated-code-via-inheritance-net-11",[42],{"type":25,"value":43},"Extending generated code via inheritance (.NET 1.1)",{"type":20,"tag":21,"props":45,"children":46},{},[47],{"type":25,"value":30},{"type":20,"tag":49,"props":50,"children":55},"pre",{"className":51,"code":52,"language":53,"meta":54,"style":54},"language-csharp shiki shiki-themes everforest-light dracula","class Customer {\n    private string name;\n    public string Name {\n        set {\n            name = value;\n            OnNameChanged();\n        }\n    }\n    protected virtual void OnNameChanged() {\n    }\n}\n\nclass Customer : CustomerGenerated {\n    protected override void OnNameChanged() {\n        DoSomething();\n    }\n}\n","csharp","",[56],{"type":20,"tag":57,"props":58,"children":59},"code",{"__ignoreMap":54},[60,84,105,123,136,155,170,179,188,217,225,234,244,271,296,309,317],{"type":20,"tag":61,"props":62,"children":65},"span",{"class":63,"line":64},"line",1,[66,72,78],{"type":20,"tag":61,"props":67,"children":69},{"style":68},"--shiki-default:#F85552;--shiki-dark:#FF79C6",[70],{"type":25,"value":71},"class",{"type":20,"tag":61,"props":73,"children":75},{"style":74},"--shiki-default:#3A94C5;--shiki-dark:#8BE9FD",[76],{"type":25,"value":77}," Customer",{"type":20,"tag":61,"props":79,"children":81},{"style":80},"--shiki-default:#5C6A72;--shiki-dark:#F8F8F2",[82],{"type":25,"value":83}," {\n",{"type":20,"tag":61,"props":85,"children":87},{"class":63,"line":86},2,[88,94,100],{"type":20,"tag":61,"props":89,"children":91},{"style":90},"--shiki-default:#F57D26;--shiki-dark:#FF79C6",[92],{"type":25,"value":93},"    private",{"type":20,"tag":61,"props":95,"children":97},{"style":96},"--shiki-default:#3A94C5;--shiki-dark:#FF79C6",[98],{"type":25,"value":99}," string",{"type":20,"tag":61,"props":101,"children":102},{"style":80},[103],{"type":25,"value":104}," name;\n",{"type":20,"tag":61,"props":106,"children":108},{"class":63,"line":107},3,[109,114,118],{"type":20,"tag":61,"props":110,"children":111},{"style":90},[112],{"type":25,"value":113},"    public",{"type":20,"tag":61,"props":115,"children":116},{"style":96},[117],{"type":25,"value":99},{"type":20,"tag":61,"props":119,"children":120},{"style":80},[121],{"type":25,"value":122}," Name {\n",{"type":20,"tag":61,"props":124,"children":126},{"class":63,"line":125},4,[127,132],{"type":20,"tag":61,"props":128,"children":129},{"style":96},[130],{"type":25,"value":131},"        set",{"type":20,"tag":61,"props":133,"children":134},{"style":80},[135],{"type":25,"value":83},{"type":20,"tag":61,"props":137,"children":139},{"class":63,"line":138},5,[140,145,150],{"type":20,"tag":61,"props":141,"children":142},{"style":80},[143],{"type":25,"value":144},"            name ",{"type":20,"tag":61,"props":146,"children":147},{"style":90},[148],{"type":25,"value":149},"=",{"type":20,"tag":61,"props":151,"children":152},{"style":80},[153],{"type":25,"value":154}," value;\n",{"type":20,"tag":61,"props":156,"children":158},{"class":63,"line":157},6,[159,165],{"type":20,"tag":61,"props":160,"children":162},{"style":161},"--shiki-default:#8DA101;--shiki-dark:#50FA7B",[163],{"type":25,"value":164},"            OnNameChanged",{"type":20,"tag":61,"props":166,"children":167},{"style":80},[168],{"type":25,"value":169},"();\n",{"type":20,"tag":61,"props":171,"children":173},{"class":63,"line":172},7,[174],{"type":20,"tag":61,"props":175,"children":176},{"style":80},[177],{"type":25,"value":178},"        }\n",{"type":20,"tag":61,"props":180,"children":182},{"class":63,"line":181},8,[183],{"type":20,"tag":61,"props":184,"children":185},{"style":80},[186],{"type":25,"value":187},"    }\n",{"type":20,"tag":61,"props":189,"children":191},{"class":63,"line":190},9,[192,197,202,207,212],{"type":20,"tag":61,"props":193,"children":194},{"style":90},[195],{"type":25,"value":196},"    protected",{"type":20,"tag":61,"props":198,"children":199},{"style":90},[200],{"type":25,"value":201}," virtual",{"type":20,"tag":61,"props":203,"children":204},{"style":96},[205],{"type":25,"value":206}," void",{"type":20,"tag":61,"props":208,"children":209},{"style":161},[210],{"type":25,"value":211}," OnNameChanged",{"type":20,"tag":61,"props":213,"children":214},{"style":80},[215],{"type":25,"value":216},"() {\n",{"type":20,"tag":61,"props":218,"children":220},{"class":63,"line":219},10,[221],{"type":20,"tag":61,"props":222,"children":223},{"style":80},[224],{"type":25,"value":187},{"type":20,"tag":61,"props":226,"children":228},{"class":63,"line":227},11,[229],{"type":20,"tag":61,"props":230,"children":231},{"style":80},[232],{"type":25,"value":233},"}\n",{"type":20,"tag":61,"props":235,"children":237},{"class":63,"line":236},12,[238],{"type":20,"tag":61,"props":239,"children":241},{"emptyLinePlaceholder":240},true,[242],{"type":25,"value":243},"\n",{"type":20,"tag":61,"props":245,"children":247},{"class":63,"line":246},13,[248,252,256,261,267],{"type":20,"tag":61,"props":249,"children":250},{"style":68},[251],{"type":25,"value":71},{"type":20,"tag":61,"props":253,"children":254},{"style":74},[255],{"type":25,"value":77},{"type":20,"tag":61,"props":257,"children":258},{"style":80},[259],{"type":25,"value":260}," : ",{"type":20,"tag":61,"props":262,"children":264},{"style":263},"--shiki-default:#3A94C5;--shiki-default-font-style:inherit;--shiki-dark:#8BE9FD;--shiki-dark-font-style:italic",[265],{"type":25,"value":266},"CustomerGenerated",{"type":20,"tag":61,"props":268,"children":269},{"style":80},[270],{"type":25,"value":83},{"type":20,"tag":61,"props":272,"children":274},{"class":63,"line":273},14,[275,279,284,288,292],{"type":20,"tag":61,"props":276,"children":277},{"style":90},[278],{"type":25,"value":196},{"type":20,"tag":61,"props":280,"children":281},{"style":90},[282],{"type":25,"value":283}," override",{"type":20,"tag":61,"props":285,"children":286},{"style":96},[287],{"type":25,"value":206},{"type":20,"tag":61,"props":289,"children":290},{"style":161},[291],{"type":25,"value":211},{"type":20,"tag":61,"props":293,"children":294},{"style":80},[295],{"type":25,"value":216},{"type":20,"tag":61,"props":297,"children":299},{"class":63,"line":298},15,[300,305],{"type":20,"tag":61,"props":301,"children":302},{"style":161},[303],{"type":25,"value":304},"        DoSomething",{"type":20,"tag":61,"props":306,"children":307},{"style":80},[308],{"type":25,"value":169},{"type":20,"tag":61,"props":310,"children":312},{"class":63,"line":311},16,[313],{"type":20,"tag":61,"props":314,"children":315},{"style":80},[316],{"type":25,"value":187},{"type":20,"tag":61,"props":318,"children":320},{"class":63,"line":319},17,[321],{"type":20,"tag":61,"props":322,"children":323},{"style":80},[324],{"type":25,"value":233},{"type":20,"tag":38,"props":326,"children":328},{"id":327},"extending-generated-code-via-delegatesevent-handlers-net-20",[329],{"type":25,"value":330},"Extending generated code via delegates/event handlers (.NET 2.0)",{"type":20,"tag":21,"props":332,"children":333},{},[334],{"type":25,"value":335},".NET 2.0 introduced partial classes and code generation moved into separate files that were pulled together at compile-time to provide a single consistent class leaving you free to choose your own inheritance.",{"type":20,"tag":21,"props":337,"children":338},{},[339],{"type":25,"value":340},"The drawback is that you can not override generated methods because they are not inherited but rather merged at compile-time.",{"type":20,"tag":21,"props":342,"children":343},{},[344],{"type":25,"value":345},"This means if you want to provide extensibility in your generated code you will either need to use inheritance or generate delegates/events that consumers of your class can hook up. This works but is not intuitive as demonstrated:",{"type":20,"tag":49,"props":347,"children":349},{"className":51,"code":348,"language":53,"meta":54,"style":54},"partial class Customer {\n  protected event EventHandler NameChangedHandler;\n  private string name;\n  public string Name {\n    set {\n      name = value;\n      if (NameChangedHandler != null)\n          NameChangedHandler.Invoke(this, null);\n    }\n  }\n}\n\npartial class Customer {\n  public Customer() {\n    NameChangedHandler += OnNameChanged;\n  }\n\n  protected void OnNameChanged(object sender, EventArgs e) {\n    DoSomething();\n  }\n}\n",[350],{"type":20,"tag":57,"props":351,"children":352},{"__ignoreMap":54},[353,374,397,413,429,441,457,486,525,532,540,547,554,573,588,606,613,620,670,683,691],{"type":20,"tag":61,"props":354,"children":355},{"class":63,"line":64},[356,361,366,370],{"type":20,"tag":61,"props":357,"children":358},{"style":90},[359],{"type":25,"value":360},"partial",{"type":20,"tag":61,"props":362,"children":363},{"style":68},[364],{"type":25,"value":365}," class",{"type":20,"tag":61,"props":367,"children":368},{"style":74},[369],{"type":25,"value":77},{"type":20,"tag":61,"props":371,"children":372},{"style":80},[373],{"type":25,"value":83},{"type":20,"tag":61,"props":375,"children":376},{"class":63,"line":86},[377,382,387,392],{"type":20,"tag":61,"props":378,"children":379},{"style":90},[380],{"type":25,"value":381},"  protected",{"type":20,"tag":61,"props":383,"children":384},{"style":96},[385],{"type":25,"value":386}," event",{"type":20,"tag":61,"props":388,"children":389},{"style":263},[390],{"type":25,"value":391}," EventHandler",{"type":20,"tag":61,"props":393,"children":394},{"style":80},[395],{"type":25,"value":396}," NameChangedHandler;\n",{"type":20,"tag":61,"props":398,"children":399},{"class":63,"line":107},[400,405,409],{"type":20,"tag":61,"props":401,"children":402},{"style":90},[403],{"type":25,"value":404},"  private",{"type":20,"tag":61,"props":406,"children":407},{"style":96},[408],{"type":25,"value":99},{"type":20,"tag":61,"props":410,"children":411},{"style":80},[412],{"type":25,"value":104},{"type":20,"tag":61,"props":414,"children":415},{"class":63,"line":125},[416,421,425],{"type":20,"tag":61,"props":417,"children":418},{"style":90},[419],{"type":25,"value":420},"  public",{"type":20,"tag":61,"props":422,"children":423},{"style":96},[424],{"type":25,"value":99},{"type":20,"tag":61,"props":426,"children":427},{"style":80},[428],{"type":25,"value":122},{"type":20,"tag":61,"props":430,"children":431},{"class":63,"line":138},[432,437],{"type":20,"tag":61,"props":433,"children":434},{"style":96},[435],{"type":25,"value":436},"    set",{"type":20,"tag":61,"props":438,"children":439},{"style":80},[440],{"type":25,"value":83},{"type":20,"tag":61,"props":442,"children":443},{"class":63,"line":157},[444,449,453],{"type":20,"tag":61,"props":445,"children":446},{"style":80},[447],{"type":25,"value":448},"      name ",{"type":20,"tag":61,"props":450,"children":451},{"style":90},[452],{"type":25,"value":149},{"type":20,"tag":61,"props":454,"children":455},{"style":80},[456],{"type":25,"value":154},{"type":20,"tag":61,"props":458,"children":459},{"class":63,"line":172},[460,465,470,475,481],{"type":20,"tag":61,"props":461,"children":462},{"style":68},[463],{"type":25,"value":464},"      if",{"type":20,"tag":61,"props":466,"children":467},{"style":80},[468],{"type":25,"value":469}," (NameChangedHandler ",{"type":20,"tag":61,"props":471,"children":472},{"style":90},[473],{"type":25,"value":474},"!=",{"type":20,"tag":61,"props":476,"children":478},{"style":477},"--shiki-default:#DF69BA;--shiki-dark:#BD93F9",[479],{"type":25,"value":480}," null",{"type":20,"tag":61,"props":482,"children":483},{"style":80},[484],{"type":25,"value":485},")\n",{"type":20,"tag":61,"props":487,"children":488},{"class":63,"line":181},[489,494,499,504,510,515,520],{"type":20,"tag":61,"props":490,"children":491},{"style":80},[492],{"type":25,"value":493},"          NameChangedHandler.",{"type":20,"tag":61,"props":495,"children":496},{"style":161},[497],{"type":25,"value":498},"Invoke",{"type":20,"tag":61,"props":500,"children":501},{"style":80},[502],{"type":25,"value":503},"(",{"type":20,"tag":61,"props":505,"children":507},{"style":506},"--shiki-default:#DF69BA;--shiki-default-font-style:inherit;--shiki-dark:#BD93F9;--shiki-dark-font-style:italic",[508],{"type":25,"value":509},"this",{"type":20,"tag":61,"props":511,"children":512},{"style":80},[513],{"type":25,"value":514},", ",{"type":20,"tag":61,"props":516,"children":517},{"style":477},[518],{"type":25,"value":519},"null",{"type":20,"tag":61,"props":521,"children":522},{"style":80},[523],{"type":25,"value":524},");\n",{"type":20,"tag":61,"props":526,"children":527},{"class":63,"line":190},[528],{"type":20,"tag":61,"props":529,"children":530},{"style":80},[531],{"type":25,"value":187},{"type":20,"tag":61,"props":533,"children":534},{"class":63,"line":219},[535],{"type":20,"tag":61,"props":536,"children":537},{"style":80},[538],{"type":25,"value":539},"  }\n",{"type":20,"tag":61,"props":541,"children":542},{"class":63,"line":227},[543],{"type":20,"tag":61,"props":544,"children":545},{"style":80},[546],{"type":25,"value":233},{"type":20,"tag":61,"props":548,"children":549},{"class":63,"line":236},[550],{"type":20,"tag":61,"props":551,"children":552},{"emptyLinePlaceholder":240},[553],{"type":25,"value":243},{"type":20,"tag":61,"props":555,"children":556},{"class":63,"line":246},[557,561,565,569],{"type":20,"tag":61,"props":558,"children":559},{"style":90},[560],{"type":25,"value":360},{"type":20,"tag":61,"props":562,"children":563},{"style":68},[564],{"type":25,"value":365},{"type":20,"tag":61,"props":566,"children":567},{"style":74},[568],{"type":25,"value":77},{"type":20,"tag":61,"props":570,"children":571},{"style":80},[572],{"type":25,"value":83},{"type":20,"tag":61,"props":574,"children":575},{"class":63,"line":273},[576,580,584],{"type":20,"tag":61,"props":577,"children":578},{"style":90},[579],{"type":25,"value":420},{"type":20,"tag":61,"props":581,"children":582},{"style":161},[583],{"type":25,"value":77},{"type":20,"tag":61,"props":585,"children":586},{"style":80},[587],{"type":25,"value":216},{"type":20,"tag":61,"props":589,"children":590},{"class":63,"line":298},[591,596,601],{"type":20,"tag":61,"props":592,"children":593},{"style":80},[594],{"type":25,"value":595},"    NameChangedHandler ",{"type":20,"tag":61,"props":597,"children":598},{"style":90},[599],{"type":25,"value":600},"+=",{"type":20,"tag":61,"props":602,"children":603},{"style":80},[604],{"type":25,"value":605}," OnNameChanged;\n",{"type":20,"tag":61,"props":607,"children":608},{"class":63,"line":311},[609],{"type":20,"tag":61,"props":610,"children":611},{"style":80},[612],{"type":25,"value":539},{"type":20,"tag":61,"props":614,"children":615},{"class":63,"line":319},[616],{"type":20,"tag":61,"props":617,"children":618},{"emptyLinePlaceholder":240},[619],{"type":25,"value":243},{"type":20,"tag":61,"props":621,"children":623},{"class":63,"line":622},18,[624,628,632,636,640,645,651,655,660,665],{"type":20,"tag":61,"props":625,"children":626},{"style":90},[627],{"type":25,"value":381},{"type":20,"tag":61,"props":629,"children":630},{"style":96},[631],{"type":25,"value":206},{"type":20,"tag":61,"props":633,"children":634},{"style":161},[635],{"type":25,"value":211},{"type":20,"tag":61,"props":637,"children":638},{"style":80},[639],{"type":25,"value":503},{"type":20,"tag":61,"props":641,"children":642},{"style":96},[643],{"type":25,"value":644},"object",{"type":20,"tag":61,"props":646,"children":648},{"style":647},"--shiki-default:#5C6A72;--shiki-default-font-style:inherit;--shiki-dark:#FFB86C;--shiki-dark-font-style:italic",[649],{"type":25,"value":650}," sender",{"type":20,"tag":61,"props":652,"children":653},{"style":80},[654],{"type":25,"value":514},{"type":20,"tag":61,"props":656,"children":657},{"style":263},[658],{"type":25,"value":659},"EventArgs",{"type":20,"tag":61,"props":661,"children":662},{"style":647},[663],{"type":25,"value":664}," e",{"type":20,"tag":61,"props":666,"children":667},{"style":80},[668],{"type":25,"value":669},") {\n",{"type":20,"tag":61,"props":671,"children":673},{"class":63,"line":672},19,[674,679],{"type":20,"tag":61,"props":675,"children":676},{"style":161},[677],{"type":25,"value":678},"    DoSomething",{"type":20,"tag":61,"props":680,"children":681},{"style":80},[682],{"type":25,"value":169},{"type":20,"tag":61,"props":684,"children":686},{"class":63,"line":685},20,[687],{"type":20,"tag":61,"props":688,"children":689},{"style":80},[690],{"type":25,"value":539},{"type":20,"tag":61,"props":692,"children":694},{"class":63,"line":693},21,[695],{"type":20,"tag":61,"props":696,"children":697},{"style":80},[698],{"type":25,"value":233},{"type":20,"tag":38,"props":700,"children":702},{"id":701},"extending-generated-code-via-partial-methods-net-35",[703],{"type":25,"value":704},"Extending generated code via partial methods (.NET 3.5)",{"type":20,"tag":21,"props":706,"children":707},{},[708],{"type":25,"value":709},".NET 3.5 sees Microsoft answer the problem by allowing the partial keyword to be used at method level instead of just at class level:",{"type":20,"tag":49,"props":711,"children":713},{"className":51,"code":712,"language":53,"meta":54,"style":54},"partial class Customer {\n  private string name;\n  public string Name {\n    set {\n      name = value;\n      OnNameChanged();\n    }\n  }\n  partial void OnNameChanged();\n}\n\npartial class Customer {\n  partial void OnNameChanged() {\n    DoSomething();\n  }\n}\n",[714],{"type":20,"tag":57,"props":715,"children":716},{"__ignoreMap":54},[717,736,751,766,777,792,804,811,818,838,845,852,871,890,901,908],{"type":20,"tag":61,"props":718,"children":719},{"class":63,"line":64},[720,724,728,732],{"type":20,"tag":61,"props":721,"children":722},{"style":90},[723],{"type":25,"value":360},{"type":20,"tag":61,"props":725,"children":726},{"style":68},[727],{"type":25,"value":365},{"type":20,"tag":61,"props":729,"children":730},{"style":74},[731],{"type":25,"value":77},{"type":20,"tag":61,"props":733,"children":734},{"style":80},[735],{"type":25,"value":83},{"type":20,"tag":61,"props":737,"children":738},{"class":63,"line":86},[739,743,747],{"type":20,"tag":61,"props":740,"children":741},{"style":90},[742],{"type":25,"value":404},{"type":20,"tag":61,"props":744,"children":745},{"style":96},[746],{"type":25,"value":99},{"type":20,"tag":61,"props":748,"children":749},{"style":80},[750],{"type":25,"value":104},{"type":20,"tag":61,"props":752,"children":753},{"class":63,"line":107},[754,758,762],{"type":20,"tag":61,"props":755,"children":756},{"style":90},[757],{"type":25,"value":420},{"type":20,"tag":61,"props":759,"children":760},{"style":96},[761],{"type":25,"value":99},{"type":20,"tag":61,"props":763,"children":764},{"style":80},[765],{"type":25,"value":122},{"type":20,"tag":61,"props":767,"children":768},{"class":63,"line":125},[769,773],{"type":20,"tag":61,"props":770,"children":771},{"style":96},[772],{"type":25,"value":436},{"type":20,"tag":61,"props":774,"children":775},{"style":80},[776],{"type":25,"value":83},{"type":20,"tag":61,"props":778,"children":779},{"class":63,"line":138},[780,784,788],{"type":20,"tag":61,"props":781,"children":782},{"style":80},[783],{"type":25,"value":448},{"type":20,"tag":61,"props":785,"children":786},{"style":90},[787],{"type":25,"value":149},{"type":20,"tag":61,"props":789,"children":790},{"style":80},[791],{"type":25,"value":154},{"type":20,"tag":61,"props":793,"children":794},{"class":63,"line":157},[795,800],{"type":20,"tag":61,"props":796,"children":797},{"style":161},[798],{"type":25,"value":799},"      OnNameChanged",{"type":20,"tag":61,"props":801,"children":802},{"style":80},[803],{"type":25,"value":169},{"type":20,"tag":61,"props":805,"children":806},{"class":63,"line":172},[807],{"type":20,"tag":61,"props":808,"children":809},{"style":80},[810],{"type":25,"value":187},{"type":20,"tag":61,"props":812,"children":813},{"class":63,"line":181},[814],{"type":20,"tag":61,"props":815,"children":816},{"style":80},[817],{"type":25,"value":539},{"type":20,"tag":61,"props":819,"children":820},{"class":63,"line":190},[821,826,830,834],{"type":20,"tag":61,"props":822,"children":823},{"style":90},[824],{"type":25,"value":825},"  partial",{"type":20,"tag":61,"props":827,"children":828},{"style":96},[829],{"type":25,"value":206},{"type":20,"tag":61,"props":831,"children":832},{"style":161},[833],{"type":25,"value":211},{"type":20,"tag":61,"props":835,"children":836},{"style":80},[837],{"type":25,"value":169},{"type":20,"tag":61,"props":839,"children":840},{"class":63,"line":219},[841],{"type":20,"tag":61,"props":842,"children":843},{"style":80},[844],{"type":25,"value":233},{"type":20,"tag":61,"props":846,"children":847},{"class":63,"line":227},[848],{"type":20,"tag":61,"props":849,"children":850},{"emptyLinePlaceholder":240},[851],{"type":25,"value":243},{"type":20,"tag":61,"props":853,"children":854},{"class":63,"line":236},[855,859,863,867],{"type":20,"tag":61,"props":856,"children":857},{"style":90},[858],{"type":25,"value":360},{"type":20,"tag":61,"props":860,"children":861},{"style":68},[862],{"type":25,"value":365},{"type":20,"tag":61,"props":864,"children":865},{"style":74},[866],{"type":25,"value":77},{"type":20,"tag":61,"props":868,"children":869},{"style":80},[870],{"type":25,"value":83},{"type":20,"tag":61,"props":872,"children":873},{"class":63,"line":246},[874,878,882,886],{"type":20,"tag":61,"props":875,"children":876},{"style":90},[877],{"type":25,"value":825},{"type":20,"tag":61,"props":879,"children":880},{"style":96},[881],{"type":25,"value":206},{"type":20,"tag":61,"props":883,"children":884},{"style":161},[885],{"type":25,"value":211},{"type":20,"tag":61,"props":887,"children":888},{"style":80},[889],{"type":25,"value":216},{"type":20,"tag":61,"props":891,"children":892},{"class":63,"line":273},[893,897],{"type":20,"tag":61,"props":894,"children":895},{"style":161},[896],{"type":25,"value":678},{"type":20,"tag":61,"props":898,"children":899},{"style":80},[900],{"type":25,"value":169},{"type":20,"tag":61,"props":902,"children":903},{"class":63,"line":298},[904],{"type":20,"tag":61,"props":905,"children":906},{"style":80},[907],{"type":25,"value":539},{"type":20,"tag":61,"props":909,"children":910},{"class":63,"line":311},[911],{"type":20,"tag":61,"props":912,"children":913},{"style":80},[914],{"type":25,"value":233},{"type":20,"tag":38,"props":916,"children":918},{"id":917},"thoughts",[919],{"type":25,"value":920},"Thoughts",{"type":20,"tag":21,"props":922,"children":923},{},[924],{"type":25,"value":925},"This is clearer than using delegates & events but still suffers some limitations:",{"type":20,"tag":927,"props":928,"children":929},"ul",{},[930,936],{"type":20,"tag":931,"props":932,"children":933},"li",{},[934],{"type":25,"value":935},"Only one method can have a body so you can’t override generated code",{"type":20,"tag":931,"props":937,"children":938},{},[939],{"type":25,"value":940},"Properties are not supported",{"type":20,"tag":21,"props":942,"children":943},{},[944],{"type":25,"value":945},"If .NET supported multiple inheritance then partial classes and methods would be redundant. As Microsoft tout interfaces and composition as a better approach it is about time they added support to automatically wire up an interface to a compound object (a blog post for another time).",{"type":20,"tag":21,"props":947,"children":948},{},[949],{"type":20,"tag":950,"props":951,"children":952},"em",{},[953],{"type":25,"value":954},"[)amien",{"type":20,"tag":956,"props":957,"children":958},"style",{},[959],{"type":25,"value":960},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":54,"searchDepth":86,"depth":86,"links":962},[963,964,965,966],{"id":40,"depth":86,"text":43},{"id":327,"depth":86,"text":330},{"id":701,"depth":86,"text":704},{"id":917,"depth":86,"text":920},"markdown","content:blog:2007:partial-methods-in-net-35-overview-and-evolution.md","content","blog/2007/partial-methods-in-net-35-overview-and-evolution.md","blog/2007/partial-methods-in-net-35-overview-and-evolution","md","/blog/2007/partial-methods-in-net-35-overview-and-evolution/",469,[976,980,984],{"title":977,"date":978,"url":979},"HTML5 Video Cheatsheet: Optimizing videos for the web","2025-12-05T00:00:00Z","/blog/2025/html5-video-cheatsheet/",{"title":981,"date":982,"url":983},"Transactions in the MongoDB EF Core Provider","2025-10-25","/blog/2025/mongodb-explicit-transactions/",{"title":985,"date":986,"url":987},"Queryable Encryption with the MongoDB EF Core Provider","2025-09-22","/blog/2025/mongodb-queryable-encryption/",[989],{"_path":990,"_dir":991,"_draft":6,"_partial":6,"_locale":7,"title":992,"description":993,"id":994,"name":995,"email":996,"avatar":997,"url":998,"date":999,"body":1000,"_type":967,"_id":1018,"_source":969,"_file":1019,"_stem":1020,"_extension":972},"/comments/partial-methods-in-net-35-overview-and-evolution/1954","partial-methods-in-net-35-overview-and-evolution","1954",".Net looks more like C++ every day ;) The ability to use 'partial' on methods basically makes the non-generated code a C++ header file.",1954,"steve","steve@stevestreeting.com","https://www.gravatar.com/avatar/fbe8cc9ac5bc8797382e01e10f5f8e33?r=pg&d=retro","https://www.stevestreeting.com","2007-08-02T18:12:41",{"type":17,"children":1001,"toc":1016},[1002,1006,1011],{"type":20,"tag":21,"props":1003,"children":1004},{},[1005],{"type":25,"value":993},{"type":20,"tag":21,"props":1007,"children":1008},{},[1009],{"type":25,"value":1010},"Personally I think it overcomplicates things to mix generated and non-generated code in one class. They're trying to address the practical difficulties of doing so when in fact I think they should be avoiding it entirely.",{"type":20,"tag":21,"props":1012,"children":1013},{},[1014],{"type":25,"value":1015},"Version by version I see .Net become more and more complex and think each time it takes it further away from the productivity gains you get from standardising and simplifying. I've said it before but I don't think layering more complexity in the core language (as opposed to keeping it simpler and providing features through libraries) always makes the platform any more productive. C++ is less productive for business apps because it's more complex and there are a hundred ways to do something, and I do wonder whether .Net is getting ever closer to that.",{"title":54,"searchDepth":86,"depth":86,"links":1017},[],"content:comments:partial-methods-in-net-35-overview-and-evolution:1954.md","comments/partial-methods-in-net-35-overview-and-evolution/1954.md","comments/partial-methods-in-net-35-overview-and-evolution/1954",1779264592410]