Note that there are some explanatory texts on larger screens.

plurals
  1. PONot sure if this is a recognized design pattern, need to improve it
    primarykey
    data
    text
    <p>I have a base class which looks like this:</p> <pre><code>public abstract class MetadataBase : NgageControl, INamingContainer, IValidator { public abstract Type DataType { get; } public string SerializedData { get; set; } .... } </code></pre> <p>I then have a generic class which extends the one above:</p> <pre><code>public abstract class MetadataBase&lt;Tdata, Traw, Tsettings&gt; : MetadataBase where Tdata : new() where Tsettings : new() where Traw : INgageData { .... } </code></pre> <p>I then have a set of classes based upon this one like this:</p> <pre><code>public class MetadataDateTime : MetadataBase&lt;MetadataDateTimeData, NgageDateTime, MetadataDateTimeSettings&gt; { public override Type DataType { get {return typeof(MetadataDateTimeData); } } .... } </code></pre> <p>The reason for this approach is so that I can do things like this:</p> <pre><code>MetadataBase test = GetMetaData(); XmlSerializer xs = new XmlSerializer(test.DataType); xs.Deserialize(); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(test.SerializedData)); _xs.Deserialize(ms); ms.Dispose(); </code></pre> <p>I could have gotten the MetadataDateTimeData type from the Type.GetGenericArguments method but I didn't want to start using reflection due to its slow performance, I'm not sure that I'm right but it seems that getting the type from an overridden property would be much faster.</p> <p>This all works fine but it now seems that I may have to support getting the type statically. Currently I'm creating an instance of this class simply to get its Type in order to deserialize some data, this approach is going to really hurt performance so I was thinking of using attributes to specify the data class. The issue with this though is that you need to use reflection to read an attribute so I may as well just use the GetGenericArguments method.</p> <p>What would you recommend doing?</p> <p>Thanks,</p> <p>Joe</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload