PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/ReactiveUI.Xaml/ServiceLocationRegistration.cs

https://github.com/bsiegel/ReactiveUI
C# | 83 lines | 66 code | 8 blank | 9 comment | 7 complexity | 141488b5a6a1bb2fde82b8e72be3a1d6 MD5 | raw file
Possible License(s): Apache-2.0, CC-BY-SA-3.0, LGPL-2.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Windows;
  8. #if WINRT
  9. using Windows.ApplicationModel;
  10. #endif
  11. namespace ReactiveUI.Xaml
  12. {
  13. /// <summary>
  14. /// Ignore me. This class is a secret handshake between RxUI and RxUI.Xaml
  15. /// in order to register certain classes on startup that would be difficult
  16. /// to register otherwise.
  17. /// </summary>
  18. public class ServiceLocationRegistration : IWantsToRegisterStuff
  19. {
  20. public void Register()
  21. {
  22. #if !MONO
  23. RxApp.Register(typeof (DependencyObjectObservableForProperty), typeof (ICreatesObservableForProperty));
  24. RxApp.Register(typeof (XamlDefaultPropertyBinding), typeof (IDefaultPropertyBindingProvider));
  25. RxApp.Register(typeof (CommandBinderImplementation), typeof (ICommandBinderImplementation));
  26. RxApp.Register(typeof (CreatesCommandBindingViaCommandParameter), typeof(ICreatesCommandBinding));
  27. RxApp.Register(typeof (CreatesCommandBindingViaEvent), typeof(ICreatesCommandBinding));
  28. RxApp.Register(typeof (BooleanToVisibilityTypeConverter), typeof (IBindingTypeConverter));
  29. #if FALSE
  30. if (InDesignMode) {
  31. RxApp.Register(typeof(SampleDataProviderBinder), typeof(IPropertyBinderImplementation));
  32. }
  33. #endif
  34. #endif
  35. #if WINRT
  36. if (!RxApp.InUnitTestRunner()) {
  37. try {
  38. RxApp.DeferredScheduler = System.Reactive.Concurrency.CoreDispatcherScheduler.Current;
  39. } catch (Exception ex) {
  40. throw new Exception("Core Dispatcher is null - this means you've accessed ReactiveUI too early in WinRT initialization", ex);
  41. }
  42. }
  43. #elif MONO
  44. // NB: Mono has like 37 UI Frameworks :)
  45. #else
  46. if (!RxApp.InUnitTestRunner()) {
  47. RxApp.DeferredScheduler = System.Reactive.Concurrency.DispatcherScheduler.Current;
  48. }
  49. #endif
  50. }
  51. static bool? inDesignMode;
  52. /// <summary>
  53. /// Indicates whether or not the framework is in design-time mode.
  54. /// </summary>
  55. public static bool InDesignMode {
  56. get {
  57. if (inDesignMode == null) {
  58. #if WINRT
  59. inDesignMode = DesignMode.DesignModeEnabled;
  60. #elif SILVERLIGHT
  61. inDesignMode = DesignerProperties.IsInDesignTool;
  62. #elif MONO
  63. return false;
  64. #else
  65. var prop = DesignerProperties.IsInDesignModeProperty;
  66. inDesignMode = (bool)DependencyPropertyDescriptor.FromProperty(prop, typeof(FrameworkElement)).Metadata.DefaultValue;
  67. if (!inDesignMode.GetValueOrDefault(false) && Process.GetCurrentProcess().ProcessName.StartsWith("devenv", StringComparison.Ordinal))
  68. inDesignMode = true;
  69. #endif
  70. }
  71. return inDesignMode.GetValueOrDefault(false);
  72. }
  73. }
  74. }
  75. }