How to add metadata to the System.Type?

前端 未结 1 1317
旧巷少年郎
旧巷少年郎 2021-01-23 09:56

I\'ve been working on a language, but in terms of .NET integration I\'ve only managed to get primitive types working so far. Last night I had a good idea - instead of trying to

相关标签:
1条回答
  • 2021-01-23 10:45

    A standard way of augmenting type information with extra data in .NET would be to use attributes, though attribute constructor arguments would normally be limited to values you can represent as literals. This may or might not be an issue for you, depending on how rich you would your metadata to be. DU's probably won't work.

    Otherwise, a straightforward solution would be to wrap your value together with arbitrary metadata into a generic type, i.e.

    type TypeWithMetadata<'typ, 'metadata>(value: 'typ, metadata: 'metadata) = 
        member this.Value = value
        member this.Metadata = metadata
    

    though that might come with an overhead you'd want to avoid?

    0 讨论(0)
提交回复
热议问题