code_junkie

How are partial methods used in C# 3.0?

Nov 10th, 2011
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. [System.Data.Linq.Mapping.DatabaseAttribute(Name="MyDB")]
  2. public partial class MyDataContext : System.Data.Linq.DataContext
  3. {
  4. ...
  5.  
  6. partial void OnCreated();
  7. partial void InsertMyTable(MyTable instance);
  8. partial void UpdateMyTable(MyTable instance);
  9. partial void DeleteMyTable(MyTable instance);
  10.  
  11. ...
  12.  
  13. public partial class MyDataContext
  14. {
  15. partial void OnCreated() {
  16. //do something on data context creation
  17. }
  18. }
  19.  
  20. //this code will get optimised out if no body is implemented
  21. partial void DoSomethingIfCompFlag();
  22.  
  23. #if COMPILER_FLAG
  24. //this code won't exist if the flag is off
  25. partial void DoSomethingIfCompFlag() {
  26. //your code
  27. }
  28. #endif
Add Comment
Please, Sign In to add comment