Scott Hanselman

Leaning on the Language and Leaning on the Libraries

February 23, '06 Comments [2] Posted in ASP.NET | Web Services | XmlSerializer | NCover | CodeRush | HttpHandler | Tools
Sponsored By

Coderush2What fun I'm having. I'm collaborating on a project for work. We're still using Visual Studio 2003 and .NET 1.1, but we're still wildly productive.

One interesting thing I've learned is that I lean on the libraries, while Paul, my counter-part leans on the language. He knows what language constructs to use and I know what BCL methods to use. Together we make an effective pair, but this realization helped us both better understand our weak areas. One can write lots of C in C#, if you know what I mean.

Do you lean on the language or the libraries?

We've been doing some fun stuff with XML lately, you might have noticed. We've used:

Also. we're using:

class KindOfPartialSgmlButMoreOfAnOfxXmlWriter : XmlWriter

{

    public KindOfPartialSgmlButMoreOfAnOfxXmlWriter(TextWriter w)

    {

        _htmlWriter = new HtmlTextWriter(w);

    }

 

    public override void Close()

    {

        _htmlWriter.Close();

    }

 

    private Stack _tags = new Stack();

    private HtmlTextWriter _htmlWriter = null;

    private bool _suppressNextEndElement = false;

    private bool _suppressNextText = false;

    private string _previousElement = null;

 

    public override void WriteStartElement(string prefix, string localName, string ns)

    {

        _htmlWriter.WriteFullBeginTag(localName);

        _previousElement = localName;

        _tags.Push(localName);

    }

 

    public override void WriteString(string text)

    {

        if (_suppressNextText == false)

        {

            _htmlWriter.Write(text);

            _suppressNextEndElement = true;

        }

    }

 

    public override void WriteEndElement()

    {

        string endtag = _tags.Pop() as string;

        if (_suppressNextEndElement && endtag == _previousElement)

        {

            _suppressNextEndElement = false;

        }

        else

        {

            _htmlWriter.WriteEndTag(endtag);

        }

    }

 

    public override void Flush()

    {

        _htmlWriter.Flush();

    }

 

    public override void WriteWhitespace(string ws)

    {

        _htmlWriter.Write(ws);

    }

 

    public override void WriteRaw(string data)

    {

        _htmlWriter.Write(data);

    }

 

    public override void WriteChars(char[] buffer, int index, int count)

    {

        _htmlWriter.Write(buffer, index, count);

    }

 

    public override void WriteQualifiedName(string localName, string ns)

    {

        _htmlWriter.WriteBeginTag(localName);

    }

 

    public override void WriteEndAttribute()

    {

        _suppressNextText = false;

    }

 

    public override void WriteStartAttribute(string prefix, string localName, string ns)

    {

        _suppressNextText = true;

    }

 

    public override void WriteRaw(char[] buffer, int index, int count)

    {

        _htmlWriter.Write(buffer,index,count);

    }

 

    public override void WriteProcessingInstruction(string name, string text)

    {

        _htmlWriter.Write(text);

    }

  

    #region Stubs

 

    ...here are overriden versions of everything else from XmlWriter, stubbed and not used. Removed for tidiness

 

    #endregion

}

 

 

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web
Thursday, February 23, 2006 9:48:55 AM UTC
If you like the new CC metric feature of CodeRush, you might also consider using Mark Miller's metric (http://www.doitwith.net/CommentView.aspx?guid=39a0e537-5d0e-4f9b-ac5c-51e8b3d1d4ec) that is implemented in the following DxCore plugin - https://sourceforge.net/projects/crplugin/.
Thursday, February 23, 2006 11:35:01 AM UTC
Oh and don't think we haven't noticed that cute little guy you sneak into your screen shots ;).
Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.