Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Could you just check to see if your command variable is of the type? If when this command object was instantiated, it inherited from it, it will return true.</p> <pre><code>if(command is IUpdateAggregateCommand&lt;TAggregate&gt;) </code></pre> <p>Then you'll just:</p> <pre><code>var newCommand = ((IUpdateAggregateCommand&lt;TAggregate&gt;)command); </code></pre> <p>or</p> <pre><code>var newCommand = command as IUpdateAggregateCommand&lt;TAggregate&gt;; </code></pre> <hr> <p>With your update that you don't know what to cast it to, you could continue using Reflection which is slow, or do <code>If, Else If</code> checks which is fast, readable and you're going to need to use some special property/functionality anyways that is unique to this type. If you're looking for a <strong><em>common property</em></strong>, then you need to make a more generic Interface that they all inherit from, at which point you don't need If/Else If anyways.</p> <hr> <p>Second edit: Are you looking for a concept like the below? This allows me to get an item from a list based on its type, as well as to return it based on its generic type.</p> <pre><code> List&lt;IMockEvent&gt; events = new List&lt;IMockEvent&gt;(); public IMockEvent&lt;K&gt; GetMockEvent&lt;T, K&gt;() { return events.First(t =&gt; t is T) as IMockEvent&lt;K&gt;; } public void Add(IMockEvent evt) { events.Add(new MockStatusUpdate()); } </code></pre> <p>where classes are defined as</p> <pre><code>public class EMockStatusUpdated : StatusUpdated, IMockEvent&lt;string&gt; { } public interface IMockEvent&lt;T&gt; : IMockEvent { } public interface IMockEvent { } </code></pre>
 

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