Skip to content

Conditional compilation symbols

Gert Driesen edited this page May 3, 2020 · 45 revisions

In our codebase, we use the following conditional compilation symbols to identity features supported by a given target framework:

Symbol Description
FEATURE_ENCODING_ASCII Encoding.ASCII is available
FEATURE_BINARY_SERIALIZATION Binary serialization is supported.
FEATURE_DIAGNOSTICS_TRACESOURCE TraceSource is available
FEATURE_DIRECTORYINFO_ENUMERATEFILES DirectoryInfo.EnumerationFiles(string) is available
FEATURE_DYNAMIC_TYPE Dynamic type is supported
FEATURE_RNG_CSP RandomNumberGenerator can be created using default ctor of RNGCryptoServiceProvider
FEATURE_RNG_CREATE RandomNumberGenerator can be created using static Create method on RandomNumberGenerator
FEATURE_HASHALGORITHM_DISPOSE HashAlgortihm.Dispose() is available
FEATURE_HASH_MD5
FEATURE_HASH_SHA1_CREATE
FEATURE_HASH_SHA1_MANAGED
FEATURE_HASH_SHA256_CREATE
FEATURE_HASH_SHA256_MANAGED
FEATURE_HASH_SHA384_CREATE
FEATURE_HASH_SHA384_MANAGED
FEATURE_HASH_SHA512_CREATE
FEATURE_HASH_SHA512_MANAGED
FEATURE_HASH_RIPEMD160_CREATE
FEATURE_HASH_RIPEMD160_MANAGED
FEATURE_HMAC_MD5
FEATURE_HMAC_SHA1
FEATURE_HMAC_SHA256
FEATURE_HMAC_SHA384
FEATURE_HMAC_SHA512
FEATURE_HMAC_RIPEMD160
FEATURE_THREAD_COUNTDOWNEVENT
FEATURE_THREAD_SLEEP Current thread can be suspended using static Sleep method on Thread class
FEATURE_THREAD_TAP Task-based Asynchronous Pattern is supported
FEATURE_THREAD_THREADPOOL ThreadPool is supported
FEATURE_WAITHANDLE_DISPOSE WaitHandle.Dispose() is available
FEATURE_MEMORYSTREAM_GETBUFFER MemoryStream features a GetBuffer() method which allows access to the byte array from which this stream was created, or the underlying array
FEATURE_MEMORYSTREAM_TRYGETBUFFER MemoryStream features a TryGetBuffer(out ArraySegment) method which allows access to the byte array from which this stream was created, or the underlying array
FEATURE_STREAM_TAP Stream supports Task-based Asynchronous Pattern (TAP)
FEATURE_STREAM_APM Stream supports Asynchronous Programming Model (APM)
FEATURE_SOCKET_TAP Socket supports Task-based Asynchronous Pattern (TAP)
FEATURE_SOCKET_EAP Socket supports Event-based Asynchronous Pattern (EAP)
FEATURE_SOCKET_APM Socket supports Asynchronous Programming Model (APM)
FEATURE_SOCKET_SYNC Socket supports synchronous execution
FEATURE_SOCKET_POLL Socket features a Poll(Int32,SelectMode) method
FEATURE_SOCKET_SELECT Socket features a Select(IList,IList,IList,Int32) method that is reliable
FEATURE_SOCKET_DISPOSE Socket.Dispose() is available
FEATURE_DNS_TAP Dns supports Task-based Asynchronous Pattern (TAP)
FEATURE_DNS_APM Dns supports Asynchronous Programming Model (APM)
FEATURE_DNS_SYNC Dns supports synchronous execution
FEATURE_REFLECTION_TYPEINFO Type.GetTypeInfo() extension method is required to get a full reflection object from a given 'Type'
FEATURE_STRINGBUILDER_CLEAR StringBuilder.Clear() is available

Below you find a detailed overview on the target frameworks for which these conditional compilation symbols are defined.

Crypto

Symbol net35 net40 netstandard1.3 netstandard2.0 sl4 sl5 uap10 wp8 wp71
FEATURE_RNG_CSP o o o o x x o x x
FEATURE_RNG_CREATE x x x x o o o o o
FEATURE_HASHALGORITHM_DISPOSE o x x x o o x o o
FEATURE_HASH_MD5 x x x x o o o o o
FEATURE_HASH_SHA1_CREATE x x x x o o o o o
FEATURE_HASH_SHA1_MANAGED o o o o x x o x x
FEATURE_HASH_SHA256_CREATE x x x x o o o o o
FEATURE_HASH_SHA256_MANAGED o o o o x x o x x
FEATURE_HASH_SHA384_CREATE x x x x o o o o o
FEATURE_HASH_SHA384_MANAGED o o o o o o o o o
FEATURE_HASH_SHA512_CREATE x x x x o o o o o
FEATURE_HASH_SHA512_MANAGED o o o o o o o o o
FEATURE_HASH_RIPEMD160_CREATE x x o o o o o o o
FEATURE_HASH_RIPEMD160_MANAGED o o o o o o o o o
FEATURE_HMAC_MD5 x x x x o o o o o
FEATURE_HMAC_SHA1 x x x x x x o x x
FEATURE_HMAC_SHA256 x x x x x x o x x
FEATURE_HMAC_SHA384 x x x x o o o o o
FEATURE_HMAC_SHA512 x x x x o o o o o
FEATURE_HMAC_RIPEMD160 x x o o o o o o o

