C# and .NET Notes
-
C#: Test For Elevated Privileges
Find out whether your code is running as administrator by testing the current Windows principal for the built-in Administrator role.
-
WF 4.0: NullReferenceException in ActivityXamlServices.Load
Loading workflow XAML from a database fails with an unknown-type exception or a bare NullReferenceException. What the errors mean and the workaround that loaded the activity.
-
Dynamically Determine MIME Types in C#
Windows already knows the MIME type of most file extensions. Read the Content Type value under HKEY_CLASSES_ROOT instead of shipping your own lookup table.
-
ANTLR cannot generate ‘org.antlr.v4.codegen.CSharp_v4_5_1Target’ code as of version 4.1-SNAPSHOT
The ANTLR 4 C# target refused to generate code for a grammar. Setting the project's target framework to .NET Framework 4.5 made the build succeed, plus the full error output.
-
Change Current Thread’s Currency Symbol
The current thread's culture is read-only, so assigning a new CurrencySymbol throws. Clone the CultureInfo, change the symbol, and assign the clone back to the thread.
-
A Flexible And Convenient Type Conversion Helper in C#
A small reusable C# helper that converts an object to a target type known only at run time, so calling code stays readable instead of turning into if-then-else chains.