In this post, we will look into an application of Source Generator. Quite often, during debugging, you would wish if you had overridden the ToString() method of the class, so that you could understand the state of the instance. These are especially useful when you are dealing with a collection of the type. The ToString() would provide you a … Continue reading Source Generator : AutoToString
Tag: .Net
CLSCompliant Attribute
While developing a library in .Net which could be used by another programming language than it was originally designed in, it is important to remember that the .Net Languages offers a subset of CLR/CTS while offering a superset of CLS. And, if you want to develop a library that could be used by any programming … Continue reading CLSCompliant Attribute
Workaround for MySql 5.7 EF DbFirst Issue
Anyone working on .Net application with MySql 5.7 and EF in Db First Approach would have come across what is an officially confirmed bug. This bug rises when you attempt to generate/update your Entity Model after changes to the Database. "Unable to generate the model because of the following exception: 'System.Data.StrongTypingException: The value for column … Continue reading Workaround for MySql 5.7 EF DbFirst Issue
Parse Sub-Folders which do not contain specified file extension.
An easier way to parse for folders, which do not contain files with a specified extension.
Rethrow Exception
CA2200 : Rethrow to preserve stack details. That's one recommendation that as a developer you might have seen when running Code Analysis on your solution. So what does it mean ? What does the guilty code looks like and what is the correct way to throw exceptions. Lets start with incorrect code first. Considering following … Continue reading Rethrow Exception
Mocking IDispossible with “Using”
Mocking objects is integral part of Unit Testing. The nucleus of Mocking is Dependency Injection, which allows us to inject Mock object into the code. But what happens when programmer has used the "Using" keyword ? For Example, This makes it difficult to mock DbCommand. The solution lies in deploying Factory Pattern to create our CustomDbCommand. For … Continue reading Mocking IDispossible with “Using”
Composite Primary Key using Data Annotations
When developing domain classes in Entity Framework using Code First Approach, the default code conventions creates a primary key of a property named "ID" or <ClassName>ID. But if you wanted to use another property as your primary key , you can use DataAnnotations and decorate the property using "Key" attribute. What is more interesting is … Continue reading Composite Primary Key using Data Annotations
Evil Code 0002 Optional Parameter Vs Method Overloading
Again one of those things which looks so simple, but could drive one mad during debugging. Much before Optional Parameters came in, C# developers used to depend on Method Overloading for mimicking Optional Parameters. Consider a scenario where both exists, what would be the output ? The output would be : The reason behind this … Continue reading Evil Code 0002 Optional Parameter Vs Method Overloading
Customized Debugger Tooltip
Code-Execute-Debug-Code-Execute-Debug.. This seems to be never ending cycle for any developer. Considerable amount of time of this cycle is spend in Debug phase, wherein user steps through breakpoints and traverse the objects and their properties. Thankfully, Microsoft has ensured that primitive types always shows the value, instead of any less-meaningful information. But what happens when … Continue reading Customized Debugger Tooltip
Evil Code 0001 : Lambda and Ref/out
What would be output of following ? static void Main(string [] args) { List< int> numlist = new List< int>() {1,2, 3, 4, 5, 6, 7 }; CalculateAndPrint( ref numlist); } public static void CalculateAndPrint( ref List< int> Num) { var n = Num.Where(d => d > Num[2]); foreach ( var item in n) { Console.WriteLine(item); } } The most obvious answer is … Continue reading Evil Code 0001 : Lambda and Ref/out