From 66ddf28633807df951e850987aa8fd4f29e71f81 Mon Sep 17 00:00:00 2001 From: albert-du <52804499+albert-du@users.noreply.github.com> Date: Sun, 13 Mar 2022 10:06:56 -0700 Subject: [PATCH] RuntimeTypeHandle F# snippet --- .../RuntimeTypeHandle/Overview/fs.fsproj | 10 +++++ .../Overview/type_gettypehandle.fs | 40 +++++++++++++++++++ xml/System/RuntimeTypeHandle.xml | 1 + 3 files changed, 51 insertions(+) create mode 100644 snippets/fsharp/System/RuntimeTypeHandle/Overview/fs.fsproj create mode 100644 snippets/fsharp/System/RuntimeTypeHandle/Overview/type_gettypehandle.fs diff --git a/snippets/fsharp/System/RuntimeTypeHandle/Overview/fs.fsproj b/snippets/fsharp/System/RuntimeTypeHandle/Overview/fs.fsproj new file mode 100644 index 00000000000..63c3cc08d29 --- /dev/null +++ b/snippets/fsharp/System/RuntimeTypeHandle/Overview/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/RuntimeTypeHandle/Overview/type_gettypehandle.fs b/snippets/fsharp/System/RuntimeTypeHandle/Overview/type_gettypehandle.fs new file mode 100644 index 00000000000..80e9900540b --- /dev/null +++ b/snippets/fsharp/System/RuntimeTypeHandle/Overview/type_gettypehandle.fs @@ -0,0 +1,40 @@ +// +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.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 +// \ No newline at end of file diff --git a/xml/System/RuntimeTypeHandle.xml b/xml/System/RuntimeTypeHandle.xml index 943ad3a71fb..75eea587eec 100644 --- a/xml/System/RuntimeTypeHandle.xml +++ b/xml/System/RuntimeTypeHandle.xml @@ -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"::: ]]>