Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. public static readonly DependencyProperty ValueProperty =
  2. DependencyProperty.Register
  3. ( "Value"
  4. , typeof(T)
  5. , typeof(ValidatingTextBox<T,C>)
  6. , new FrameworkPropertyMetadata(default(T), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)
  7. );
  8.  
  9. public static T MyDefault<T>(){
  10.  
  11. switch(typeof(T)){
  12. case (typeof(String)) : return "";
  13. case (typeof(Foo)) : return new Foo();
  14. }
  15.  
  16. }
  17.  
  18. DefaultGenerator<T>.Default
  19.  
  20. private static Dictionary<Type,Func<object>> factory = new Dictionary<Type,Func<object>>{
  21. {typeof(string), ()=> String.Empty },
  22. {typeof(MyClass), ()=> new MyClass() },
  23. };
  24. public static T MyDefault<T>()
  25. {
  26.  
  27. Type t = typeof(T);
  28. Func<object> func = null;
  29.  
  30. if(factory.TryGetValue(t, out func))
  31. return (T)func();
  32. else
  33. return default(T);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement