C# Create New T()

You can see what I’m trying (but failing) to do with the following code: protected T GetObject() { return new T(); } Any help would be greatly appreciated. EDIT: The context was as follows. I was playing around with a custom controller class for all controllers to derive from, with standardised methods. So in context, … Read more

When to dispose CancellationTokenSource?

The class CancellationTokenSource is disposable. A quick look in Reflector proves usage of KernelEvent, a (very likely) unmanaged resource. Since CancellationTokenSource has no finalizer, if we do not dispose it, the GC won’t do it. On the other hand, if you look at the samples listed on the MSDN article Cancellation in Managed Threads, only … Read more

.NET NewtonSoft JSON deserialize map to a different property name

I have following JSON string which is received from an external party. { “team”:[ { “v1″:””, “attributes”:{ “eighty_min_score”:””, “home_or_away”:”home”, “score”:”22″, “team_id”:”500″ } }, { “v1″:””, “attributes”:{ “eighty_min_score”:””, “home_or_away”:”away”, “score”:”30″, “team_id”:”600″ } } ] } My mapping classes: public class Attributes { public string eighty_min_score { get; set; } public string home_or_away { get; set; } … Read more