title: Generic Method, Generic Type, Generic Parameter
body: <p>I'm not even sure how to describe what I'm trying to do (sorry, newb), but duplicating code because I haven't figured out how to do correctly isn't high on my list.  Any help, please?</p>
  
  <p>Original non-generic method:</p>
  
  <pre><code>    public static string SerializetaUpdateCreateItemRcd(IVItemMasterType o)
      {
          eConnectType eConnect = new eConnectType();
  
          IVItemMasterType[] myMaster = { o };
  
          // Populate the eConnectType object with the schema object
          eConnect.IVItemMasterType = myMaster;
  
          return MemoryStreamSerializer(eConnect);
      }
  </code></pre>
  
  <p>My attempt at generic, so close, lost at setting typed property (?):</p>
  
  <pre><code>    public static string Serialize&lt;T&gt;(T o) where T : eConnectType
      {
          eConnectType eConnect = new eConnectType();
  
          T[] myMaster = { o };
  
          // Populate the eConnectType object with the schema object
          eConnect.? = myMaster;
  
          return MemoryStreamSerializer(eConnect);
      }
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>Sorry, this all may just be an architecture thing, but there's around 166 possible combinations and it just seems ridiculous to code this one step for each one.  I may have to do just that though...</p>
  
  <p>MS Doc reference to eConnect:  <a href="http://msdn.microsoft.com/en-us/library/ff623781.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ff623781.aspx</a></p>
  
  <p>Example code that calls the serialization:</p>
  
  <pre><code>    IVItemMasterType o = new IVItemMasterType();
  
      o.eConnectProcessInfo = null;
      o.taCreateInternetAddresses_Items = null;
      o.taCreateItemVendors_Items = null;
      o.taCreateKitItemRcd_Items = null;
      o.taItemSite_Items = null;
      o.taIVCreateItemPriceListHeader = null;
      o.taIVCreateItemPriceListLine_Items = null;
      o.taRequesterTrxDisabler_Items = null;
      o.taUpdateCreateItemCurrencyRcd_Items = null;
      o.taUpdateCreateItemRcd = eConnectHelper.taUpdateCreateItemRcdFactory(eItem);
  
      // Serialize into string &amp; add to list
      List&lt;string&gt; sList = new List&lt;string&gt;();             
      sList.Add(eConnectHelper.Serialize(o));
  
      // Submit list to eConnect
      eCreateEntity(sList);
  </code></pre>
  
  <p>SerializeMemoryStream code:</p>
  
  <pre><code>    public static string MemoryStreamSerializer(eConnectType e)
      {
          XmlSerializer serializer = new XmlSerializer(e.GetType());
  
          using (var memoryStream = new MemoryStream())
          {
              serializer.Serialize(memoryStream, e);
              memoryStream.Position = 0;
  
              // Use memory streamed XML document to create a string representation of the object
              XmlDocument xmldoc = new XmlDocument();
              xmldoc.Load(memoryStream);
              memoryStream.Close();
              string sDocument = xmldoc.OuterXml;
  
              return sDocument;
          }
      }
  </code></pre>
  
  <p><strong>Update 2:</strong></p>
  
  <p>Many thanks to both of you.  After sleeping on it, I realized the error in my architecture.  I have to build the eConnect object either way and I'm already building the sub-type object in the previous method call, so I've back-tracked and moved the typed serialize code into the main calling method.</p>
  
  <p>I did try the reflection, and while it did compile and run, for some reason it excepted with an ObjectReference/NullReference despite, as far as I could tell, all the objects being populated.</p>
  
  <p>Here's how I was using it:</p>
  
  <pre><code>    public static string Serialize&lt;T&gt;(T o)
      {
          eConnectType e = new eConnectType();
  
          T[] myMaster = { o };
  
          // Populate the eConnectType object with the schema object
          typeof(eConnectType).GetProperty(typeof(T).Name).SetValue(e, myMaster, null);
  
          return MemoryStreamSerializer(e);
      }
  </code></pre>