Refactor Code

Latest Refactorings
  • Gravatar
    Enumerating Enum Values

    by azamsharp on 8/27/2008 2:09:56 PM (C#)
    Refactorings => 0
  • Here is a nice way to enumerate Enum values.
  • private string[] GetAllColorNames()
    {
    List<String> colorNames = new List<string>();


    foreach(KnownColor color in Enum.GetValues(typeof(KnownColor)))
    {
    colorNames.Add(color.ToString());
    }

    return colorNames.ToArray();
    }
  • Gravatar
    Retrive Tag children

    by alaqunaibi on 8/25/2008 11:19:45 PM (LINQ to XML)
    Refactorings => 0
  • Retrieve All Tag Descendants which Tag parent equal epecified ID
  • var query = from c in loaded.Descendants("Columns")
    where c.Parent.HasAttributes && (string) c.Parent.Attribute("ID")==ID
    select c ;
  • Gravatar
    How to Cache Parameter based Method Results

    by azamsharp on 8/14/2008 8:13:12 PM (C#)
    Refactorings => 2
  • Recently, I posted about how to cache the result of the method using the custom attributes. One of the difficulty I was having was to cache the result of the parameter based method. This means GetCustomerById(1) should be cached separately then the GetCustomerById(2). Below you can find partial implementation which cache the results of the method with no parameters. For the complete post check out the following URL: http://azamsharp.com/Posts/75_Implementing_CacheCall_Attribute_to_Cache_Method_Results.aspx
  • public static TResult Invoke<TSource,TResult>(TSource service,string methodName,object[] parameters)
    {
    CacheCallAttribute cacheCallAtt = null;

    string key = String.Format("{0}_{1}", (string) HttpContext.Current.Session["UniqueId"],
    methodName);

    MethodInfo method = service.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);
  • Gravatar
    How to use ValidationGroup with user controls

    by azamsharp on 8/14/2008 8:10:12 PM (ASP.NET)
    Refactorings => 0
  • How do you use ValidationGroup control with the user controls? Like how do you make a user control behave like a unit and validate only that user control. I have used the following approach. Here is the post: http://azamsharp.com/Posts/77_Unraveling_the_Mysterious_of_the_ValidationGroup_Control.aspx
  • public class BaseUserControl : UserControl
    {
    public BaseUserControl()
    {
    // automatically register the event
    this.Load += new EventHandler(BaseUserControl_Load);
    }

    void BaseUserControl_Load(object sender, EventArgs e)
    {
    // something!
    AssignValidationGroupToControls();
    }

    // assign the validation group to the controls
    protected void AssignValidati
  • Gravatar
    Forcing Users to Type Caps in TextBox Control

    by azamsharp on 7/30/2008 8:48:04 AM (ASP.NET)
    Refactorings => 2
  • This was a question posted on the ASP.NET forums. How can I make sure that everything typed in the TextBox is capitalized. The easiest way to do this is by using plain old CSS.
  • <style type="text/css">
    .t
    {
    text-transform: uppercase
    }
    </style>



    <asp:TextBox ID="txtName" CssClass="t" runat="server"></asp:TextBox>