XMLSerializer, XDocument and LINQ

I took the sample from my previous post and wanted to use LINQ to query the XML. You can pretty much use the power of SQL on the document object to richly query for things you are looking for.   using System; using System.Linq; using System.Xml.Linq; using System.Collections.Generic; using System.Xml; using System.Xml.Serialization; using System.IO;  …

5

XmlSerialization to generate and consume XML

I want to talk about Xml Serialization this month. One of the work I was involved in recently required generation of XML and a I came across this wonderful technology which helps you generate and consume XML seamlessly.   If you are generating XML in a clumsy way using printf containing the XML tags, I…

4

Simple sample for Events and Delegates

I wanted to write a small sample to illustrate events and delegates. Here is a compact sample that illustrates it.   using System; public class EventSample {     public delegate void EventHandler();     public event EventHandler myeh;       public void Method()     {         Console.WriteLine(“Inside Sample Method … “);     }       public…

2

DBNull and Nullable types

When we have C# code interacting with the data base you run into this problem. Let me try and explain it. The database has nullable columns and C# has nullable types. For example, let us take a table Employee which has Id (int), name (string) and age (int). Let us assume that age will be…

13

Diagnostics: Using ETW tracing in .NET 3.5 (EventProviderTraceListener)

.NET exposes an elegant diagnostics model that can be used by applications. It is a bit confusing to start with. There are a few listeners that exist in the Diagnostics namespace. Some of them are   1.       TextWriterTraceListener 2.       DefaultTraceListener 3.       EventLogTraceListener 4.       EventProviderTraceListener 5.       EventSchemaTraceListener 6.       XMLWriterTraceListener 7.       ConsoleTraceListener   The EventSchemaTraceListener, EventLogTraceListener and…

7

Handling, throwing – exceptions and Clean up on error

There are four ways to throw an exception in my opinion. They are:   1.  Throw a new exception a.  throw new ArgumentException( … ); 2.  Throw the exception you caught a.  throw e; 3.  Throw the same exception preserving the stack a.  throw; 4.  Throw with the original exception as an internal exception a. …

5

Code Access Security, LinkDemand and Effective Sandbox

I wrote about Deny and Assert in my previous blog post. In my repeated attempts to get the previous sample working for LinkDemand, I discovered that Deny and PermitOnly are not effective against LinkDemand. The code worked all the time and I was wondering why.   After some good research and lots of learning (from…

1

Code Access Security – Understanding Demand and Declarative Security

I wanted to talk about Code Access Security this time. Code Access Security is a big in itself. In this post I wanted to talk about Declarative Security. Declarative security uses attributes to place security information on assemblies, classes and methods.   In the sample below I have defined a method “MethodDemandingFileIOPermission” which demands “FileIOPermission”…

1