Browse by Tags
All Tags »
Tips & Tricks »
C# (
RSS)
Quick Tip – Making Beep From the PC Speaker Using P/Invoke I was asked yesterday how can we perform a beep sound from the PC speaker. This is something that is needed in one of the applications that I’m consulting for to indicate a successful transaction (don’t ask me way…). Setting the Environment We first need to add the using for Runtime.InteropServices : using System.Runtime.InteropServices; Then load the unmanaged dll of kernel32.dll with the method signature for Beep which...
Error CS0029: Cannot implicitly convert type Using WSDL Tool Today I was asked by one of developers I work with to check an error he got after he generated a proxy class with the wsdl.exe tool from a third party wsdl he got. The error was generated in runtime when he tried to use the generated class and it was something like: Unable to generate a temporary class (result=1). error CS0029: Cannot implicitly convert type 'A' to 'A[]' After searching in the internet I found that there...
Reading a Xml File in T4 Templates After I wrote the post about the use of T4 templates in EF4 , I played with them for a while (not in EF but generally with T4 templates ). In an old project that I’ve created almost 3 years ago which automated the use of lookup tables I had an enum. That enum was meant to be the connection between an Xml node names and was heavily used in the application. For each Xml node I needed to add an entry in the enum. So I thought what the hell lets see if I could have...
Building a Custom Site Map Provider In the last ASP.NET course I delivered I was asked how to build a custom site map provider . This post holds the answer. You can download the full example from here . Building a Custom Site Map Provider There are times that our requirements demand that our site navigation will not be based on the default site map provider . Such times are for example when we want to use a database table to hold our site navigation . In these times we can create a custom site map...
Quick Tip – Using the ShouldSerializeXXX methods Something that I encountered last week. The ShouldSerialize methods are optional methods that you can provide for a class property. These methods are built as ShouldSerialize PropertyName and inside of them you can provide a check that will determine whether the property should be serialized or not. Of course this can be achieved only in serializable classes. An example of use: public string Text { get; set; } public bool ShouldSerializeText...
Back to Basics – Calculating MD5 Hashing Yesterday I needed to use a hashing algorithm for a given task. I chose to use the MD5 hashing algorithm and in this post I’ll show how to calculate MD5 hash from a given string. What is MD5 Hashing Algorithm? MD5 is a very widely used hashing function that commonly used to check the integrity of files or strings. When using MD5 There is a small possibility of getting two identical hashes to two different strings. It is very useful for storing passwords...
Quick Tip – Convert VB.NET to C# or C# to VB.NET There is a need sometimes to convert VB.NET files to C# or vice versa. There are two tools that I use in this process: Code Converter by Telerik – enables the convert of a given piece of code or multiple files. .net code converter – enables the convert of a given piece of code. There are also add-ins to Visual Studio that enables the convert between VB.NET to C# like C-Sharpener For VB but since I don’t have full projects to convert I prefer the above...