-
Setting the culture on WPF bindings
Situation You work on WPF bindings, for example a binding to a DateTime object. Problem The DateTime object is displayed in en-US culture format. Solution Set the current culture on the root element, which is most probably the outer most Grid element, of your XAML. For example: Set the culture in the corresponding ViewModel constructor…
-
Using reflection to unit-test private methods
Situation There is a class called “MyClass” which has a private method called “MyPrivateMethod” (which expects a single string parameter) that you want to unit-test. Problem You can’t access private methods from the test class by just calling them. Solution Use reflection to invoke the method. typeof(MyClass).GetMethod(“MyPrivateMethod”, BindingFlags.NonPublic | BindingFlags.Instance) .Invoke(null, new object[] { “MyStringParameter” }); Hint: Static methods require the BindingFlag…