Guest User

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

a guest
Feb 26th, 2012
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  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. }
Add Comment
Please, Sign In to add comment