简体   繁体   中英

Detecting F# record type from C# at runtime

有没有办法在C#中检查对象是否是运行时的F#记录类型而不引用FSharp.Core库?

Record types get marked with [<CompilationMapping(SourceConstructFlags.RecordType)>] attribute at compilation. This is what FSharpType.IsRecord looks for, you can see the implementation here . Discriminated unions get marked in a similar way.

It's possible to reimplement that logic without referring to any FSharp.Core types explicitly, ie you could look up the attribute by name and have your own copy of SourceConstructFlags enum for matching attribute data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM