Skip to main content

Posts

Restoring Nuget packages in less annoying way

Hope most of you are aware of Nuget packages. It is a way to get 3rd party libraries into your project. Nuget also makes developer's life easier by checking for updates for all the available libraries. Apart from this Nuget also provides package restoration option, which is disabled by default. Another annoying thing about restoration is, it is very very slow. So, it means that until your restoration is complete, you can not do anything. What is the solution or workaround of this slow restoration of Nuget package ? Well, one workaround can be instead of restoring packages from Visual Studio, why can't we do it outside of Visual Studio. Interesting, isn't it ??? A Very simple and straight forward command to do this is: NuGet.exe restore [SolutionFile] –PackagesDirectory [PackagesDirectory]

Congratulations! You have received MVP award

Hey folks, I have something very exciting to share with you all. Today morning, I received a mail stating " Congratulations!  You have received MVP award” . At first I didn’t believed my eyes, but after reading a mail, finally I got a feel that I really won. Actually it was surprised for me too !!! I’m really proud that someone noticed my technical skills and what I do for community. Whenever I meet or look at other MVPs, I always think, “Wow, these guys are brilliant! Simply awesome…I wish I could…” But finally it happened. I’m honored to be a part of the C# community. It’s a privilege. MVP: MVP is an annual award given by C# corner to its community leaders who actively share their technical skills and excellent knowledge.  This award recognizes exceptional technical community leaders who have deep understanding on some technology and how they can contribute to communities so that people around them can make the most out of them. Every day, around the world, M...

Customizing debugging session - Part II

Continuing to my previous article on 'Customizing debugging session' , we can further control on how properties and fields appear in our debugger window. Based on our debugging requirement, we can show and hide properties in our debugging session using one of the useful attribute named DebuggerBrowsableAttribute . Let’s go ahead and see debug window for one of the code snippet: In above image you will notice that by default list of Awards is not in expanded form. In order to view the values of awards, one needs to expand that forcibly either by hovering the mouse or by click on the plus symbol, which will result in below screenshot: How to hide unwanted properties during debugging session? What if a developer is not interested in viewing employee’s branch? Well, that unwanted property can be made hidden by using DebuggerBrowsableState as Never as shown below: Now let’s run the code and check, whether it is h...

Customizing debugging session - Part I

I hope, being a developer everyone needs to debug their code at least once a day even if it is a very small snippet. Frankly speaking, sometimes it becomes very frustrating when we are looking for a value of particular property or let’s say very few properties of a huge object and it gets TIMEOUT. Uhhh !!! This time, we feel like there should be some easy way to navigate to that particular property instead of going to the object and clicking on plus symbol to reach the required property. Well, let’s understand it via code: Aim: I have an Employee class with two members as EmployeeName and BranchName. I want to know the name and branch of an Employee during my debugging session. So, I start debugging and lend up on below screen: Now in order to view the required details, I need to expand the employee object as shown in below screenshot: Now first question is, is there any way to display customized message in debugger window?  Answer wo...

FallbackValue and TargetNullValue

One of the ability of binding in WPF is the ability to support Fallback values. Fallback values are used when a binding comes up with an un-appropriate value which in turn can't be set on binding target. There are 2 types of Fallback values:        TargetNullValue :     As its name communicate itself that when a source object’s property is null, then what is the alternate value you want to set for the target. So, whatever value is set for TargetNullValue, it will be set for target. Pretty simple, isn't it ? 2   FallbackValue :      This is used when a binding cannot come up with a value at all, based on the the data source and the path. Or in other words, FallbackValue is used when the property binded with source is not at all available. In that case, value supplied to FallbackValue will be considered at the target end. Getting into the code:  Now, let’s jump on to the code on how to use both of these. ...

Gotcha with StringFormat

Hope most of you have used StringFormat property on your binding to render the formatted value on the user interface. But are you aware about one of its secret. Well before revealing that secret, let’s have a look at how StringFormat works with binding. Scenario problem: I am taking an example scenario, in which my text box will display amount till three decimals.  Now there are multiple ways to achieve this. One way can be by using Converters, another way can be by using StringFormat along with TextBox binding. Perhaps there can be more ways apart from these two ;) In below sample I am going to take StringFormat trick to achieve this and code to perform this operation is very straight forward as: <TextBox Text="{Binding Amount,StringFormat=f3}" /> With above code, whenever you will lost focus from your TextBox, given amount will be displayed as three decimal points. Till here everything is perfect as expected BUT with one downsize. Important...

Converters in WPF

Converters give you a lot supremacy as it allows you to insert an object between a source and a target object. At high level, converters are a chunk of custom code that hooked up through the binding and data will flow via that converter. So, whenever data is flown from source to target, one can change the value or can change the type of object that needs to be set on target property. So, whenever data travels from source to target, it can be transformed in two ways: Data value: Here transformation will be done with just the value by keeping the data type intact. For example, for number fields, you can transform value to floating point number to an integer, by keeping the actual value as a float. Data type:  One can also transform the data type. For example, setting a style based on some Boolean flag, this is one of the most common example. Isn't it? Defining a converter: Defining any converter requires implementation of IValueConverter interface in a class. Thi...