Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two interpretations of your question; one would be trivial, one impossible, so I'll go forward and cover both.</p> <ol> <li><p>You want to return an instance of a type which implements both <a href="http://msdn.microsoft.com/en-us/library/system.type.aspx" rel="nofollow noreferrer"><code>System.Type</code></a> and <code>TInterface</code>.</p> <p>This is trivial: Just use <code>where TType : Type</code> and <code>where TType : TInterface</code>.</p></li> <li><p>You want to return an instance of <a href="http://msdn.microsoft.com/en-us/library/system.type.aspx" rel="nofollow noreferrer"><code>System.Type</code></a> that represents a type which inherits from <code>TInterface</code>.</p> <p>This is impossible to specify in the .NET (and C#) type-system.</p> <p>The type system can only resolve information from the type hierarchy themselves, but not enforce "contracts" like restricted run-time property values. There are a few hacks regarding default-constructors etc., but as far as I know not even testing for existing methods is possible (unlike C++ templates, for instance, not to speak of Qi et al.).</p></li> </ol> <p><em>Update</em></p> <p>Please check the comment from <a href="https://stackoverflow.com/users/1301879/michael-graczyk">Michael Graczyk</a>.</p> <p>Also: I just found out that there are code-contract checkers (static and run-time) for .NET: <a href="http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx" rel="nofollow noreferrer">Microsoft DevLabs Code-Contracts for .NET</a>. I have never used them, not even new about them, but that looks interesting!</p> <p>However, even without looking, I'm quite sure that overload-resolution etc. will not be able to use such information.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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