Check if two variables are of the same when the type is dynamic and both variables are the derivatives of same base class
<p>Is it possible to check if the list contains an object of given (but dynamic) type, derrived from same basic abstract class?</p>

<p>The main problem is not about the list, but about comparing types itself. 
In single variables and static variables, it's easy: </p>

<pre><code>if(someVariable is int)
</code></pre>

<p>Checking the list with static type is also easy, like:</p>

<pre><code>SomeList.OfType&lt;int&gt;().Any()
</code></pre>

<p>or</p>

<pre><code>(from _Object in SomeList.OfType&lt;int&gt; where _Object is int select _Object).Count() == 0
</code></pre>

<p>but I cant't handle it if the type I want to check is dynamic, f.e. passed as method parameter:</p>

<pre><code>abstract class BasicClass;
class DerivativeOne : BasicClass { }
class DerivativeTwo : BasicClass { }

// in main:

List&lt;BasicClass&gt; _List = new List&lt;BasicClass&gt;();
DerivativeOne a = new DerivativeOne();
DerivativeTwo b = new DerivativeTwo();
DerivativeOne c = new DerivativeOne();

if(!CheckIfTypeExistsInList(a, _List)
{
    _List.Add(a);
}
if(!CheckIfTypeExistsInList(b, _List)
{
    _List.Add(b);
}
if(!CheckIfTypeExistsInList(c, _List)
{
    _List.Add(c);  // this is what I don't want to happen,
           // because I already have one object of type DerivativeOne in my list.
}


// the function:
bool CheckIfTypeExistsInList(BasicClass pObject, List&lt;BasicClass&gt; pList)
{
    /// few attempts:
    pList.OfType&lt;(pObject.GetType()&gt;().Any();  // attempt one, error
    return  (from _Object in SomeList.OfType&lt;(pObject.GetType())&gt; where _Object is int select _Object).Count() == 0;    // attempt two, error
}
</code></pre>

<p>PS. I am aware that the code doesn't look neat, but I tried to show just the problem itself, skipping extra logic and stuff.</p>

<p>PS2. I am aware that the solution to the problem would be just to put some attribute to BasicClass and make each derivative to have unique value of the attribute, but still - I'm not looking for another route to solve the problem, I'm just interested if it's possible to do it "this" way.</p>