Threading

Symbol net35 net40 netstandard1.3 netstandard2.0 sl4 sl5 uap10 wp8 wp71
FEATURE_THREAD_COUNTDOWNEVENT o x x x o o x x o
FEATURE_THREAD_SLEEP x x x x x x o x x
FEATURE_THREAD_TAP o o o x o o x o o
FEATURE_THREAD_THREADPOOL x x x x x x o x x
FEATURE_WAITHANDLE_DISPOSE o x x x x x x x x

IO

Symbol net35 net40 netstandard1.3 netstandard2.0 sl4 sl5 uap10 wp8 wp71
FEATURE_DIRECTORYINFO_ENUMERATEFILES o x x x x x x o o
FEATURE_MEMORYSTREAM_GETBUFFER x x o x x x o x x
FEATURE_MEMORYSTREAM_TRYGETBUFFER o o x x o o x o o
FEATURE_STREAM_TAP o o x x o o x x o
FEATURE_STREAM_APM x x o x x x o x x

Remarks:

  • The following symbols are treated as mutually exclusive in the listed order:

    • FEATURE_MEMORYSTREAM_GETBUFFER
    • FEATURE_MEMORYSTREAM_TRYGETBUFFER

    When, for example, both FEATURE_MEMORYSTREAM_GETBUFFER and FEATURE_MEMORYSTREAM_TRYGETBUFFER are defined for a given target framework, then FEATURE_MEMORYSTREAM_GETBUFFER will take precedence.

  • The following symbols are treated as mutually exclusive in the listed order:

    • FEATURE_STREAM_TAP
    • FEATURE_STREAM_APM

    When, for example, both FEATURE_STREAM_TAP and FEATURE_STREAM_APM are defined for a given target framework, then FEATURE_STREAM_TAP will take precedence.

Name resolution

Symbol net35 net40 netstandard1.3 netstandard2.0 sl4 sl5 uap10 wp8 wp71
FEATURE_DNS_TAP o o x x o o o o o
FEATURE_DNS_APM x x o x o o o o o
FEATURE_DNS_SYNC x x o x o o o o o
FEATURE_DEVICEINFORMATION_APM o o o o o o o x x
FEATURE_DATAGRAMSOCKET o o o o o o x o o

Remarks:

  • Name resolution is not supported on Silverlight 4 and 5.

  • The following symbols are treated as mutually exclusive in the listed order:

    • FEATURE_DNS_SYNC
    • FEATURE_DNS_APM
    • FEATURE_DNS_TAP

    When, for example, both FEATURE_DNS_SYNC and FEATURE_DNS_APM are defined for a given target framework, then FEATURE_DNS_SYNC will take precedence.

Networking

Symbol net35 net40 netstandard1.3 netstandard2.0 sl4 sl5 uap10 wp8 wp71
FEATURE_SOCKET_TAP o o x x o o o o o
FEATURE_SOCKET_EAP x x x x x x x x x
FEATURE_SOCKET_APM x x o x o o o o o
FEATURE_SOCKET_SYNC x x x x o o o o o
FEATURE_SOCKET_POLL x x x x o o o o o
FEATURE_SOCKET_SELECT o x x x o o o o o
FEATURE_SOCKET_DISPOSE o x x x x x x x x

Remarks:

  • FEATURE_SOCKET_POLL is preferred over FEATURE_SOCKET_SELECT due to issues in:

  • The following symbols are treated as mutually exclusive in the listed order:

    • FEATURE_SOCKET_SYNC
    • FEATURE_SOCKET_EAP
    • FEATURE_SOCKET_APM
    • FEATURE_SOCKET_TAP

    When, for example, both FEATURE_SOCKET_SYNC and FEATURE_SOCKET_EAP are defined for a given target framework, then FEATURE_SOCKET_SYNC will take precedence.

Other

Symbol net35 net40 netstandard1.3 netstandard2.0 sl4 sl5 uap10 wp8 wp71
FEATURE_ENCODING_ASCII x x x x o o x o o
FEATURE_REGEX_COMPILE x x x x o o x x x
FEATURE_BINARY_SERIALIZATION x x o o o o o o o
FEATURE_DIAGNOSTICS_TRACESOURCE x x x x o o o o o
FEATURE_REFLECTION_TYPEINFO o o x o o o x o o
FEATURE_STRINGBUILDER_CLEAR o x x x o o x o o