This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

What's the best way to add custom functionality to existing code in C#

By: a guest on Feb 26th, 2012  |  syntax: None  |  size: 0.85 KB  |  views: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. interface IFoo { void Bar();}
  2. class Foo : IFoo {public void Bar() { /* imp 1 */ } }
  3. class FooWrapper : IFoo {
  4.     IFoo parent;
  5.     public FooWrapper(IFoo parent) {this. parent = parent;}
  6.     public void Bar() { /* imp 2, perhaps using "parent" }
  7. }
  8.        
  9. public class BaseUser {
  10.  
  11.     public BaseUser() {}
  12.  
  13.     public bool login() {
  14.  
  15.         return false;
  16.  
  17.     }
  18.  
  19. }
  20.        
  21. public class User : BaseUser {}
  22.        
  23. User u = new User();
  24. u.login();
  25.        
  26. public static int WeekNumber(this DateTime dtPassed)
  27.     {
  28.         CultureInfo ciCurr = CultureInfo.CurrentCulture;
  29.         int weekNum = 0;
  30.         try
  31.         {
  32.             weekNum = ciCurr.Calendar.GetWeekOfYear(dtPassed,
  33.            CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Sunday);
  34.         }
  35.         catch (Exception ex)
  36.         {
  37.             //TODO: Add error handling code
  38.         }
  39.  
  40.         return weekNum;
  41.     }
clone this paste RAW Paste Data