C#

How to properly deprecate methods

If you work with a C# class that has many deprecated methods in they clutter intellisense and you cannot see the useful methods anymore. To avoid this you can add the Annotation EditorBrowsable and disable intellisense:

[EditorBrowsable(EditorBrowsableState.Never)]
[System.Obsolete("use new method abc instead")]
        public void OldMethodThatShouldNotBeUsedAnymore() {
            // Do some stuff
        }

Tags:

Find out how wpf is being rendered

WPF applications can render in three modes: everything in software, partial hardware rendering or full hardware rendering. The rendering mode may have a big effect to the application performance. This it is important to know which mode is active:

Tags:

C# Syntax Highlighting for HTML Pages

The following website can be used to generate html friendly representation of c# code

Tags:

C# Pass Arguments to the first instance of a program

Sometimes you don't want the user to run more than one instance of a program. But if the user associates a filetype with your programm it shall open the filetype in this first instance. The code below uses interprocess communication to find out if there is already another instance. It further allows the first instance to register an eventhandler which can be called from a second instance in order pass its command line parameters to the first instance.

This is how to use the code:

Tags:

C# Pitfalls

Closures

If you have code like this:

Tags:

Disable validation of Self-Signed Certificates

You can use the following code:

ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;

Be aware that this code does just accept every certificate and it is not only active for one request but for all requests. You should think before you use this code. But for development convenience or on a test system it might be ok to make your program easier to install and test.

Tags:

C# Entity Framework - Clear Context

Put the following code in the partial class of your entity context:

Tags:

WPF: Check if there are validation errors

I worked on a wpf window containing some controls that were required and that validated the format of the entered data. Once the user pressed a button I wanted to check if there was any validation error and notify the user with an error message. This is how to do it:

Helper class:

Tags:

C# Dijkstra

Implementation

Uses the HeapPriorityQueue.
Code on Github

Tags:

C# PriorityQueue with fast Update operation

Implementation

Uses a heap for fast retrieval of the smallest element as well as a dictionary for a fast access to an element which is already in the data strucutre. This priority queue is not too bad for implementing a Dijkstra (a fibonacci heap would be perfect...).
Code on Github

Tags:

Pages

Subscribe to RSS - C#