<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:www.refactormycode.com,2007:users1475</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/1475" rel="self"/>
  <title>escapetherace</title>
  <updated>Sat Apr 25 07:05:35 -0700 2009</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor155754</id>
    <published>2009-04-25T07:05:35-07:00</published>
    <title>[C#] On Help me Refactor My Classes &amp; Methods</title>
    <content type="html">&lt;p&gt;What's so horrible about the DAL? Sure, all those parameters don't make for attractive code, but that's what you get without using ORMs. Do you mean the design is horrible, or just the appearance?&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>escapetherace</name>
      <email>obrien_chris@hotmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/831-help-me-refactor-my-class-function/refactors/155754" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code845</id>
    <published>2009-04-25T07:01:57-07:00</published>
    <updated>2009-05-04T07:32:06-07:00</updated>
    <title>[C#] ASP.NET CSS classes</title>
    <content type="html">&lt;p&gt;Have at it.&lt;/p&gt;

&lt;pre&gt;    public static void CssAddClass(this Control control, string className)
    { 
        if (control == null)
        {
            throw new ArgumentNullException(&amp;quot;control&amp;quot;);
        }
 
        if (className == null)
        {
            throw new ArgumentNullException(&amp;quot;className&amp;quot;);
        }
 
        string classAttributeValue;
 
        if (control is WebControl)
        {
            classAttributeValue = (control as WebControl).CssClass;
        }
        else if (control is HtmlControl)
        {
            classAttributeValue = (control as HtmlControl).Attributes[&amp;quot;class&amp;quot;];
        }
        else
        {
            throw new ArgumentException
                (&amp;quot;Must be WebControl or HtmlControl.&amp;quot;, &amp;quot;control&amp;quot;);
        }
 
        if (string.IsNullOrEmpty(classAttributeValue))
        {
            classAttributeValue = className;
        }
        else
        {
            var classNameList = classAttributeValue.Split
                (new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
 
            if (classNameList.Contains(className))
            {
                return;
            }
 
            classAttributeValue = string.Concat
                    (classNameList.Select(name =&amp;gt; name + &amp;quot; &amp;quot;).ToArray()) + className;
        }
 
        if (control is WebControl)
        {
            (control as WebControl).CssClass = classAttributeValue;
        }
        else if (control is HtmlControl)
        {
            (control as HtmlControl).Attributes[&amp;quot;class&amp;quot;] = classAttributeValue;
        }
    }
 
    public static void CssRemoveClass
        (this Control control, string className, bool mayNotExist)
    {
        if (control == null)
        {
            throw new ArgumentNullException(&amp;quot;control&amp;quot;);
        }
 
        if (className == null)
        {
            throw new ArgumentNullException(&amp;quot;className&amp;quot;);
        }
 
        string classAttributeValue;
 
        if (control is WebControl)
        {
            classAttributeValue = (control as WebControl).CssClass;
        }
        else if (control is HtmlControl)
        {
            classAttributeValue = (control as HtmlControl).Attributes[&amp;quot;class&amp;quot;];
        }
        else
        {
            throw new ArgumentException
                (&amp;quot;Must be WebControl or HtmlControl.&amp;quot;, &amp;quot;control&amp;quot;);
        }
 
        bool isNullOrEmpty = string.IsNullOrEmpty(classAttributeValue);
 
        if (!mayNotExist &amp;amp;&amp;amp; isNullOrEmpty)
        {
            throw new ArgumentException
                (&amp;quot;Does not have any CSS classes defined.&amp;quot;, className);
        }
        else if (isNullOrEmpty)
        {
            classAttributeValue = string.Empty;
        }
 
 
        var classNames =
            from name in classAttributeValue.Split
                (new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
            where name != className
            select name + &amp;quot; &amp;quot;;
 
        classAttributeValue = string.Concat(classNames.ToArray()).TrimEnd();
 
        if (control is WebControl)
        {
            (control as WebControl).CssClass = classAttributeValue;
        }
        else if (control is HtmlControl)
        {
            (control as HtmlControl).Attributes[&amp;quot;class&amp;quot;] = classAttributeValue;
        }
    }&lt;/pre&gt;</content>
    <author>
      <name>escapetherace</name>
      <email>obrien_chris@hotmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/845-asp-net-css-classes" rel="alternate"/>
  </entry>
</feed>

