Posts

WeakReference and WeakEventManager (listener)

Both are perfect as long as you understand the concept. Essentially, whilst instances of the Weak classes can be rooted, their contents cannot. For example: Something that naughtily references the object inside WeakReference may magically lose this reference once it get's GC'd. Any subscribers to events attached via the WeakEventManager class will GC'd once the underlying instance of the WeakEventManager is GC'd.
 public class ImapClientGmail : ImapClient     {         public ImapClientGmail()             : base()         {         }         public ImapClientGmail(string host, string username, string password, ImapClient.AuthMethods method = ImapClient.AuthMethods.Login, int port = 143, bool secure = false, bool skipSslValidation = false)             : base(host, username, password, method, port, secure, skipSslValidation)         {         }         public string GETTAG()         {             var method = typeof(ImapClient).GetMethod("GetTag", BindingFlags.NonPublic | BindingFlags.Instance);             return (string)method.Invoke(this, null);         }   ...

Visual Studio 2012 Theming

Image
Our team has recently upgraded from Visual Studio 2010 to Visual Studio 2012. I couldnt get to grips with the colour theming of the revamped UI. 'Light' was too light, and 'Dark' was too dark...if that makes sense. I reached a happy medium by importing the text editor colour scheme from my old VS2010 setup, as show in the screenshot below. This can be replicated by doing the following: Download the following text file:  http://pastebin.com/download.php?i=tt0x6eYZ Save the extension as '.vssettings' In VS2012, Set the default theme to 'Light' (Tools  >  Options  >  Environment  >  General). Tools  >  Import / Export Settings  >  Import Selected Environment Settings, then selecting the file you downloaded above.

Distance between two gps coordinates?

private static double Radians(double x) { return x * Math.PI / 180d; } public static DistanceContainer DistanceBetweenPlaces(decimal lat1, decimal lon1, decimal lat2, decimal lon2) { return DistanceBetweenPlaces((double)lat1, (double)lon1, (double)lat2, (double)lon2); } public static DistanceContainer DistanceBetweenPlaces(double lat1, double lon1, double lat2, double lon2) { double dlat = Radians(lat2 - lat1); double dlon = Radians(lon2 - lon1); lat1 = Radians(lat1); lat2 = Radians(lat2); var a = Math.Sin(dlat / 2d) * Math.Sin(dlat / 2d) + Math.Sin(dlon / 2d) * Math.Sin(dlon / 2d) * Math.Cos(lat1) * Math.Cos(lat2); var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1d - a)); return new DistanceContainer(c); }

c# 'params' keyword

The 'params' keyword. Basically 'params' has the runtime encapsulate the parameters in an array when passed to the method, so: void main() { foo(1,2,3); bar(new int[]{1,2,3}); } void foo (params int[] i){} void bar (int[] i){} Can be treated similarly. It must be placed at the end of a list of method parameters

Difference between interface and abstract class

Abstract Class versus Interface