Detecting F # Record Type from C # at Runtime

Is there a way to check if an object is an F # record type at runtime in C # without reference to the FSharp.Core library?

+4
source share
1 answer

Record types will be marked with an attribute [<CompilationMapping(SourceConstructFlags.RecordType)>]during compilation. This is what it is looking for FSharpType.IsRecord, you can see the implementation here . Discriminatory unions are marked in the same way.

You can override this logic without referring to any types FSharp.Coreexplicitly, i.e. you can search for an attribute by name and have your own copy of the enumeration SourceConstructFlagsto match attribute data.

+6
source

Source: https://habr.com/ru/post/1687032/


All Articles