Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions snippets/fsharp/System/RuntimeTypeHandle/Overview/fs.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="type_gettypehandle.fs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// <Snippet1>
open System

type MyClass1() =
let x = 0
member _.MyMethod() =
x

let myClass1 = MyClass1()

// Get the RuntimeTypeHandle from an object.
let myRTHFromObject = Type.GetTypeHandle myClass1
// Get the RuntimeTypeHandle from a type.
let myRTHFromType = typeof<MyClass1>.TypeHandle

printfn $"\nmyRTHFromObject.Value: {myRTHFromObject.Value}"
printfn $"myRTHFromObject.GetType(): {myRTHFromObject.GetType()}"
printfn "Get the type back from the handle..."
printfn $"Type.GetTypeFromHandle(myRTHFromObject): {Type.GetTypeFromHandle myRTHFromObject}"

printfn $"\nmyRTHFromObject.Equals(myRTHFromType): {myRTHFromObject.Equals myRTHFromType}"

printfn $"\nmyRTHFromType.Value: {myRTHFromType.Value}"
printfn $"myRTHFromType.GetType(): {myRTHFromType.GetType()}"
printfn "Get the type back from the handle..."
printfn $"Type.GetTypeFromHandle(myRTHFromType): {Type.GetTypeFromHandle myRTHFromType}"

// This code example produces output similar to the following:
// myRTHFromObject.Value: 799464
// myRTHFromObject.GetType(): System.RuntimeTypeHandle
// Get the type back from the handle...
// Type.GetTypeFromHandle(myRTHFromObject): MyClass1
//
// myRTHFromObject.Equals(myRTHFromType): True
//
// myRTHFromType.Value: 799464
// myRTHFromType.GetType(): System.RuntimeTypeHandle
// Get the type back from the handle...
// Type.GetTypeFromHandle(myRTHFromType): MyClass1
// </Snippet1>
1 change: 1 addition & 0 deletions xml/System/RuntimeTypeHandle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@

:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetTypeHandle/CPP/Type_GetTypeHandle.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/RuntimeTypeHandle/Overview/type_gettypehandle.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System/RuntimeTypeHandle/Overview/type_gettypehandle.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetTypeHandle/VB/type_gettypehandle.vb" id="Snippet1":::

]]></format>
Expand Down