I wrote this function that is suppose to returnt rue if an array of
types(actually stuff returned by GetInterfaces) implements the interface Q.
private bool ContainsInterfa ce<A, Q>(A[] list)
{
foreach (A a in list)
if (a is Q)
return true;
return false;
}
and is used like
ContainsInterfa ce<Type, IEnumerable>(fi eld.FieldType.G etInterfaces()) )
So it checks the list for elements that implement IEnumerable.
I used this successfully in a "ContainsTy pe"
ContainsType<At tribute, RawExcludeAttri bute>(attribute s)
Where its the same code. The above essentially just checks if any of the
attribute's in attributes is a RawExcludeAttri bute. It works fine. My logic
was the same for interfaces but it doesn't work. (Maybe interfaces cannot
implement themselfs as "a is Q" is always false... yet when I debug I get
exactly these type for a and typeof(Q).
Even something like
foreach (A a in list)
{
Type t = typeof(Q);
if (a.GetType() == typeof(Q))
return true;
}
does not work.
In this case
t = + t {Name = "IEnumerabl e" FullName = "System.Collect ions.IEnumerabl e"}
System.Type {System.Runtime Type}
a = + a {Name = "IEnumerabl e" FullName = "System.Collect ions.IEnumerabl e"}
System.Type {System.Runtime Type}
So I don't see why they are not the same types ;/
Thanks,
Jon
types(actually stuff returned by GetInterfaces) implements the interface Q.
private bool ContainsInterfa ce<A, Q>(A[] list)
{
foreach (A a in list)
if (a is Q)
return true;
return false;
}
and is used like
ContainsInterfa ce<Type, IEnumerable>(fi eld.FieldType.G etInterfaces()) )
So it checks the list for elements that implement IEnumerable.
I used this successfully in a "ContainsTy pe"
ContainsType<At tribute, RawExcludeAttri bute>(attribute s)
Where its the same code. The above essentially just checks if any of the
attribute's in attributes is a RawExcludeAttri bute. It works fine. My logic
was the same for interfaces but it doesn't work. (Maybe interfaces cannot
implement themselfs as "a is Q" is always false... yet when I debug I get
exactly these type for a and typeof(Q).
Even something like
foreach (A a in list)
{
Type t = typeof(Q);
if (a.GetType() == typeof(Q))
return true;
}
does not work.
In this case
t = + t {Name = "IEnumerabl e" FullName = "System.Collect ions.IEnumerabl e"}
System.Type {System.Runtime Type}
a = + a {Name = "IEnumerabl e" FullName = "System.Collect ions.IEnumerabl e"}
System.Type {System.Runtime Type}
So I don't see why they are not the same types ;/
Thanks,
Jon
Comment