title: How should be the architecture of the object in C# if there are few properties and out of those only one be used at a time?
body: <p>I have classes like below:</p>
  <pre><code>public class APIAuth
  {
      public ServiceAuthenticationMethod AuthenticationMethod { get; set; }
  
      public BasicAuthentication BasicAuth { get; set; }
  
      public SigV4Authentication SigV4Auth { get; set; }
      
      public JwtAuth { get; set; }
  
   }
  
  
  public enum ServiceAuthenticationMethod
  {
      Anonymous = 1,
      BasicAuthentication = 2,
      SigV4 = 3,
      Jwt = 4,
  }
  
   public class BasicAuthentication
   {
      public string UserName { get; set; }
  
      public string Password { get; set; }
   }
  
   public class SigV4Authentication
   {
      public string AccessKey { get; set; }
  
      public string SecretKey { get; set; }
  
      public string Region { get; set; }
  
      public string ServiceName { get; set; }
  
      public string SessionToken { get; set; }
   }
  
   public class JwtAuthentication
   {
      public string Token{ get; set; }
   }
  </code></pre>
  <p>Now, based on the <code>AuthenticationMethod</code> property of the <code>APIAuth</code> class, one of the properties will be having value and the others will be null. For e.g., if <code>AuthenticationMethod</code> has <code>BasicAuthentication</code> as a value, then the <code>BasicAuth</code> property of the <code>APIAuth</code> class will be having value and <code>SigV4Auth</code> and <code>JwtAuth</code> would be null. And when storing the data in the database, either of the Auth property will be serialized and stored depending upon the <code>AuthenticationMethod</code> value.</p>
  <p>So is there any way to create a class so that there would be only one property called <code>AuthenticationType</code> and it would be having value based on the <code>AuthenticationMethod</code>? So that, when storing in the database, I can simply serialize the <code>AuthenticationType</code> value and when deserializing back I can specify the type as <code>AuthenticationType</code>.</p>
  <p>Not sure if it is possible or not but I am open to suggestions of having a better approach.</p>