Note that there are some explanatory texts on larger screens.

plurals
  1. POCLS-compliant alternative for ulong property
    text
    copied!<h3>Background</h3> <p>I am writing a managed x64 assembler (which is also a library), so it has multiple classes which define an unsigned 64-bit integer property for use as addresses and offsets. Some are file offsets, others are absolute addresses (relative to the main memory) and again others are relative virtual addresses.</p> <h3>Problem</h3> <p>I use the <code>ulong</code> datatype for the properties in the mentioned scenarios, and this works fine. However, such properties are not CLS-compliant. I can mark them as <code>[ClsCompliant(false)]</code>, but then I need to provide a CLS-compliant alternative to users of the library.</p> <h3>Options and questions</h3> <p>Some <a href="https://stackoverflow.com/questions/5514855/pattern-for-naming-cls-compatible-alternative-properties">suggest</a> providing an alternative property with a bigger data type, but this is not an option because there is no bigger signed integer primitive which could hold all values from <code>0</code> to <code>UInt64.MaxValue</code>.</p> <p>I would rather not mark my entire assembly as non-CLS-compliant, because in most usage scenario's, not all the possible values up to <code>UInt64.MaxValue</code> are used. So, for e.g. <code>Address</code> I could provide an alternative <code>long</code> property <code>AddressAlternative</code>, which only accepts positive values. However, what should happen when <code>Address</code> somehow contains a value above <code>Int64.MaxValue</code>. Should <code>AddressAlternative</code> throw some exception?</p> <p>And what would be an appropriate name for <code>AddressAlternative</code>?</p> <p>Providing an alternative for every usage of <code>ulong</code> would result in many 'double' properties. Is there a better way to do this? Note that not all usages of <code>ulong</code> properties have the same semantics, so a single <code>struct</code> would not cut it.</p> <p>And finally, I have the same CLS compliance problem in constructor parameters. So should I provide an alternative overload accepting <code>long</code> for such a parameter?</p> <p>I do not mind restricting the use of (some functionality) of the library when it is used from a CLS-only context, as long as it can be used in most scenarios.</p>
 

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