Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
Simple Particle Engine for a shooter game
Snake / Nibbles clone in C and Ncurses
Please improve
Parsing of XML data has high CPU usage
Convert simple Javascript to jQuery plugin
Active Record getting unique records
List the files in a directory without the directory name or the extension
clean the code
ohs system, recruitment software, hr software, oh&s software, human resources software, ohs software
Array parsing in a block
Popular
Parsing of XML data has high CPU usage
Snake / Nibbles clone in C and Ncurses
Please improve
List the files in a directory without the directory name or the extension
Convert simple Javascript to jQuery plugin
Active Record getting unique records
Simple Particle Engine for a shooter game
Breadth first cartesian product iterator
php refactoring
first BST
Pastable version of
ASP.NET CSS classes
<pre class='prettyprint' language='cs'>public static void CssAddClass(this Control control, string className) { if (control == null) { throw new ArgumentNullException("control"); } if (className == null) { throw new ArgumentNullException("className"); } string classAttributeValue; if (control is WebControl) { classAttributeValue = (control as WebControl).CssClass; } else if (control is HtmlControl) { classAttributeValue = (control as HtmlControl).Attributes["class"]; } else { throw new ArgumentException ("Must be WebControl or HtmlControl.", "control"); } 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 => name + " ").ToArray()) + className; } if (control is WebControl) { (control as WebControl).CssClass = classAttributeValue; } else if (control is HtmlControl) { (control as HtmlControl).Attributes["class"] = classAttributeValue; } } public static void CssRemoveClass (this Control control, string className, bool mayNotExist) { if (control == null) { throw new ArgumentNullException("control"); } if (className == null) { throw new ArgumentNullException("className"); } string classAttributeValue; if (control is WebControl) { classAttributeValue = (control as WebControl).CssClass; } else if (control is HtmlControl) { classAttributeValue = (control as HtmlControl).Attributes["class"]; } else { throw new ArgumentException ("Must be WebControl or HtmlControl.", "control"); } bool isNullOrEmpty = string.IsNullOrEmpty(classAttributeValue); if (!mayNotExist && isNullOrEmpty) { throw new ArgumentException ("Does not have any CSS classes defined.", className); } else if (isNullOrEmpty) { classAttributeValue = string.Empty; } var classNames = from name in classAttributeValue.Split (new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) where name != className select name + " "; classAttributeValue = string.Concat(classNames.ToArray()).TrimEnd(); if (control is WebControl) { (control as WebControl).CssClass = classAttributeValue; } else if (control is HtmlControl) { (control as HtmlControl).Attributes["class"] = classAttributeValue; } }</pre> <a href="http://www.refactormycode.com/codes/845-asp-net-css-classes" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>