title: How to make clone of static variables of static class in c#
body: <p>I am working on different approaches of cloning of an objects in c# but currently I stuck with the simple one. I have a static class with static variables &amp; I want to make an exact copy of one of my static variable.I have sketched my code structure below:  </p>
  
  <pre><code>public static class RULE_SET
  {
      public static bool IsdataValid;
      public static GCBRequest GCBData;
  
      public static T Clone&lt;T&gt;(this T source)
      {
          try
          {
              if (!typeof(T).IsSerializable)
              {                   
                  throw new ArgumentException("The type must be serializable.", "source");
              }            
              if (Object.ReferenceEquals(source, null))
              {                   
                  return default(T);
              }
  
              IFormatter formatter = new BinaryFormatter();
              Stream stream = new MemoryStream();
              using (stream)
              {
                  formatter.Serialize(stream, source);
                  stream.Seek(0, SeekOrigin.Begin);
                  return (T)formatter.Deserialize(stream);
              }
          }
          catch (Exception ee) { return default(T); }
      }
  }
  
  [XmlRoot(ElementName = "GCBRequest")]
      public class GCBRequest
      {
          [XmlElement(ElementName = "PID")]
          public string PID { get; set; }
          [XmlElement(ElementName = "AID")]
          public string AID { get; set; }
          [XmlElement(ElementName = "CID")]
          public string CID { get; set; }
       }
  </code></pre>
  
  <p>//code to load the RULE_SET</p>
  
  <pre><code>    string strJsonRuleset = "{\r\n  \"GCdBINRequest\": {\r\n\"PID\": \"(?s).*#M#20\",\r\n\"AID\": \"(?s).*#O#10\",\r\n\"CID\": \"(?s).*#O#25\"\r\n  }\r\n}";
       public class RULE_SET_LOCAL 
      {
          public static GCBRequest GCBData;
      }
      //from other method
    RULE_SET_LOCAL objParentRuleSet = new RULE_SET_LOCAL(); 
    objParentRuleSet = JsonConvert.DeserializeObject&lt;RULE_SET_LOCAL&gt;(strJsonRuleset);
    RULE_SET.GCBData = objParentRuleSet.GCBData;
  </code></pre>
  
  <p>//Main Method from which I have to create a clone object</p>
  
  <pre><code>  Object objRuleset;
    objRuleset =  RULE_SET.GCBData.Clone();
  
    if(objRuleset == null)
    {
    ** stuck here**
     I don't know why Everytime I got the null object ?
    }
    // but I have use
    objRuleset = RULE_SET.GCBData;
    if(objRuleset != null)
    {
     ** Successfully reached **
     //But I can't do any operation on this object as it will effect the original one.
    } 
  </code></pre>
  
  <p>Guys, Do you have any solution/Suggestion ? 
  Please help me to understand this , any help will be appreciated.</p>
  
  <p>Thanks.</p>