Note that there are some explanatory texts on larger screens.

plurals
  1. POMake type's instances non-storable
    primarykey
    data
    text
    <ul> <li>Is there a way to mark a type (or even better, an interface) so that no instances of it can be stored in a field (in a similar way to <code>TypedReference</code> and <code>ArgIterator</code>)?</li> <li>In the same way, is there a way to prevent instances from being passed through anonymous methods and -- In general -- To mimic the behavior of the two types above?</li> <li>Can this be done through ILDasm or more generally through IL editing? Since <a href="http://code.google.com/p/unconstrained-melody/" rel="nofollow noreferrer">UnconstrainedMelody</a> achieves normally unobtainable results through binary editing of a compiled assembly, maybe there's a way to "mark" certain types (or even better, abstract ones or marker interfaces) through the same approach.</li> </ul> <p>I doubt it’s hardcoded in the compiler because the <a href="http://msdn.microsoft.com/en-us/library/t93xez96(v=vs.80).aspx" rel="nofollow noreferrer">documentation for the error CS0610</a> states:</p> <blockquote> <p>There are some types that cannot be used as fields or properties. These types include...</p> </blockquote> <p>Which in my opinion hints that the set of types like those can be extended -- But I could be wrong.</p> <p>I've searched a bit on SO and while I understand that <a href="https://stackoverflow.com/questions/6266031/c-sharp-net-how-to-throw-a-compiler-error">throwing a compiler error</a> programmatically can't be done, I could find no source stating that certain "special" types' behaviors couldn't be replicated.</p> <p>Even if the question is mostly academic, there could be some usages for an answer. For example, it could be useful sometimes to be sure that a certain object's lifetime is constrained to the method block which creates it.</p> <p><strong>EDIT:</strong> <code>RuntimeArgumentHandle</code> is one more (unmentioned) non-storable type.</p> <p><strong>EDIT 2:</strong> If it can be of any use, it seems that the CLR treats those types in a different way as well, if not only the compiler (still assuming that the types are in no way different from others). The following program, for example, will throw a <code>TypeLoadException</code> regarding <code>TypedReference*</code>. I've adapted it to make it shorter but you can work around it all you want. Changing the pointer's type to, say, <code>void*</code> will not throw the exception.</p> <pre><code>using System; unsafe static class Program { static TypedReference* _tr; static void Main(string[] args) { _tr = (TypedReference*) IntPtr.Zero; } } </code></pre>
    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.
 

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