File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed 
snippets/fsharp/System/RuntimeTypeHandle/Overview Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ <Project  Sdk =" Microsoft.NET.Sdk"  >
2+   <PropertyGroup >
3+     <OutputType >Exe</OutputType >
4+     <TargetFramework >net6.0</TargetFramework >
5+   </PropertyGroup >
6+ 
7+   <ItemGroup >
8+     <Compile  Include =" type_gettypehandle.fs"   />
9+   </ItemGroup >
10+ </Project >
Original file line number Diff line number Diff line change 1+ // <Snippet1> 
2+ open  System 
3+ 
4+ type  MyClass1 ()  = 
5+     let  x  =  0 
6+     member  _.MyMethod ()  = 
7+         x
8+ 
9+ let  myClass1  =  MyClass1() 
10+ 
11+ // Get the RuntimeTypeHandle from an object. 
12+ let  myRTHFromObject  =  Type.GetTypeHandle myClass1
13+ // Get the RuntimeTypeHandle from a type. 
14+ let  myRTHFromType  =  typeof< MyClass1>. TypeHandle
15+ 
16+ printfn $" \n myRTHFromObject.Value:  {myRTHFromObject.Value}" 
17+ printfn $" myRTHFromObject.GetType():  {myRTHFromObject.GetType()}" 
18+ printfn " Get the type back from the handle..." 
19+ printfn $" Type.GetTypeFromHandle(myRTHFromObject):  {Type.GetTypeFromHandle myRTHFromObject}" 
20+ 
21+ printfn $" \n myRTHFromObject.Equals(myRTHFromType):  {myRTHFromObject.Equals myRTHFromType}" 
22+ 
23+ printfn $" \n myRTHFromType.Value:  {myRTHFromType.Value}" 
24+ printfn $" myRTHFromType.GetType():  {myRTHFromType.GetType()}" 
25+ printfn " Get the type back from the handle..." 
26+ printfn $" Type.GetTypeFromHandle(myRTHFromType):  {Type.GetTypeFromHandle myRTHFromType}" 
27+ 
28+ // This code example produces output similar to the following: 
29+ //     myRTHFromObject.Value:  799464 
30+ //     myRTHFromObject.GetType():  System.RuntimeTypeHandle 
31+ //     Get the type back from the handle... 
32+ //     Type.GetTypeFromHandle(myRTHFromObject):  MyClass1 
33+ //     
34+ //     myRTHFromObject.Equals(myRTHFromType):  True 
35+ //     
36+ //     myRTHFromType.Value:  799464 
37+ //     myRTHFromType.GetType():  System.RuntimeTypeHandle 
38+ //     Get the type back from the handle... 
39+ //     Type.GetTypeFromHandle(myRTHFromType):  MyClass1 
40+ // </Snippet1> 
Original file line number Diff line number Diff line change 7777   
7878 :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetTypeHandle/CPP/Type_GetTypeHandle.cpp" id="Snippet1"::: 
7979 :::code language="csharp" source="~/snippets/csharp/System/RuntimeTypeHandle/Overview/type_gettypehandle.cs" id="Snippet1"::: 
80+  :::code language="fsharp" source="~/snippets/fsharp/System/RuntimeTypeHandle/Overview/type_gettypehandle.fs" id="Snippet1"::: 
8081 :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetTypeHandle/VB/type_gettypehandle.vb" id="Snippet1":::   
8182   
8283 ]]>  </format >
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments