using System.Data.SqlClient;
    using System.Xml;

    public static class Extensions
    {
        // http://stackoverflow.com/questions/1772025/sql-data-reader-handling-null-column-values - for original extension method
        // https://blogs.msdn.com/b/pedram/archive/2007/06/02/extension-methods-in-c-3-0.aspx - for tip on static class called "Extensions"
        public static string SafeGetString(this SqlDataReader reader, int colIndex)
        {
            return !reader.IsDBNull(colIndex) ? reader.GetString(colIndex) : string.Empty;
        }

        public static string SafeGetString(this SqlDataReader reader, string colName)
        {
            return !reader.IsDBNull(reader.GetOrdinal(colName)) ? reader.GetString(reader.GetOrdinal(colName)) : string.Empty;
        }

        //http://stackoverflow.com/questions/1176202/c-xmltextwriter-writeelementstring-fails-on-empty-strings/1176214#1176214
        public static void WriteFullElementString(this XmlWriter writer,
                                          string localName,
                                          string value)
        {
            writer.WriteStartElement(localName);
            writer.WriteString(value);
            writer.WriteFullEndElement();
        }

        //http://stackoverflow.com/questions/1176202/c-xmltextwriter-writeelementstring-fails-on-empty-strings/1176214#1176214
        public static void WriteFullElementString(this XmlWriter writer,
                                          string localName)
        {
            writer.WriteFullElementString(localName, string.Empty);
        }
    }