Logo Xantham

SpecialRender Module

Functions and values

Function or value Description

renderErasedUnion caseCount

Full Usage: renderErasedUnion caseCount

Parameters:
    caseCount : int

Returns: WidgetBuilder<TypeDefn>
caseCount : int
Returns: WidgetBuilder<TypeDefn>

renderTypeKeyOfSRTP srtpMember

Full Usage: renderTypeKeyOfSRTP srtpMember

Parameters:
    srtpMember : Name -

Returns: WidgetBuilder<TypeDefn>

Renders a type definition for a SRTP bound typekeyof accessor. Given a member name like ofValue, the following type definition will be rendered:

 [<Erase>]
 type OfValueAccessor =
     static member inline create<^T, ^ReturnType when ^T:(member ofValue: ^ReturnType)>(?object: ^T): typekeyof<^T, ^ReturnType> = unbox "ofValue"
     static member inline access<^T, ^ReturnType when ^T:(member ofValue: ^ReturnType)>(object: ^T): ^ReturnType = object.ofValue
'T
'ReturnType
val object: 'T option (requires member ofValue)
val unbox: value: objnull -> 'T
val object: 'T (requires member ofValue)
'T: (member ofValue: 'ReturnType)

Now we can observe usage. If we were to create an untyped ofValue typekeyof by using the unit method call, then the result type will be typekeyof<obj, obj>

Subsequent usage would instantly resolve the type to the object it is used on, but this would invalidate it for usage on other types with the same property.

 type TestObject = {
     ofValue: int
 }
 type TestObject2 = {
     ofValue: string
 }
 let testObject = { TestObject.ofValue = 1 }
 let testObject2 = { TestObject2.ofValue = "1" }

 let ofValueAccessor = OfValueAccessor.create()
 
 // the line below will resolve ofValueAccessor to typekeyof<TestObject, int>
 TypeKeyOf.access ofValueAccessor testObject
 
 // The line before can no longer be used on testObject2, as it is of a different type
 // TypeKeyOf.access ofValueAccessor testObject2
type TestObject = { ofValue: int }
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

--------------------
type int = int32

--------------------
type int<'Measure> = int
type TestObject2 = { ofValue: string }
Multiple items
val string: value: 'T -> string

--------------------
type string = System.String
val testObject: TestObject
val testObject2: TestObject2
val ofValueAccessor: obj

We can also alternatively use the SRTP static method to access the value directly, without restricting the method to a single object type.

 // Both are valid and are resolved by the compiler correctly
 OfValueAccessor.access testObject // int
 OfValueAccessor.access testObject2 // string

srtpMember : Name

Returns: WidgetBuilder<TypeDefn>

Type something to start searching.