This article marks the beginning of a new series of posts, which aims to dig deeper into 26 different features of .Net. For the first article, or the A - I have selected Anonymous Types. I would have chosen asynchronous programming, but I have whole dedicated series on asynchronous programming which could followed in this link. Introduced … Continue reading A2Z.Net : A – Anonymous Types
Category: C#
MemoryCache – AddOrGetExisting Method
MemoryCache provides an easy to use method AddOrGetExisting which provides an easy way to retrive or add data to cache. While it is extremely convenient, it comes off at a cost. Let's explore it a bit along with alternative. Note : For the sake of example, let us ignore multi-threading scenarios for the moment. public class MemoryCacheRunner { … Continue reading MemoryCache – AddOrGetExisting Method
Stay Open Functionality for Oxyplot Tracker
One of the recent questions on Stackoverflow was about having a Oxyplot tracker that Is evoked only over the Points and NOT line/outside.Stays Open until another point is selected. The first part could be easily achieved by using a Custom PlotController that Binds the Mouse Down event only the Left Mouse Button and only on Tracks CustomPlotController = … Continue reading Stay Open Functionality for Oxyplot Tracker
C# 9.0 : Top Level Programs and Targeted type ‘new’ Expression
In the previous post, we saw how C# 9.0 introduced the init only properties. In this blog post, we will explore some more of the language features which would be introduced in C# 9.0. Top Level Programs One of the annonying quality of any programming language is the baggage of boiler plate code that needs to be written … Continue reading C# 9.0 : Top Level Programs and Targeted type ‘new’ Expression
Evolution of Properties : C# 1 to C# 9
Properties in .Net has evolved over time, retaining its core functionality while making it super sleek via subtle changes. Let us take a brief look at the evolution before digging in deeper about the features introduced in C# 9. C# 1.0. Back when it all started, if you were to declare a property in C#, … Continue reading Evolution of Properties : C# 1 to C# 9
C# 8 : Nullable Reference Types, Null Forgiving and Null Coalescing Assignment
There are some properties that ought to be learned together to understand the complete picture. In this blog post, we will address two of such features. Nullable Reference Types Let us begin by writing some code. public class Foo { public Bar Bar { get; set; } } public class Bar { public int Id … Continue reading C# 8 : Nullable Reference Types, Null Forgiving and Null Coalescing Assignment
C# 8 : Asynchronous Streams and Static Local Functions
Asynchronous StreamHow often have you come across situations when you would want to return streams of data from an asynchronous method ? Plenty of times I would guess. The asynchronous methods were pretty limited when return data in streams, but not any longer. Consider the following code. // Will not compile public static async Task<IEnumerable<int>> Generate(int max) { for (int i = 0; i < max; i++) { await Task.Delay(1000); yield return i; } } The above code would not compile. There is no way you could `yield return` values (or in other words, stream values) from an asynchronous method. This would have been a highly useful situation when you want to iterate over results from a query over an extremely large database. There are other countless situation the ability to stream data from asynchronous method could be useful. However, prior to C# 8.0, we were severely handicapped in such a situation. With C# 8.0, .Net comprises a new Type called the IAsyncEnumerable, which allows us to accomplis this. The above code could be now rewritten … Continue reading C# 8 : Asynchronous Streams and Static Local Functions
Asynchronous Code – Behind the Scenes – 004
During this series of deep dive into the asynchronous calls, we have so far looked into [x] General Structure of generated code.[x] Role of Stub/Worker method.[x] Structure of State Machine and role of Fields.[x] Implementation of the SetStateMachine method.[ ] Implementation of the MoveNext method. It is now time to look at the most important piece of the puzzle … Continue reading Asynchronous Code – Behind the Scenes – 004
Asynchronous Code – Behind the Scenes – 003
Okay, I wasn't quite realistic in the earlier post when I mentioned we would look at MoveNext in this one. I missed an important clog of the wheel. The SetStateMachine() method. IAsyncStateMachine.SetStateMachine We will only breifly visit the SetStateMachine method here, as the complete picture becomes more clear when we look to details of the MoveNext() method. So how does the SetStateMachine method … Continue reading Asynchronous Code – Behind the Scenes – 003
Asynchronous Code – Behind the Scenes – 002
In the earlier part of this series, we reviewed the generic structure of decompiled async code, especially the stub method. In this part, we would continue our explore of async code and look into the State Machine. We would not delve deep into the most important MoveNext() method yet, we will first familiar with the different parts … Continue reading Asynchronous Code – Behind the Scenes – 002