From ec63f9378289d9b9c886f19ce5b1c83e25bf04b6 Mon Sep 17 00:00:00 2001 From: albert-du <52804499+albert-du@users.noreply.github.com> Date: Wed, 20 Apr 2022 17:15:40 -0700 Subject: [PATCH 1/2] Type F# snippets --- .../fsharp/System/Type/Assembly/fs.fsproj | 10 ++ .../System/Type/Assembly/type_assembly.fs | 16 ++ .../Type/AssemblyQualifiedName/fs.fsproj | 10 ++ .../Type/AssemblyQualifiedName/fullname1.fs | 79 +++++++++ .../fsharp/System/Type/BaseType/basetype3.fs | 37 +++++ .../fsharp/System/Type/BaseType/fs.fsproj | 12 ++ .../fsharp/System/Type/BaseType/remarks.fs | 6 + .../System/Type/BaseType/testbasetype.fs | 6 + .../Type/ContainsGenericParameters/fs.fsproj | 10 ++ .../Type/ContainsGenericParameters/source.fs | 74 +++++++++ .../System/Type/DeclaringMethod/fs.fsproj | 10 ++ .../System/Type/DeclaringMethod/source.fs | 103 ++++++++++++ .../System/Type/DeclaringType/fs.fsproj | 11 ++ .../System/Type/DeclaringType/remarks.fs | 5 + .../System/Type/DeclaringType/source.fs | 17 ++ .../System/Type/DefaultBinder/fs.fsproj | 10 ++ .../Type/DefaultBinder/type_defaultbinder.fs | 19 +++ .../fsharp/System/Type/EmptyTypes/fs.fsproj | 10 ++ .../fsharp/System/Type/EmptyTypes/source.fs | 9 ++ .../fsharp/System/Type/Equals/EqualsEx1.fs | 43 +++++ snippets/fsharp/System/Type/Equals/fs.fsproj | 11 ++ snippets/fsharp/System/Type/Equals/source.fs | 38 +++++ .../System/Type/FilterAttribute/fs.fsproj | 10 ++ .../FilterAttribute/type_filterattribute.fs | 20 +++ .../fsharp/System/Type/FilterName/fs.fsproj | 10 ++ .../fsharp/System/Type/FilterName/source.fs | 13 ++ .../Type/FilterNameIgnoreCase/fs.fsproj | 10 ++ .../type_filternameignorecase.fs | 22 +++ .../System/Type/FindInterfaces/fs.fsproj | 10 ++ .../FindInterfaces/type_findinterfaces.fs | 35 ++++ .../fsharp/System/Type/FindMembers/fs.fsproj | 10 ++ .../Type/FindMembers/type_findmembers.fs | 24 +++ .../fsharp/System/Type/FullName/Fullname3.fs | 20 +++ .../fsharp/System/Type/FullName/Fullname4.fs | 37 +++++ .../fsharp/System/Type/FullName/Fullname5.fs | 40 +++++ .../fsharp/System/Type/FullName/fs.fsproj | 13 ++ .../System/Type/FullName/fullnameex1.fs | 19 +++ .../System/Type/FullName/testfullname.fs | 13 ++ snippets/fsharp/System/Type/GUID/fs.fsproj | 10 ++ snippets/fsharp/System/Type/GUID/type_guid.fs | 11 ++ .../Type/GenericParameterAttributes/fs.fsproj | 10 ++ .../Type/GenericParameterAttributes/source.fs | 90 +++++++++++ .../Type/GenericParameterPosition/fs.fsproj | 10 ++ .../Type/GenericParameterPosition/remarks.fs | 6 + .../fsharp/System/Type/GetArrayRank/fs.fsproj | 10 ++ .../Type/GetArrayRank/type_getarrayrank.fs | 34 ++++ .../System/Type/GetConstructor/fs.fsproj | 12 ++ .../GetConstructor/type_getconstructor.fs | 20 +++ .../GetConstructor/type_getconstructor2.fs | 28 ++++ .../GetConstructor/type_getconstructor3.fs | 28 ++++ .../System/Type/GetConstructors/fs.fsproj | 11 ++ .../System/Type/GetConstructors/source1.fs | 13 ++ .../System/Type/GetConstructors/source2.fs | 15 ++ .../System/Type/GetDefaultMembers/fs.fsproj | 10 ++ .../type_getdefaultmembers.fs | 27 ++++ .../System/Type/GetElementType/fs.fsproj | 10 ++ .../Type/GetElementType/testgetelementtype.fs | 19 +++ .../fsharp/System/Type/GetEvent/fs.fsproj | 12 ++ .../System/Type/GetEvent/type_getevent.fs | 23 +++ .../System/Type/GetEvent/type_getevent1.fs | 26 +++ .../fsharp/System/Type/GetEvents/fs.fsproj | 12 ++ .../System/Type/GetEvents/type_getevents1.fs | 23 +++ .../System/Type/GetEvents/type_getevents2.fs | 23 +++ .../fsharp/System/Type/GetField/fs.fsproj | 10 ++ .../System/Type/GetField/type_getfield.fs | 26 +++ .../Type/GetFields/fieldinfo_isspecialname.fs | 20 +++ .../fsharp/System/Type/GetFields/fs.fsproj | 11 ++ .../fsharp/System/Type/GetFields/source.fs | 35 ++++ .../System/Type/GetGenericArguments/fs.fsproj | 10 ++ .../System/Type/GetGenericArguments/source.fs | 68 ++++++++ .../Type/GetGenericTypeDefinition/fs.fsproj | 10 ++ .../Type/GetGenericTypeDefinition/source.fs | 47 ++++++ .../fsharp/System/Type/GetHashCode/fs.fsproj | 11 ++ .../GetHashCode/type_gethashcode_getfields.fs | 24 +++ .../fsharp/System/Type/GetInterface/fs.fsproj | 10 ++ .../Type/GetInterface/type_getinterface.fs | 31 ++++ .../System/Type/GetInterfaceMap/fs.fsproj | 10 ++ .../Type/GetInterfaceMap/interfacemapping1.fs | 45 ++++++ .../System/Type/GetInterfaces/fs.fsproj | 10 ++ .../Type/GetInterfaces/type_getinterfaces1.fs | 22 +++ .../fsharp/System/Type/GetMember/fs.fsproj | 10 ++ .../System/Type/GetMember/type_getmember.fs | 71 ++++++++ .../fsharp/System/Type/GetMembers/fs.fsproj | 11 ++ .../Type/GetMembers/type_getmembers1.fs | 27 ++++ .../Type/GetMembers/type_getmembers2.fs | 42 +++++ .../System/Type/GetMethod/GetMethod1.fs | 48 ++++++ .../Type/GetMethod/GetMethodWithOverloads1.fs | 69 ++++++++ .../Type/GetMethod/GetMethodWithOverloads2.fs | 33 ++++ .../fsharp/System/Type/GetMethod/fs.fsproj | 17 ++ .../System/Type/GetMethod/type_getmethod1.fs | 11 ++ .../System/Type/GetMethod/type_getmethod2.fs | 13 ++ .../System/Type/GetMethod/type_getmethod3.fs | 44 +++++ .../System/Type/GetMethod/type_getmethod4.fs | 37 +++++ .../System/Type/GetMethod/type_getmethod5.fs | 45 ++++++ .../System/Type/GetProperties/fs.fsproj | 11 ++ .../Type/GetProperties/type_getproperties2.fs | 86 ++++++++++ .../Type/GetProperties/type_gettypecode.fs | 37 +++++ .../fsharp/System/Type/GetProperty/fs.fsproj | 14 ++ .../Type/GetProperty/type_getproperty1.fs | 24 +++ .../Type/GetProperty/type_getproperty2.fs | 25 +++ .../Type/GetProperty/type_getproperty21.fs | 28 ++++ .../Type/GetProperty/type_getproperty3.fs | 29 ++++ .../GetProperty/type_getproperty_types.fs | 32 ++++ snippets/fsharp/System/Type/GetType/fs.fsproj | 11 ++ snippets/fsharp/System/Type/GetType/source.fs | 37 +++++ .../System/Type/GetType/type_gettype.fs | 23 +++ .../fsharp/System/Type/GetTypeCode/fs.fsproj | 10 ++ .../System/Type/GetTypeCode/iconvertible.fs | 91 +++++++++++ .../System/Type/GetTypeFromCLSID/fs.fsproj | 14 ++ .../GetTypeFromCLSID/gettypefromclsid1.fs | 20 +++ .../GetTypeFromCLSID/gettypefromclsid11.fs | 65 ++++++++ .../GetTypeFromCLSID/gettypefromclsid_ex2.fs | 23 +++ .../GetTypeFromCLSID/gettypefromclsid_ex3.fs | 24 +++ .../GetTypeFromCLSID/gettypefromclsid_ex4.fs | 24 +++ .../System/Type/GetTypeFromHandle/fs.fsproj | 10 ++ .../type_gettypefromhandle.fs | 9 ++ .../System/Type/GetTypeFromProgID/fs.fsproj | 12 ++ .../type_gettypefromprogid2.fs | 22 +++ .../type_gettypefromprogid3.fs | 20 +++ .../type_gettypefromprogid4.fs | 23 +++ .../System/Type/HasElementType/fs.fsproj | 10 ++ .../HasElementType/type_haselementtype.fs | 50 ++++++ .../System/Type/HasElementTypeImpl/fs.fsproj | 10 ++ .../type_haselementtypeimpl.fs | 45 ++++++ .../fsharp/System/Type/InvokeMember/fs.fsproj | 10 ++ .../System/Type/InvokeMember/invokemem.fs | 80 +++++++++ .../fsharp/System/Type/IsAbstract/fs.fsproj | 10 ++ .../System/Type/IsAbstract/isabstract1.fs | 49 ++++++ .../fsharp/System/Type/IsAnsiClass/fs.fsproj | 10 ++ .../Type/IsAnsiClass/type_isansiclass.fs | 18 +++ snippets/fsharp/System/Type/IsArray/fs.fsproj | 10 ++ .../fsharp/System/Type/IsArray/isarray2.fs | 19 +++ .../fsharp/System/Type/IsArrayImpl/fs.fsproj | 10 ++ .../Type/IsArrayImpl/type_isarrayimpl.fs | 39 +++++ .../IsAssignableFrom/IsAssignableFrom2.fs | 11 ++ .../IsAssignableFrom/IsAssignableFrom3.fs | 16 ++ .../System/Type/IsAssignableFrom/fs.fsproj | 13 ++ .../IsAssignableFrom/isassignablefrom_ex1.fs | 25 +++ .../IsAssignableFrom/testisassignablefrom.fs | 82 ++++++++++ .../fsharp/System/Type/IsAutoLayout/fs.fsproj | 10 ++ .../Type/IsAutoLayout/type_isautolayout.fs | 13 ++ snippets/fsharp/System/Type/IsClass/fs.fsproj | 10 ++ .../System/Type/IsClass/type_isclass.fs | 10 ++ .../fsharp/System/Type/IsContextful/fs.fsproj | 10 ++ .../Type/IsContextful/type_iscontextful.fs | 31 ++++ .../System/Type/IsContextfulImpl/fs.fsproj | 10 ++ .../IsContextfulImpl/type_iscontextfulimpl.fs | 42 +++++ snippets/fsharp/System/Type/IsEnum/fs.fsproj | 10 ++ .../fsharp/System/Type/IsEnum/testisenum.fs | 19 +++ .../System/Type/IsExplicitLayout/fs.fsproj | 10 ++ .../IsExplicitLayout/type_isexplicitlayout.fs | 20 +++ .../System/Type/IsGenericParameter/fs.fsproj | 10 ++ .../System/Type/IsGenericParameter/source.fs | 65 ++++++++ .../System/Type/IsGenericType/fs.fsproj | 11 ++ .../System/Type/IsGenericType/remarks.fs | 13 ++ .../System/Type/IsGenericType/source.fs | 83 ++++++++++ .../System/Type/IsInstanceOfType/fs.fsproj | 10 ++ .../IsInstanceOfType/testisinstanceoftype.fs | 28 ++++ .../fsharp/System/Type/IsInterface/fs.fsproj | 10 ++ .../Type/IsInterface/type_isinterface.fs | 23 +++ .../System/Type/IsLayoutSequential/fs.fsproj | 10 ++ .../type_islayoutsequential.fs | 22 +++ .../System/Type/IsMarshalByRefImpl/fs.fsproj | 10 ++ .../type_ismarshalbyrefimpl.fs | 42 +++++ .../fsharp/System/Type/IsNotPublic/fs.fsproj | 10 ++ .../fsharp/System/Type/IsNotPublic/source.fs | 19 +++ .../System/Type/IsPrimitiveImpl/fs.fsproj | 10 ++ .../IsPrimitiveImpl/type_isprimitiveimpl.fs | 34 ++++ .../fsharp/System/Type/IsPublic/fs.fsproj | 10 ++ .../System/Type/IsPublic/type_ispublic.fs | 12 ++ .../fsharp/System/Type/IsSealed/fs.fsproj | 10 ++ .../System/Type/IsSealed/type_issealed.fs | 15 ++ .../System/Type/IsSerializable/fs.fsproj | 10 ++ .../IsSerializable/type_isserializable.fs | 17 ++ .../fsharp/System/Type/IsSubclassOf/fs.fsproj | 11 ++ .../IsSubclassOf/issubclassof_interface1.fs | 16 ++ .../Type/IsSubclassOf/testissubclassof.fs | 11 ++ .../fsharp/System/Type/IsValueType/fs.fsproj | 10 ++ .../Type/IsValueType/type_isvaluetype.fs | 13 ++ .../fsharp/System/Type/IsVisible/fs.fsproj | 10 ++ .../fsharp/System/Type/IsVisible/source.fs | 19 +++ .../System/Type/MakeByRefType/fs.fsproj | 10 ++ .../System/Type/MakeByRefType/source.fs | 62 +++++++ .../System/Type/MakeGenericType/fs.fsproj | 11 ++ .../System/Type/MakeGenericType/remarks.fs | 5 + .../System/Type/MakeGenericType/source.fs | 55 +++++++ .../fsharp/System/Type/MemberType/fs.fsproj | 10 ++ .../fsharp/System/Type/MemberType/source.fs | 8 + snippets/fsharp/System/Type/Missing/fs.fsproj | 14 ++ snippets/fsharp/System/Type/Missing/source.fs | 43 +++++ snippets/fsharp/System/Type/Module/fs.fsproj | 10 ++ .../System/Type/Module/type_tostring.fs | 22 +++ .../fsharp/System/Type/Overview/Equals1.fs | 23 +++ .../fsharp/System/Type/Overview/GetType1.fs | 13 ++ .../fsharp/System/Type/Overview/fs.fsproj | 12 ++ .../fsharp/System/Type/Overview/source.fs | 20 +++ .../System/Type/ReflectedType/fs.fsproj | 10 ++ .../System/Type/ReflectedType/source.fs | 8 + .../Type/StructLayoutAttribute/fs.fsproj | 10 ++ .../Type/StructLayoutAttribute/source.fs | 23 +++ .../fsharp/System/Type/TypeHandle/fs.fsproj | 10 ++ .../System/Type/TypeHandle/type_typehandle.fs | 23 +++ xml/System/Type.xml | 153 +++++++++++++++++- 203 files changed, 4786 insertions(+), 2 deletions(-) create mode 100644 snippets/fsharp/System/Type/Assembly/fs.fsproj create mode 100644 snippets/fsharp/System/Type/Assembly/type_assembly.fs create mode 100644 snippets/fsharp/System/Type/AssemblyQualifiedName/fs.fsproj create mode 100644 snippets/fsharp/System/Type/AssemblyQualifiedName/fullname1.fs create mode 100644 snippets/fsharp/System/Type/BaseType/basetype3.fs create mode 100644 snippets/fsharp/System/Type/BaseType/fs.fsproj create mode 100644 snippets/fsharp/System/Type/BaseType/remarks.fs create mode 100644 snippets/fsharp/System/Type/BaseType/testbasetype.fs create mode 100644 snippets/fsharp/System/Type/ContainsGenericParameters/fs.fsproj create mode 100644 snippets/fsharp/System/Type/ContainsGenericParameters/source.fs create mode 100644 snippets/fsharp/System/Type/DeclaringMethod/fs.fsproj create mode 100644 snippets/fsharp/System/Type/DeclaringMethod/source.fs create mode 100644 snippets/fsharp/System/Type/DeclaringType/fs.fsproj create mode 100644 snippets/fsharp/System/Type/DeclaringType/remarks.fs create mode 100644 snippets/fsharp/System/Type/DeclaringType/source.fs create mode 100644 snippets/fsharp/System/Type/DefaultBinder/fs.fsproj create mode 100644 snippets/fsharp/System/Type/DefaultBinder/type_defaultbinder.fs create mode 100644 snippets/fsharp/System/Type/EmptyTypes/fs.fsproj create mode 100644 snippets/fsharp/System/Type/EmptyTypes/source.fs create mode 100644 snippets/fsharp/System/Type/Equals/EqualsEx1.fs create mode 100644 snippets/fsharp/System/Type/Equals/fs.fsproj create mode 100644 snippets/fsharp/System/Type/Equals/source.fs create mode 100644 snippets/fsharp/System/Type/FilterAttribute/fs.fsproj create mode 100644 snippets/fsharp/System/Type/FilterAttribute/type_filterattribute.fs create mode 100644 snippets/fsharp/System/Type/FilterName/fs.fsproj create mode 100644 snippets/fsharp/System/Type/FilterName/source.fs create mode 100644 snippets/fsharp/System/Type/FilterNameIgnoreCase/fs.fsproj create mode 100644 snippets/fsharp/System/Type/FilterNameIgnoreCase/type_filternameignorecase.fs create mode 100644 snippets/fsharp/System/Type/FindInterfaces/fs.fsproj create mode 100644 snippets/fsharp/System/Type/FindInterfaces/type_findinterfaces.fs create mode 100644 snippets/fsharp/System/Type/FindMembers/fs.fsproj create mode 100644 snippets/fsharp/System/Type/FindMembers/type_findmembers.fs create mode 100644 snippets/fsharp/System/Type/FullName/Fullname3.fs create mode 100644 snippets/fsharp/System/Type/FullName/Fullname4.fs create mode 100644 snippets/fsharp/System/Type/FullName/Fullname5.fs create mode 100644 snippets/fsharp/System/Type/FullName/fs.fsproj create mode 100644 snippets/fsharp/System/Type/FullName/fullnameex1.fs create mode 100644 snippets/fsharp/System/Type/FullName/testfullname.fs create mode 100644 snippets/fsharp/System/Type/GUID/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GUID/type_guid.fs create mode 100644 snippets/fsharp/System/Type/GenericParameterAttributes/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GenericParameterAttributes/source.fs create mode 100644 snippets/fsharp/System/Type/GenericParameterPosition/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GenericParameterPosition/remarks.fs create mode 100644 snippets/fsharp/System/Type/GetArrayRank/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetArrayRank/type_getarrayrank.fs create mode 100644 snippets/fsharp/System/Type/GetConstructor/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetConstructor/type_getconstructor.fs create mode 100644 snippets/fsharp/System/Type/GetConstructor/type_getconstructor2.fs create mode 100644 snippets/fsharp/System/Type/GetConstructor/type_getconstructor3.fs create mode 100644 snippets/fsharp/System/Type/GetConstructors/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetConstructors/source1.fs create mode 100644 snippets/fsharp/System/Type/GetConstructors/source2.fs create mode 100644 snippets/fsharp/System/Type/GetDefaultMembers/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetDefaultMembers/type_getdefaultmembers.fs create mode 100644 snippets/fsharp/System/Type/GetElementType/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetElementType/testgetelementtype.fs create mode 100644 snippets/fsharp/System/Type/GetEvent/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetEvent/type_getevent.fs create mode 100644 snippets/fsharp/System/Type/GetEvent/type_getevent1.fs create mode 100644 snippets/fsharp/System/Type/GetEvents/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetEvents/type_getevents1.fs create mode 100644 snippets/fsharp/System/Type/GetEvents/type_getevents2.fs create mode 100644 snippets/fsharp/System/Type/GetField/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetField/type_getfield.fs create mode 100644 snippets/fsharp/System/Type/GetFields/fieldinfo_isspecialname.fs create mode 100644 snippets/fsharp/System/Type/GetFields/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetFields/source.fs create mode 100644 snippets/fsharp/System/Type/GetGenericArguments/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetGenericArguments/source.fs create mode 100644 snippets/fsharp/System/Type/GetGenericTypeDefinition/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetGenericTypeDefinition/source.fs create mode 100644 snippets/fsharp/System/Type/GetHashCode/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetHashCode/type_gethashcode_getfields.fs create mode 100644 snippets/fsharp/System/Type/GetInterface/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetInterface/type_getinterface.fs create mode 100644 snippets/fsharp/System/Type/GetInterfaceMap/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetInterfaceMap/interfacemapping1.fs create mode 100644 snippets/fsharp/System/Type/GetInterfaces/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetInterfaces/type_getinterfaces1.fs create mode 100644 snippets/fsharp/System/Type/GetMember/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetMember/type_getmember.fs create mode 100644 snippets/fsharp/System/Type/GetMembers/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetMembers/type_getmembers1.fs create mode 100644 snippets/fsharp/System/Type/GetMembers/type_getmembers2.fs create mode 100644 snippets/fsharp/System/Type/GetMethod/GetMethod1.fs create mode 100644 snippets/fsharp/System/Type/GetMethod/GetMethodWithOverloads1.fs create mode 100644 snippets/fsharp/System/Type/GetMethod/GetMethodWithOverloads2.fs create mode 100644 snippets/fsharp/System/Type/GetMethod/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetMethod/type_getmethod1.fs create mode 100644 snippets/fsharp/System/Type/GetMethod/type_getmethod2.fs create mode 100644 snippets/fsharp/System/Type/GetMethod/type_getmethod3.fs create mode 100644 snippets/fsharp/System/Type/GetMethod/type_getmethod4.fs create mode 100644 snippets/fsharp/System/Type/GetMethod/type_getmethod5.fs create mode 100644 snippets/fsharp/System/Type/GetProperties/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetProperties/type_getproperties2.fs create mode 100644 snippets/fsharp/System/Type/GetProperties/type_gettypecode.fs create mode 100644 snippets/fsharp/System/Type/GetProperty/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetProperty/type_getproperty1.fs create mode 100644 snippets/fsharp/System/Type/GetProperty/type_getproperty2.fs create mode 100644 snippets/fsharp/System/Type/GetProperty/type_getproperty21.fs create mode 100644 snippets/fsharp/System/Type/GetProperty/type_getproperty3.fs create mode 100644 snippets/fsharp/System/Type/GetProperty/type_getproperty_types.fs create mode 100644 snippets/fsharp/System/Type/GetType/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetType/source.fs create mode 100644 snippets/fsharp/System/Type/GetType/type_gettype.fs create mode 100644 snippets/fsharp/System/Type/GetTypeCode/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetTypeCode/iconvertible.fs create mode 100644 snippets/fsharp/System/Type/GetTypeFromCLSID/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.fs create mode 100644 snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.fs create mode 100644 snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.fs create mode 100644 snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.fs create mode 100644 snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.fs create mode 100644 snippets/fsharp/System/Type/GetTypeFromHandle/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetTypeFromHandle/type_gettypefromhandle.fs create mode 100644 snippets/fsharp/System/Type/GetTypeFromProgID/fs.fsproj create mode 100644 snippets/fsharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.fs create mode 100644 snippets/fsharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.fs create mode 100644 snippets/fsharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.fs create mode 100644 snippets/fsharp/System/Type/HasElementType/fs.fsproj create mode 100644 snippets/fsharp/System/Type/HasElementType/type_haselementtype.fs create mode 100644 snippets/fsharp/System/Type/HasElementTypeImpl/fs.fsproj create mode 100644 snippets/fsharp/System/Type/HasElementTypeImpl/type_haselementtypeimpl.fs create mode 100644 snippets/fsharp/System/Type/InvokeMember/fs.fsproj create mode 100644 snippets/fsharp/System/Type/InvokeMember/invokemem.fs create mode 100644 snippets/fsharp/System/Type/IsAbstract/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsAbstract/isabstract1.fs create mode 100644 snippets/fsharp/System/Type/IsAnsiClass/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsAnsiClass/type_isansiclass.fs create mode 100644 snippets/fsharp/System/Type/IsArray/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsArray/isarray2.fs create mode 100644 snippets/fsharp/System/Type/IsArrayImpl/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsArrayImpl/type_isarrayimpl.fs create mode 100644 snippets/fsharp/System/Type/IsAssignableFrom/IsAssignableFrom2.fs create mode 100644 snippets/fsharp/System/Type/IsAssignableFrom/IsAssignableFrom3.fs create mode 100644 snippets/fsharp/System/Type/IsAssignableFrom/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.fs create mode 100644 snippets/fsharp/System/Type/IsAssignableFrom/testisassignablefrom.fs create mode 100644 snippets/fsharp/System/Type/IsAutoLayout/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsAutoLayout/type_isautolayout.fs create mode 100644 snippets/fsharp/System/Type/IsClass/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsClass/type_isclass.fs create mode 100644 snippets/fsharp/System/Type/IsContextful/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsContextful/type_iscontextful.fs create mode 100644 snippets/fsharp/System/Type/IsContextfulImpl/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsContextfulImpl/type_iscontextfulimpl.fs create mode 100644 snippets/fsharp/System/Type/IsEnum/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsEnum/testisenum.fs create mode 100644 snippets/fsharp/System/Type/IsExplicitLayout/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsExplicitLayout/type_isexplicitlayout.fs create mode 100644 snippets/fsharp/System/Type/IsGenericParameter/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsGenericParameter/source.fs create mode 100644 snippets/fsharp/System/Type/IsGenericType/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsGenericType/remarks.fs create mode 100644 snippets/fsharp/System/Type/IsGenericType/source.fs create mode 100644 snippets/fsharp/System/Type/IsInstanceOfType/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsInstanceOfType/testisinstanceoftype.fs create mode 100644 snippets/fsharp/System/Type/IsInterface/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsInterface/type_isinterface.fs create mode 100644 snippets/fsharp/System/Type/IsLayoutSequential/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsLayoutSequential/type_islayoutsequential.fs create mode 100644 snippets/fsharp/System/Type/IsMarshalByRefImpl/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsMarshalByRefImpl/type_ismarshalbyrefimpl.fs create mode 100644 snippets/fsharp/System/Type/IsNotPublic/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsNotPublic/source.fs create mode 100644 snippets/fsharp/System/Type/IsPrimitiveImpl/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsPrimitiveImpl/type_isprimitiveimpl.fs create mode 100644 snippets/fsharp/System/Type/IsPublic/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsPublic/type_ispublic.fs create mode 100644 snippets/fsharp/System/Type/IsSealed/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsSealed/type_issealed.fs create mode 100644 snippets/fsharp/System/Type/IsSerializable/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsSerializable/type_isserializable.fs create mode 100644 snippets/fsharp/System/Type/IsSubclassOf/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsSubclassOf/issubclassof_interface1.fs create mode 100644 snippets/fsharp/System/Type/IsSubclassOf/testissubclassof.fs create mode 100644 snippets/fsharp/System/Type/IsValueType/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsValueType/type_isvaluetype.fs create mode 100644 snippets/fsharp/System/Type/IsVisible/fs.fsproj create mode 100644 snippets/fsharp/System/Type/IsVisible/source.fs create mode 100644 snippets/fsharp/System/Type/MakeByRefType/fs.fsproj create mode 100644 snippets/fsharp/System/Type/MakeByRefType/source.fs create mode 100644 snippets/fsharp/System/Type/MakeGenericType/fs.fsproj create mode 100644 snippets/fsharp/System/Type/MakeGenericType/remarks.fs create mode 100644 snippets/fsharp/System/Type/MakeGenericType/source.fs create mode 100644 snippets/fsharp/System/Type/MemberType/fs.fsproj create mode 100644 snippets/fsharp/System/Type/MemberType/source.fs create mode 100644 snippets/fsharp/System/Type/Missing/fs.fsproj create mode 100644 snippets/fsharp/System/Type/Missing/source.fs create mode 100644 snippets/fsharp/System/Type/Module/fs.fsproj create mode 100644 snippets/fsharp/System/Type/Module/type_tostring.fs create mode 100644 snippets/fsharp/System/Type/Overview/Equals1.fs create mode 100644 snippets/fsharp/System/Type/Overview/GetType1.fs create mode 100644 snippets/fsharp/System/Type/Overview/fs.fsproj create mode 100644 snippets/fsharp/System/Type/Overview/source.fs create mode 100644 snippets/fsharp/System/Type/ReflectedType/fs.fsproj create mode 100644 snippets/fsharp/System/Type/ReflectedType/source.fs create mode 100644 snippets/fsharp/System/Type/StructLayoutAttribute/fs.fsproj create mode 100644 snippets/fsharp/System/Type/StructLayoutAttribute/source.fs create mode 100644 snippets/fsharp/System/Type/TypeHandle/fs.fsproj create mode 100644 snippets/fsharp/System/Type/TypeHandle/type_typehandle.fs diff --git a/snippets/fsharp/System/Type/Assembly/fs.fsproj b/snippets/fsharp/System/Type/Assembly/fs.fsproj new file mode 100644 index 00000000000..1f2541e7bb5 --- /dev/null +++ b/snippets/fsharp/System/Type/Assembly/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/Assembly/type_assembly.fs b/snippets/fsharp/System/Type/Assembly/type_assembly.fs new file mode 100644 index 00000000000..0c256d12309 --- /dev/null +++ b/snippets/fsharp/System/Type/Assembly/type_assembly.fs @@ -0,0 +1,16 @@ +// +open System + +let objType = typeof + +// Print the assembly full name. +printfn $"Assembly full name:\n {objType.Assembly.FullName}." + +// Print the assembly qualified name. +printfn $"Assembly qualified name:\n {objType.AssemblyQualifiedName}." +// The example displays the following output if run under the .NET Framework 4.5: +// Assembly full name: +// mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. +// Assembly qualified name: +// System.Array, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/AssemblyQualifiedName/fs.fsproj b/snippets/fsharp/System/Type/AssemblyQualifiedName/fs.fsproj new file mode 100644 index 00000000000..1a8fe46b2e0 --- /dev/null +++ b/snippets/fsharp/System/Type/AssemblyQualifiedName/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/AssemblyQualifiedName/fullname1.fs b/snippets/fsharp/System/Type/AssemblyQualifiedName/fullname1.fs new file mode 100644 index 00000000000..5fe88cb0434 --- /dev/null +++ b/snippets/fsharp/System/Type/AssemblyQualifiedName/fullname1.fs @@ -0,0 +1,79 @@ +// +open System +open System.Globalization + +let showTypeInfo (t: Type) = + printfn $"Name: {t.Name}" + printfn $"Full Name: {t.FullName}" + printfn $"ToString: {t}" + printfn $"Assembly Qualified Name: {t.AssemblyQualifiedName}\n" + +typeof +|> showTypeInfo + +(typeof>).GetGenericTypeDefinition() +|> showTypeInfo + +let list = ResizeArray() +list.GetType() +|> showTypeInfo + +let v: obj = 12 +v.GetType() +|> showTypeInfo + +typeof +|> showTypeInfo + +let ifmt = NumberFormatInfo.CurrentInfo +ifmt.GetType() +|> showTypeInfo + +let o = Some 3 +o.GetType() +|> showTypeInfo + +// The example displays output like the following: +// Name: String +// Full Name: System.String +// ToString: System.String +// Assembly Qualified Name: System.String, mscorlib, Version=4.0.0.0, Culture=neutr +// al, PublicKeyToken=b77a5c561934e089 +// +// Name: List`1 +// Full Name: System.Collections.Generic.List`1 +// ToString: System.Collections.Generic.List`1[T] +// Assembly Qualified Name: System.Collections.Generic.List`1, mscorlib, Version=4. +// 0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 +// +// Name: List`1 +// Full Name: System.Collections.Generic.List`1[[System.String, mscorlib, Version=4 +// .0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] +// ToString: System.Collections.Generic.List`1[System.String] +// Assembly Qualified Name: System.Collections.Generic.List`1[[System.String, mscor +// lib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorl +// ib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 +// +// Name: Int32 +// Full Name: System.Int32 +// ToString: System.Int32 +// Assembly Qualified Name: System.Int32, mscorlib, Version=4.0.0.0, Culture=neutra +// l, PublicKeyToken=b77a5c561934e089 +// +// Name: IFormatProvider +// Full Name: System.IFormatProvider +// ToString: System.IFormatProvider +// Assembly Qualified Name: System.IFormatProvider, mscorlib, Version=4.0.0.0, Cult +// ure=neutral, PublicKeyToken=b77a5c561934e089 +// +// Name: NumberFormatInfo +// Full Name: System.Globalization.NumberFormatInfo +// ToString: System.Globalization.NumberFormatInfo +// Assembly Qualified Name: System.Globalization.NumberFormatInfo, mscorlib, Versio +// n=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 +// +// Name: FSharpOption`1 +// Full Name: Microsoft.FSharp.Core.FSharpOption`1[[System.Int32, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]] +// ToString: Microsoft.FSharp.Core.FSharpOption`1[System.Int32] +// Assembly Qualified Name: Microsoft.FSharp.Core.FSharpOption`1[[System.Int32, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], FSharp.Core, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/BaseType/basetype3.fs b/snippets/fsharp/System/Type/BaseType/basetype3.fs new file mode 100644 index 00000000000..9314f99e7d2 --- /dev/null +++ b/snippets/fsharp/System/Type/BaseType/basetype3.fs @@ -0,0 +1,37 @@ +namespace global + +// +type A() = class end + +type B() = inherit A() + +type C() = inherit B() + +module Example = + [] + let main _ = + for t in typeof.Assembly.GetTypes() do + printfn $"{t.FullName} derived from: " + let mutable derived = t + while derived <> null do + derived <- derived.BaseType + if derived <> null then + printfn $" {derived.FullName}" + printfn "" + 0 +// The example displays the following output: +// Example derived from: +// System.Object +// +// A derived from: +// System.Object +// +// B derived from: +// A +// System.Object +// +// C derived from: +// B +// A +// System.Object +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/BaseType/fs.fsproj b/snippets/fsharp/System/Type/BaseType/fs.fsproj new file mode 100644 index 00000000000..11c8b5aec14 --- /dev/null +++ b/snippets/fsharp/System/Type/BaseType/fs.fsproj @@ -0,0 +1,12 @@ + + + Exe + net6.0 + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/BaseType/remarks.fs b/snippets/fsharp/System/Type/BaseType/remarks.fs new file mode 100644 index 00000000000..2acdf4f21d3 --- /dev/null +++ b/snippets/fsharp/System/Type/BaseType/remarks.fs @@ -0,0 +1,6 @@ +module remarks + +// +type B<'U>() = class end +type C<'T>() = inherit B<'T>() +// diff --git a/snippets/fsharp/System/Type/BaseType/testbasetype.fs b/snippets/fsharp/System/Type/BaseType/testbasetype.fs new file mode 100644 index 00000000000..c38b6a2ab00 --- /dev/null +++ b/snippets/fsharp/System/Type/BaseType/testbasetype.fs @@ -0,0 +1,6 @@ +module testbasetype + +// +let t = typeof +printfn $"{t} inherits from {t.BaseType}." +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/ContainsGenericParameters/fs.fsproj b/snippets/fsharp/System/Type/ContainsGenericParameters/fs.fsproj new file mode 100644 index 00000000000..f0a89cd967d --- /dev/null +++ b/snippets/fsharp/System/Type/ContainsGenericParameters/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/ContainsGenericParameters/source.fs b/snippets/fsharp/System/Type/ContainsGenericParameters/source.fs new file mode 100644 index 00000000000..6ac57857fe0 --- /dev/null +++ b/snippets/fsharp/System/Type/ContainsGenericParameters/source.fs @@ -0,0 +1,74 @@ +// +open System +open System.Reflection +open System.Collections.Generic + +// Define a base class with two type parameters. +type Base<'T, 'U>() = class end + +// Define a derived class. The derived class inherits from a constructed +// class that meets the following criteria: +// (1) Its generic type definition is Base. +// (2) It specifies int for the first type parameter. +// (3) For the second type parameter, it uses the same type that is used +// for the type parameter of the derived class. +// Thus, the derived class is a generic type with one type parameter, but +// its base class is an open constructed type with one type argument and +// one type parameter. +type Derived<'V>() = inherit Base() + +let displayGenericTypeInfo (t: Type) = + printfn $"\n{t}" + printfn $"\tIs this a generic type definition? {t.IsGenericTypeDefinition}" + printfn $"\tIs it a generic type? {t.IsGenericType}" + printfn $"\tDoes it have unassigned generic parameters? {t.ContainsGenericParameters}" + + if t.IsGenericType then + // If this is a generic type, display the type arguments. + let typeArguments = t.GetGenericArguments() + + printfn $"\tList type arguments ({typeArguments.Length}):" + + for tParam in typeArguments do + // IsGenericParameter is true only for generic type + // parameters. + if tParam.IsGenericParameter then + printfn $"\t\t{tParam} (unassigned - parameter position {tParam.GenericParameterPosition})" + else + printfn $"\t\t{tParam}" + +printfn $"\r\n--- Display a generic type and the open constructed" +printfn $" type from which it is derived." + +// Create a Type object representing the generic type definition +// for the Derived type, by omitting the type argument. (For +// types with multiple type parameters, supply the commas but +// omit the type arguments.) +// +let derivedType = (typeof>).GetGenericTypeDefinition() +displayGenericTypeInfo derivedType + +// Display its open constructed base type. +displayGenericTypeInfo derivedType.BaseType + +(* This example produces the following output: + +--- Display a generic type and the open constructed + type from which it is derived. + +Derived`1[V] + Is this a generic type definition? True + Is it a generic type? True + Does it have unassigned generic parameters? True + List type arguments (1): + V (unassigned - parameter position 0) + +Base`2[System.Int32,V] + Is this a generic type definition? False + Is it a generic type? True + Does it have unassigned generic parameters? True + List type arguments (2): + System.Int32 + V (unassigned - parameter position 0) + *) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/DeclaringMethod/fs.fsproj b/snippets/fsharp/System/Type/DeclaringMethod/fs.fsproj new file mode 100644 index 00000000000..f0a89cd967d --- /dev/null +++ b/snippets/fsharp/System/Type/DeclaringMethod/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/DeclaringMethod/source.fs b/snippets/fsharp/System/Type/DeclaringMethod/source.fs new file mode 100644 index 00000000000..f7d653f8ffe --- /dev/null +++ b/snippets/fsharp/System/Type/DeclaringMethod/source.fs @@ -0,0 +1,103 @@ +// +open System.Reflection + +// +// Define a class with a generic method. +type Example = + static member Generic<'T>(toDisplay: 'T) = + printfn $"\r\nHere it is: {toDisplay}" +// + +let displayGenericMethodInfo (mi: MethodInfo) = + printfn $"\n{mi}" + + // + printfn $"\tIs this a generic method definition? {mi.IsGenericMethodDefinition}" + // + + // + printfn $"\tIs it a generic method? {mi.IsGenericMethod}" + // + + // + printfn $"\tDoes it have unassigned generic parameters? {mi.ContainsGenericParameters}" + // + + // + // If this is a generic method, display its type arguments. + // + if mi.IsGenericMethod then + let typeArguments = mi.GetGenericArguments() + + printfn $"\tList type arguments ({typeArguments.Length}):" + + for tParam in typeArguments do + // IsGenericParameter is true only for generic type + // parameters. + if tParam.IsGenericParameter then + printfn $"\t\t{tParam} parameter position {tParam.GenericParameterPosition}\n\t\t declaring method: {tParam.DeclaringMethod}" + else + printfn $"\t\t{tParam}" + // + +printfn "\r\n--- Examine a generic method." + +// +// Create a Type object representing class Example, and +// get a MethodInfo representing the generic method. +// +let ex = typeof +let mi = ex.GetMethod "Generic" + +displayGenericMethodInfo mi + +// Assign the int type to the type parameter of the Example +// method. +// +let miConstructed = mi.MakeGenericMethod typeof + +displayGenericMethodInfo miConstructed +// + +// Invoke the method. +let args = [| box 42 |] +miConstructed.Invoke(null, args) |> ignore + +// Invoke the method normally. +Example.Generic 42 + +// +// Get the generic type definition from the closed method, +// and show it's the same as the original definition. +// +let miDef = miConstructed.GetGenericMethodDefinition() +printfn $"\r\nThe definition is the same: {miDef = mi}" +// + +(* This example produces the following output: + +--- Examine a generic method. + +Void Generic[T](T) + Is this a generic method definition? True + Is it a generic method? True + Does it have unassigned generic parameters? True + List type arguments (1): + T parameter position 0 + declaring method: Void Generic[T](T) + +Void Generic[Int32](Int32) + Is this a generic method definition? False + Is it a generic method? True + Does it have unassigned generic parameters? False + List type arguments (1): + System.Int32 + +Here it is: 42 + +Here it is: 42 + +The definition is the same: True + + *) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/DeclaringType/fs.fsproj b/snippets/fsharp/System/Type/DeclaringType/fs.fsproj new file mode 100644 index 00000000000..513e36482ac --- /dev/null +++ b/snippets/fsharp/System/Type/DeclaringType/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net6.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/DeclaringType/remarks.fs b/snippets/fsharp/System/Type/DeclaringType/remarks.fs new file mode 100644 index 00000000000..6e44d37111b --- /dev/null +++ b/snippets/fsharp/System/Type/DeclaringType/remarks.fs @@ -0,0 +1,5 @@ +module remarks + +// +let t = typeof>.GetMethod("ConvertAll").GetGenericArguments().[0].DeclaringType +// diff --git a/snippets/fsharp/System/Type/DeclaringType/source.fs b/snippets/fsharp/System/Type/DeclaringType/source.fs new file mode 100644 index 00000000000..d79fa6d06d9 --- /dev/null +++ b/snippets/fsharp/System/Type/DeclaringType/source.fs @@ -0,0 +1,17 @@ +module source + +// +[] +type MyClassA() = + abstract m: unit -> int + +[] +type MyClassB() = + inherit MyClassA() + +printfn $"""The declaring type of m is {typeof.GetMethod("m").DeclaringType}.""" +(* The example produces the following output: + +The declaring type of m is dtype+MyClassA. +*) +// diff --git a/snippets/fsharp/System/Type/DefaultBinder/fs.fsproj b/snippets/fsharp/System/Type/DefaultBinder/fs.fsproj new file mode 100644 index 00000000000..bec219ce89a --- /dev/null +++ b/snippets/fsharp/System/Type/DefaultBinder/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/DefaultBinder/type_defaultbinder.fs b/snippets/fsharp/System/Type/DefaultBinder/type_defaultbinder.fs new file mode 100644 index 00000000000..af135facdd8 --- /dev/null +++ b/snippets/fsharp/System/Type/DefaultBinder/type_defaultbinder.fs @@ -0,0 +1,19 @@ +module type_defaultbinder + +// +open System +open System.Reflection + +type MyClass() = + member _.HelloWorld() = + printfn "Hello World" + +try + let defaultBinder = Type.DefaultBinder + let myClass = MyClass() + // Invoke the HelloWorld method of MyClass. + myClass.GetType().InvokeMember("HelloWorld", BindingFlags.InvokeMethod, defaultBinder, myClass, [||]) + |> ignore +with e -> + printfn $"Exception: {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/EmptyTypes/fs.fsproj b/snippets/fsharp/System/Type/EmptyTypes/fs.fsproj new file mode 100644 index 00000000000..f0a89cd967d --- /dev/null +++ b/snippets/fsharp/System/Type/EmptyTypes/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/EmptyTypes/source.fs b/snippets/fsharp/System/Type/EmptyTypes/source.fs new file mode 100644 index 00000000000..3f55b7d890b --- /dev/null +++ b/snippets/fsharp/System/Type/EmptyTypes/source.fs @@ -0,0 +1,9 @@ +open System +open System.IO +open System.Reflection + +let func (typ: Type) = + // + let cInfo = typ.GetConstructor(BindingFlags.ExactBinding, null, Type.EmptyTypes, null) + // + () \ No newline at end of file diff --git a/snippets/fsharp/System/Type/Equals/EqualsEx1.fs b/snippets/fsharp/System/Type/Equals/EqualsEx1.fs new file mode 100644 index 00000000000..4c269fcfc7e --- /dev/null +++ b/snippets/fsharp/System/Type/Equals/EqualsEx1.fs @@ -0,0 +1,43 @@ +module EqualsEx1 + +// +open System +open System.Reflection + +let isEqualTo (t: Type) (inst: obj) = + match inst with + | :? Type as t2 -> + printfn $"{t.Name} = {t2.Name}: {t.Equals t2}\n" + | _ -> + printfn "Cannot cast the argument to a type.\n" + +do + let t = typeof + typeof.GetTypeInfo() + |> isEqualTo t + + typeof + |> isEqualTo t + + let t = typeof + typeof + |> isEqualTo t + + let t = typeof>.GetGenericTypeDefinition() + let obj4: obj = (ResizeArray()).GetType() + isEqualTo t obj4 + + let t = typeof + let obj5: obj = null + isEqualTo t obj5 +// The example displays the following output: +// Int32 = Int32: True +// +// Int32 = String: False +// +// Object = Object: True +// +// List`1 = List`1: False +// +// Cannot cast the argument to a type. +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/Equals/fs.fsproj b/snippets/fsharp/System/Type/Equals/fs.fsproj new file mode 100644 index 00000000000..2b808653a6b --- /dev/null +++ b/snippets/fsharp/System/Type/Equals/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net6.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/Equals/source.fs b/snippets/fsharp/System/Type/Equals/source.fs new file mode 100644 index 00000000000..0496d4bc4b7 --- /dev/null +++ b/snippets/fsharp/System/Type/Equals/source.fs @@ -0,0 +1,38 @@ +module source + +// +open System + +type Example() = class end + +do + let a = typeof + let b = typeof + + printfn $"{a} == {b}: {a.Equals b}" + + // The Type objects in a and b are not equal, + // because they represent different types. + + let a = typeof + let b = Example().GetType() + + printfn $"{a} is equal to {b}: {a.Equals b}" + + // The Type objects in a and b are equal, + // because they both represent type Example. + + let b = typeof + + printfn $"typeof({a}).Equals(typeof({b})): {a.Equals b}" + +// The Type objects in a and b are not equal, +// because variable a represents type Example +// and variable b represents type Type. + +(* This code example produces the following output: + System.String == System.Int32: False + Example is equal to Example: True + typeof(Example).Equals(typeof(System.Type)): False +*) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/FilterAttribute/fs.fsproj b/snippets/fsharp/System/Type/FilterAttribute/fs.fsproj new file mode 100644 index 00000000000..257bf613d82 --- /dev/null +++ b/snippets/fsharp/System/Type/FilterAttribute/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/FilterAttribute/type_filterattribute.fs b/snippets/fsharp/System/Type/FilterAttribute/type_filterattribute.fs new file mode 100644 index 00000000000..c7302e3b1cf --- /dev/null +++ b/snippets/fsharp/System/Type/FilterAttribute/type_filterattribute.fs @@ -0,0 +1,20 @@ +// +open System +open System.Reflection +open System.Security + +try + let myFilter = Type.FilterAttribute + let myType = typeof + let myMemberInfoArray = myType.FindMembers(MemberTypes.Constructor ||| MemberTypes.Method, BindingFlags.Public ||| BindingFlags.Static ||| BindingFlags.Instance, myFilter, MethodAttributes.SpecialName) + for myMemberinfo in myMemberInfoArray do + printf $"\n{myMemberinfo.Name}" + printf $" is a {myMemberinfo.MemberType}" +with +| :? ArgumentNullException as e -> + printf $"ArgumentNullException: {e.Message}" +| :? SecurityException as e -> + printf $"SecurityException: {e.Message}" +| e -> + printf $"Exception: {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/FilterName/fs.fsproj b/snippets/fsharp/System/Type/FilterName/fs.fsproj new file mode 100644 index 00000000000..f0a89cd967d --- /dev/null +++ b/snippets/fsharp/System/Type/FilterName/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/FilterName/source.fs b/snippets/fsharp/System/Type/FilterName/source.fs new file mode 100644 index 00000000000..3b63913e91b --- /dev/null +++ b/snippets/fsharp/System/Type/FilterName/source.fs @@ -0,0 +1,13 @@ +open System +open System.Reflection + +type Application = class end +// +// Get the set of methods associated with the type +let mi = typeof.FindMembers(MemberTypes.Constructor ||| + MemberTypes.Method, + BindingFlags.Public ||| BindingFlags.Static ||| BindingFlags.NonPublic ||| + BindingFlags.Instance ||| BindingFlags.DeclaredOnly, + Type.FilterName, "*") +printfn $"Number of methods (includes constructors): {mi.Length}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/FilterNameIgnoreCase/fs.fsproj b/snippets/fsharp/System/Type/FilterNameIgnoreCase/fs.fsproj new file mode 100644 index 00000000000..5ebd7d8f51f --- /dev/null +++ b/snippets/fsharp/System/Type/FilterNameIgnoreCase/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/FilterNameIgnoreCase/type_filternameignorecase.fs b/snippets/fsharp/System/Type/FilterNameIgnoreCase/type_filternameignorecase.fs new file mode 100644 index 00000000000..14d413875ae --- /dev/null +++ b/snippets/fsharp/System/Type/FilterNameIgnoreCase/type_filternameignorecase.fs @@ -0,0 +1,22 @@ +// +open System +open System.Reflection +open System.Security + +try + let myFilter = Type.FilterNameIgnoreCase + let myType = typeof + let myMemberinfo1 = + myType.FindMembers(MemberTypes.Constructor ||| MemberTypes.Method, BindingFlags.Public ||| BindingFlags.Static ||| BindingFlags.Instance, myFilter, "C*") + for myMemberinfo2 in myMemberinfo1 do + printf "\n{myMemberinfo2.Name}" + myMemberinfo2.MemberType + |> printfn " is a %O" +with +| :? ArgumentNullException as e -> + printf $"ArgumentNullException : {e.Message}" +| :? SecurityException as e -> + printf $"SecurityException : {e.Message}" +| e -> + printf $"Exception : {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/FindInterfaces/fs.fsproj b/snippets/fsharp/System/Type/FindInterfaces/fs.fsproj new file mode 100644 index 00000000000..2b907f882e8 --- /dev/null +++ b/snippets/fsharp/System/Type/FindInterfaces/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/FindInterfaces/type_findinterfaces.fs b/snippets/fsharp/System/Type/FindInterfaces/type_findinterfaces.fs new file mode 100644 index 00000000000..d79f6dbac51 --- /dev/null +++ b/snippets/fsharp/System/Type/FindInterfaces/type_findinterfaces.fs @@ -0,0 +1,35 @@ +// +open System +open System.Xml +open System.Reflection + +let myInterfaceFilter (typeObj: Type) (criteriaObj: obj) = + string typeObj = string criteriaObj + +try + let myXMLDoc = XmlDocument() + myXMLDoc.LoadXml("" + "Pride And Prejudice" + "") + let myType = myXMLDoc.GetType() + + // Specify the TypeFilter delegate that compares the + // interfaces against filter criteria. + let myFilter = TypeFilter myInterfaceFilter + let myInterfaceList = + [ "System.Collections.IEnumerable" + "System.Collections.ICollection" ] + for i in myInterfaceList do + let myInterfaces = myType.FindInterfaces(myFilter, i) + if myInterfaces.Length > 0 then + printfn $"\n{myType} implements the interface {i}." + for j in myInterfaces do + printfn $"Interfaces supported: {j}." + else + printfn $"\n{myType} does not implement the interface {i}." +with +| :? ArgumentNullException as e -> + printfn $"ArgumentNullException: {e.Message}" +| :? TargetInvocationException as e -> + printfn $"TargetInvocationException: {e.Message}" +| e -> + printfn $"Exception: {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/FindMembers/fs.fsproj b/snippets/fsharp/System/Type/FindMembers/fs.fsproj new file mode 100644 index 00000000000..75c8e6903aa --- /dev/null +++ b/snippets/fsharp/System/Type/FindMembers/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/FindMembers/type_findmembers.fs b/snippets/fsharp/System/Type/FindMembers/type_findmembers.fs new file mode 100644 index 00000000000..36da1b089d0 --- /dev/null +++ b/snippets/fsharp/System/Type/FindMembers/type_findmembers.fs @@ -0,0 +1,24 @@ +// +open System.Reflection + +let delegateToSearchCriteria (objMemberInfo: MemberInfo) (objSearch: obj) = + // Compare the name of the member function with the filter criteria. + string objMemberInfo.Name = string objSearch + +let objTest = obj () +let objType = objTest.GetType () +try + //Find all static or public methods in the Object class that match the specified name. + let arrayMemberInfo = + objType.FindMembers(MemberTypes.Method, BindingFlags.Public ||| BindingFlags.Static ||| BindingFlags.Instance, MemberFilter delegateToSearchCriteria, "ReferenceEquals") + + for info in arrayMemberInfo do + printfn $"Result of FindMembers -\t{info}\n" +with e -> + printfn $"Exception : {e}" + +(* The example produces the following output: + +Result of FindMembers - Boolean ReferenceEquals(System.Object, System.Object) +*) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/FullName/Fullname3.fs b/snippets/fsharp/System/Type/FullName/Fullname3.fs new file mode 100644 index 00000000000..7cd202f7021 --- /dev/null +++ b/snippets/fsharp/System/Type/FullName/Fullname3.fs @@ -0,0 +1,20 @@ +module Fullname3x + +// +open System + +let t = typeof>.GetGenericTypeDefinition() +printfn $"{t.FullName}" +if t.IsGenericType then + printf " Generic Type Parameters: " + let gtArgs = t.GetGenericArguments() + for arg in gtArgs do + match arg.FullName with + | null -> "(unassigned) " + string arg + | _ -> arg.FullName + |> printfn "%s" + printfn "" +// The example displays the following output: +// System.Nullable`1 +// Generic Type Parameters: (unassigned) T +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/FullName/Fullname4.fs b/snippets/fsharp/System/Type/FullName/Fullname4.fs new file mode 100644 index 00000000000..d10f55bdd32 --- /dev/null +++ b/snippets/fsharp/System/Type/FullName/Fullname4.fs @@ -0,0 +1,37 @@ +module Fullname4 + +// +open System.Reflection + +type GenericType1<'T>() = + member _.Display(elements: 'T[]) = () + member _.HandleT(obj: 'T) = () + member _.ChangeValue(arg: 'T byref) = true + +let t = typeof>.GetGenericTypeDefinition() + +printfn $"Type Name: {t.FullName}" + +let methods = + t.GetMethods(BindingFlags.Instance ||| BindingFlags.DeclaredOnly ||| BindingFlags.Public) + +for method in methods do + printfn $" Method: {method.Name}" + // Get method parameters. + let param = method.GetParameters()[0] + let paramType = param.ParameterType + if method.Name = "HandleT" then + let paramType = paramType.MakePointerType() + match paramType.FullName with + | null -> string paramType + " (unassigned)" + | _ -> paramType.FullName + |> printfn " Parameter: %s" +// The example displays the following output: +// Type Name: GenericType1`1 +// Method: Display +// Parameter: T[] (unassigned)) +// Method: HandleT +// Parameter: T* (unassigned) +// Method: ChangeValue +// Parameter: T& (unassigned) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/FullName/Fullname5.fs b/snippets/fsharp/System/Type/FullName/Fullname5.fs new file mode 100644 index 00000000000..c587e01444f --- /dev/null +++ b/snippets/fsharp/System/Type/FullName/Fullname5.fs @@ -0,0 +1,40 @@ +module Fullname5 + +// +type Base<'T>() = class end + +type Derived<'T>() = inherit Base<'T>() + +let t = typeof>.GetGenericTypeDefinition() +printfn $"Generic Class: {t.FullName}" +printfn $" Contains Generic Paramters: {t.ContainsGenericParameters}" +printfn $" Generic Type Definition: {t.IsGenericTypeDefinition}\n" + +let baseType = t.BaseType +match baseType.FullName with +| null -> "(unassigned) " + string baseType +| _ -> baseType.FullName +|> printfn "Its Base Class: %s" + +printfn $" Contains Generic Paramters: {baseType.ContainsGenericParameters}" +printfn $" Generic Type Definition: {baseType.IsGenericTypeDefinition}" +printfn $" Full Name: {baseType.GetGenericTypeDefinition().FullName}\n" + +let t2 = typeof>.GetGenericTypeDefinition() +printfn $"Generic Class: {t2.FullName}" +printfn $" Contains Generic Paramters: {t2.ContainsGenericParameters}" +printfn $" Generic Type Definition: {t2.IsGenericTypeDefinition}\n" +// The example displays the following output: +// Generic Class: Derived`1 +// Contains Generic Paramters: True +// Generic Type Definition: True +// +// Its Base Class: (unassigned) Base`1[T] +// Contains Generic Paramters: True +// Generic Type Definition: False +// Full Name: Base`1 +// +// Generic Class: Base`1 +// Contains Generic Paramters: True +// Generic Type Definition: True +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/FullName/fs.fsproj b/snippets/fsharp/System/Type/FullName/fs.fsproj new file mode 100644 index 00000000000..8dbcdf38f2b --- /dev/null +++ b/snippets/fsharp/System/Type/FullName/fs.fsproj @@ -0,0 +1,13 @@ + + + Exe + net6.0 + + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/FullName/fullnameex1.fs b/snippets/fsharp/System/Type/FullName/fullnameex1.fs new file mode 100644 index 00000000000..0ffead02129 --- /dev/null +++ b/snippets/fsharp/System/Type/FullName/fullnameex1.fs @@ -0,0 +1,19 @@ +module fullnameex1 + +// +// ResizeArray<'T> is an F# type abbreviation for System.Collection.Generic.List<'T> +open System + +let t = typeof>.GetGenericTypeDefinition() +printfn $"{t.FullName}" +Console.WriteLine() + +let list = ResizeArray() +let t2 = list.GetType() +printfn $"{t2.FullName}" +// The example displays the following output: +// System.Collections.Generic.List`1 +// +// System.Collections.Generic.List`1[[System.String, mscorlib, +// Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/FullName/testfullname.fs b/snippets/fsharp/System/Type/FullName/testfullname.fs new file mode 100644 index 00000000000..7f310db8bce --- /dev/null +++ b/snippets/fsharp/System/Type/FullName/testfullname.fs @@ -0,0 +1,13 @@ +module testfullname + +// +open System + +let t = typeof +printfn $"The full name of the Array type is {t.FullName}." + +(* This example produces the following output: + +The full name of the Array type is System.Array. + *) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GUID/fs.fsproj b/snippets/fsharp/System/Type/GUID/fs.fsproj new file mode 100644 index 00000000000..67478832021 --- /dev/null +++ b/snippets/fsharp/System/Type/GUID/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GUID/type_guid.fs b/snippets/fsharp/System/Type/GUID/type_guid.fs new file mode 100644 index 00000000000..4aa1e125a41 --- /dev/null +++ b/snippets/fsharp/System/Type/GUID/type_guid.fs @@ -0,0 +1,11 @@ +// +type MyClass1() = + member _.MyMethod1() = () + +// Get the type corresponding to the class MyClass. +let myType = typeof +// Get the object of the Guid. +let myGuid = myType.GUID +printfn $"The name of the class is {myType}" +printfn $"The ClassId of MyClass is {myType.GUID}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GenericParameterAttributes/fs.fsproj b/snippets/fsharp/System/Type/GenericParameterAttributes/fs.fsproj new file mode 100644 index 00000000000..f0a89cd967d --- /dev/null +++ b/snippets/fsharp/System/Type/GenericParameterAttributes/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GenericParameterAttributes/source.fs b/snippets/fsharp/System/Type/GenericParameterAttributes/source.fs new file mode 100644 index 00000000000..ab24a1fe59c --- /dev/null +++ b/snippets/fsharp/System/Type/GenericParameterAttributes/source.fs @@ -0,0 +1,90 @@ +// +open System +open System.Reflection + +// Define a sample interface to use as an interface constraint. +type ITest = interface end + +// Define a base type to use as a base class constraint. +type Base() = class end + +// Define the generic type to examine. The first generic type parameter, +// T, derives from the class Base and implements ITest. This demonstrates +// a base class constraint and an interface constraint. The second generic +// type parameter, U, must be a reference type (class) and must have a +// default constructor (new()). This demonstrates special constraints. +type Test<'T, 'U + when 'T :> Base + and 'T :> ITest + and 'U : not struct + and 'U : (new : unit -> 'U)>() = class end + +// Define a type that derives from Base and implements ITest. This type +// satisfies the constraints on T in class Test. +type Derived() = + inherit Base() + interface ITest + +// List the variance and special constraint flags. +let listGenericParameterAttributes (t: Type) = + let gpa = t.GenericParameterAttributes + let variance = gpa &&& GenericParameterAttributes.VarianceMask + + let mutable retval = + // Select the variance flags. + if variance = GenericParameterAttributes.None then + "No variance flag" + else + if variance &&& GenericParameterAttributes.Covariant <> 0 then + "Covariant" + else + "Contravariant" + // Select + let constraints = gpa &&& GenericParameterAttributes.SpecialConstraintMask + + if constraints = GenericParameterAttributes.None then + retval <- retval + " No special constraints" + else + if constraints &&& GenericParameterAttributes.ReferenceTypeConstraint <> 0 then + retval <- retval + " ReferenceTypeConstraint" + if constraints &&& GenericParameterAttributes.NotNullableValueTypeConstraint <> 0 then + retval <- retval + " NotNullableValueTypeConstraint" + if constraints &&& GenericParameterAttributes.DefaultConstructorConstraint <> 0 then + retval <- retval + " DefaultConstructorConstraint" + retval + + +// To get the generic type definition, omit the type +// arguments but retain the comma to indicate the number +// of type arguments. +let def = typeof>.GetGenericTypeDefinition() +printfn $"\nExamining generic type {def}" + +// Get the type parameters of the generic type definition, +// and display them. +let defparams = def.GetGenericArguments() +for tp in defparams do + printfn $"\nType parameter: {tp.Name}" + printfn $"\t{listGenericParameterAttributes tp}" + + // List the base class and interface constraints. The + // constraints are returned in no particular order. If + // there are no class or interface constraints, an empty + // array is returned. + let tpConstraints = tp.GetGenericParameterConstraints() + for tpc in tpConstraints do + printfn $"\t{tpc}" + +(* This example produces the following output: + +Examining generic type Test`2[T,U] + +Type parameter: T + No variance flag no special constraints. + Base + ITest + +Type parameter: U + No variance flag ReferenceTypeConstraint DefaultConstructorConstraint + *) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GenericParameterPosition/fs.fsproj b/snippets/fsharp/System/Type/GenericParameterPosition/fs.fsproj new file mode 100644 index 00000000000..d4d6de0761f --- /dev/null +++ b/snippets/fsharp/System/Type/GenericParameterPosition/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GenericParameterPosition/remarks.fs b/snippets/fsharp/System/Type/GenericParameterPosition/remarks.fs new file mode 100644 index 00000000000..e8375561469 --- /dev/null +++ b/snippets/fsharp/System/Type/GenericParameterPosition/remarks.fs @@ -0,0 +1,6 @@ +// +type B<'T, 'U>() = class end +type A<'V>() = + member _.GetSomething<'X>() = + B<'V, 'X>() +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetArrayRank/fs.fsproj b/snippets/fsharp/System/Type/GetArrayRank/fs.fsproj new file mode 100644 index 00000000000..c39076c7676 --- /dev/null +++ b/snippets/fsharp/System/Type/GetArrayRank/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetArrayRank/type_getarrayrank.fs b/snippets/fsharp/System/Type/GetArrayRank/type_getarrayrank.fs new file mode 100644 index 00000000000..19df0e94deb --- /dev/null +++ b/snippets/fsharp/System/Type/GetArrayRank/type_getarrayrank.fs @@ -0,0 +1,34 @@ +// +open System + +try + let myArray = Array3D.zeroCreate 2 2 3 + myArray[0, 0, 0] <- 12 + myArray[0, 0, 1] <- 2 + myArray[0, 0, 2] <- 35 + + myArray[0, 1, 0] <- 300 + myArray[0, 1, 1] <- 78 + myArray[0, 1, 2] <- 33 + + myArray[1, 0, 0] <- 92 + myArray[1, 0, 1] <- 42 + myArray[1, 0, 2] <- 135 + + myArray[1, 1, 0] <- 30 + myArray[1, 1, 1] <- 7 + myArray[1, 1, 2] <- 3 + let myType = myArray.GetType() + + printfn "Contents of myArray: {{{12,2,35},{300,78,33}},{{92,42,135},{30,7,3}}}" + printfn $"myArray has {myType.GetArrayRank()} dimensions." +with +| :? NotSupportedException as e -> + printfn "NotSupportedException raised." + printfn $"Source: {e.Source}" + printfn $"Message: {e.Message}" +| e -> + printfn "Exception raised." + printfn $"Source: {e.Source}" + printfn $"Message: {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetConstructor/fs.fsproj b/snippets/fsharp/System/Type/GetConstructor/fs.fsproj new file mode 100644 index 00000000000..8633edd1a8c --- /dev/null +++ b/snippets/fsharp/System/Type/GetConstructor/fs.fsproj @@ -0,0 +1,12 @@ + + + Exe + net6.0 + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetConstructor/type_getconstructor.fs b/snippets/fsharp/System/Type/GetConstructor/type_getconstructor.fs new file mode 100644 index 00000000000..063a2ebb7f1 --- /dev/null +++ b/snippets/fsharp/System/Type/GetConstructor/type_getconstructor.fs @@ -0,0 +1,20 @@ +module type_getconstructor + +// +type MyClass1() = + new (i: int) = MyClass1() + +try + let myType = typeof + let types = [| typeof |] + // Get the constructor that takes an integer as a parameter. + let constructorInfoObj = myType.GetConstructor types + if constructorInfoObj <> null then + printfn "The constructor of MyClass1 that takes an integer as a parameter is: \n{constructorInfoObj}" + else + printfn "The constructor of MyClass1 that takes an integer as a parameter is not available." +with e -> + printfn "Exception caught." + printfn $"Source: {e.Source}" + printfn $"Message: {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetConstructor/type_getconstructor2.fs b/snippets/fsharp/System/Type/GetConstructor/type_getconstructor2.fs new file mode 100644 index 00000000000..3ee20e05bf4 --- /dev/null +++ b/snippets/fsharp/System/Type/GetConstructor/type_getconstructor2.fs @@ -0,0 +1,28 @@ +module type_getconstructor2 + +// +open System +open System.Reflection +open System.Security + +type MyClass1(i: int) = class end + +try + let myType = typeof + let types = [| typeof |] + // Get the constructor that is public and takes an integer parameter. + let constructorInfoObj = myType.GetConstructor(BindingFlags.Instance ||| BindingFlags.Public, null, types, null) + if constructorInfoObj <> null then + printfn "The constructor of MyClass1 that is public and takes an integer as a parameter is:\n{constructorInfoObj}" + else + printfn "The constructor of the MyClass1 that is public and takes an integer as a parameter is not available." +with +| :? ArgumentNullException as e -> + printfn $"ArgumentNullException: {e.Message}" +| :? ArgumentException as e -> + printfn $"ArgumentException: {e.Message}" +| :? SecurityException as e -> + printfn $"SecurityException: {e.Message}" +| e -> + printfn $"Exception: {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetConstructor/type_getconstructor3.fs b/snippets/fsharp/System/Type/GetConstructor/type_getconstructor3.fs new file mode 100644 index 00000000000..187b1f40520 --- /dev/null +++ b/snippets/fsharp/System/Type/GetConstructor/type_getconstructor3.fs @@ -0,0 +1,28 @@ +module type_getconstructor3 + +// +open System +open System.Reflection +open System.Security + +type MyClass1(i: int) = class end + +try + let myType = typeof + let types = [| typeof |] + // Get the public instance constructor that takes an integer parameter. + let constructorInfoObj = myType.GetConstructor(BindingFlags.Instance ||| BindingFlags.Public, null, CallingConventions.HasThis, types, null) + if constructorInfoObj <> null then + printfn "The constructor of MyClass1 that is a public instance method and takes an integer as a parameter is: \n{constructorInfoObj}" + else + printfn "The constructor of MyClass1 that is a public instance method and takes an integer as a parameter is not available." +with +| :? ArgumentNullException as e -> + printfn $"ArgumentNullException: {e.Message}" +| :? ArgumentException as e -> + printfn $"ArgumentException: {e.Message}" +| :? SecurityException as e -> + printfn $"SecurityException: {e.Message}" +| e -> + printfn $"Exception: {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetConstructors/fs.fsproj b/snippets/fsharp/System/Type/GetConstructors/fs.fsproj new file mode 100644 index 00000000000..43e50dbf942 --- /dev/null +++ b/snippets/fsharp/System/Type/GetConstructors/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net6.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetConstructors/source1.fs b/snippets/fsharp/System/Type/GetConstructors/source1.fs new file mode 100644 index 00000000000..4274c3f164c --- /dev/null +++ b/snippets/fsharp/System/Type/GetConstructors/source1.fs @@ -0,0 +1,13 @@ +module source1 + +// +type t() = + static do () + new(i: int) = t () + +let p = typeof.GetConstructors() +printfn $"{p.Length}" + +for c in p do + printfn $"{c.IsStatic}" +// diff --git a/snippets/fsharp/System/Type/GetConstructors/source2.fs b/snippets/fsharp/System/Type/GetConstructors/source2.fs new file mode 100644 index 00000000000..d66062c416d --- /dev/null +++ b/snippets/fsharp/System/Type/GetConstructors/source2.fs @@ -0,0 +1,15 @@ +module source2 + +// +open System.Reflection + +type t() = + static do () + new (i: int) = t () + +let p = typeof.GetConstructors(BindingFlags.Public ||| BindingFlags.Static ||| BindingFlags.NonPublic ||| BindingFlags.Instance) +printfn $"{p.Length}" + +for c in p do + printfn $"{c.IsStatic}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetDefaultMembers/fs.fsproj b/snippets/fsharp/System/Type/GetDefaultMembers/fs.fsproj new file mode 100644 index 00000000000..d43269e18af --- /dev/null +++ b/snippets/fsharp/System/Type/GetDefaultMembers/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetDefaultMembers/type_getdefaultmembers.fs b/snippets/fsharp/System/Type/GetDefaultMembers/type_getdefaultmembers.fs new file mode 100644 index 00000000000..3d56dae29eb --- /dev/null +++ b/snippets/fsharp/System/Type/GetDefaultMembers/type_getdefaultmembers.fs @@ -0,0 +1,27 @@ +// +open System +open System.Reflection +open System.IO + +[] +type MyClass() = + member _.Name(s: string) = () + member _.Age + with get () = + 20 +try + let myType = typeof + let memberInfoArray = myType.GetDefaultMembers() + if memberInfoArray.Length > 0 then + for memberInfoObj in memberInfoArray do + printfn $"The default member name is: {memberInfoObj}" + else + printfn "No default members are available." +with +| :? InvalidOperationException as e -> + printfn $"InvalidOperationException: {e.Message}" +| :? IOException as e -> + printfn $"IOException: {e.Message}" +| e -> + printfn $"Exception: {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetElementType/fs.fsproj b/snippets/fsharp/System/Type/GetElementType/fs.fsproj new file mode 100644 index 00000000000..ecc6c9812bf --- /dev/null +++ b/snippets/fsharp/System/Type/GetElementType/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetElementType/testgetelementtype.fs b/snippets/fsharp/System/Type/GetElementType/testgetelementtype.fs new file mode 100644 index 00000000000..70ace19d7ff --- /dev/null +++ b/snippets/fsharp/System/Type/GetElementType/testgetelementtype.fs @@ -0,0 +1,19 @@ +// +type TestGetElementType() = class end +do + let array = [| 1; 2; 3 |] + let t = array.GetType() + let t2 = t.GetElementType() + printfn $"The element type of {array} is {t2}." + + let newMe = TestGetElementType() + let t = newMe.GetType() + let t2 = t.GetElementType() + printfn $"""The element type of {newMe} is {if t2 = null then "null" else string t2}.""" + +(* This code produces the following output: + +The element type of System.Int32[] is System.Int32. +The element type of TestGetElementType is null. + *) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetEvent/fs.fsproj b/snippets/fsharp/System/Type/GetEvent/fs.fsproj new file mode 100644 index 00000000000..ef8126b04be --- /dev/null +++ b/snippets/fsharp/System/Type/GetEvent/fs.fsproj @@ -0,0 +1,12 @@ + + + Exe + net6.0-windows + true + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetEvent/type_getevent.fs b/snippets/fsharp/System/Type/GetEvent/type_getevent.fs new file mode 100644 index 00000000000..4a0595bae42 --- /dev/null +++ b/snippets/fsharp/System/Type/GetEvent/type_getevent.fs @@ -0,0 +1,23 @@ +module type_getevent + +// +open System +open System.Security + +try + let myType = typeof + let myEvent = myType.GetEvent "Click" + if myEvent <> null then + printfn $"Looking for the Click event in the Button class.\n{myEvent}" + else + printfn "The Click event is not available in the Button class." +with +| :? SecurityException as e -> + printfn "An exception occurred." + printfn $"Message :{e.Message}" +| :? ArgumentNullException as e -> + printfn "An exception occurred." + printfn $"Message :{e.Message}" +| e -> + printfn $"The following exception was raised : {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetEvent/type_getevent1.fs b/snippets/fsharp/System/Type/GetEvent/type_getevent1.fs new file mode 100644 index 00000000000..1a6703adb6e --- /dev/null +++ b/snippets/fsharp/System/Type/GetEvent/type_getevent1.fs @@ -0,0 +1,26 @@ +module type_getevent1 + +// +open System +open System.Reflection +open System.Security + +try + // Creates a bitmask based on BindingFlags. + let myBindingFlags = BindingFlags.Instance ||| BindingFlags.Public ||| BindingFlags.NonPublic + let myTypeBindingFlags = typeof + let myEventBindingFlags = myTypeBindingFlags.GetEvent("Click", myBindingFlags) + if myEventBindingFlags <> null then + printfn $"Looking for the Click event in the Button class with the specified BindingFlags.\n{myEventBindingFlags}" + else + printfn "The Click event is not available with the Button class." +with +| :? SecurityException as e -> + printfn "An exception occurred." + printfn $"Message :{e.Message}" +| :? ArgumentNullException as e -> + printfn "An exception occurred." + printfn $"Message :{e.Message}" +| e -> + printfn $"The following exception was raised : {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetEvents/fs.fsproj b/snippets/fsharp/System/Type/GetEvents/fs.fsproj new file mode 100644 index 00000000000..3b55534ca20 --- /dev/null +++ b/snippets/fsharp/System/Type/GetEvents/fs.fsproj @@ -0,0 +1,12 @@ + + + Exe + net6.0-windows + true + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetEvents/type_getevents1.fs b/snippets/fsharp/System/Type/GetEvents/type_getevents1.fs new file mode 100644 index 00000000000..431d0f4b2f1 --- /dev/null +++ b/snippets/fsharp/System/Type/GetEvents/type_getevents1.fs @@ -0,0 +1,23 @@ +module type_getevents + +// +open System +open System.Reflection +open System.Security + +try + // Creates a bitmask based on BindingFlags. + let myBindingFlags = BindingFlags.Instance ||| BindingFlags.Public + let myTypeEvent = typeof + let myEventsBindingFlags = myTypeEvent.GetEvents myBindingFlags + printfn "\nThe events on the Button class with the specified BindingFlags are : " + for flag in myEventsBindingFlags do + printfn $"{flag}" +with +| :? SecurityException as e -> + printfn $"SecurityException: {e.Message}" +| :? ArgumentNullException as e -> + printfn $"ArgumentNullException: {e.Message}" +| e -> + printfn $"Exception : {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetEvents/type_getevents2.fs b/snippets/fsharp/System/Type/GetEvents/type_getevents2.fs new file mode 100644 index 00000000000..7627af96bf3 --- /dev/null +++ b/snippets/fsharp/System/Type/GetEvents/type_getevents2.fs @@ -0,0 +1,23 @@ +module type_getevents2 + +// +open System +open System.Reflection +open System.Security + +try + // Creates a bitmask based on BindingFlags. + let myBindingFlags = BindingFlags.Instance ||| BindingFlags.Public + let myTypeEvent = typeof + let myEventsBindingFlags = myTypeEvent.GetEvents myBindingFlags + printfn "\nThe events on the Button class with the specified BindingFlags are : " + for flag in myEventsBindingFlags do + printfn $"{flag}" +with +| :? SecurityException as e -> + printfn $"SecurityException: {e.Message}" +| :? ArgumentNullException as e -> + printfn $"ArgumentNullException: {e.Message}" +| e -> + printfn $"Exception : {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetField/fs.fsproj b/snippets/fsharp/System/Type/GetField/fs.fsproj new file mode 100644 index 00000000000..c00baaf0831 --- /dev/null +++ b/snippets/fsharp/System/Type/GetField/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetField/type_getfield.fs b/snippets/fsharp/System/Type/GetField/type_getfield.fs new file mode 100644 index 00000000000..13eb3792ed5 --- /dev/null +++ b/snippets/fsharp/System/Type/GetField/type_getfield.fs @@ -0,0 +1,26 @@ +// +// +open System.Reflection + +type MyFieldClassA = + val public Field: string + new () = { Field = "A Field"} + +type MyFieldClassB() = + let field = "B Field" + member _.Field + with get () = field + +let myFieldObjectB = MyFieldClassB() +let myFieldObjectA = MyFieldClassA() + +let myTypeA = typeof +let myFieldInfo = myTypeA.GetField "Field" + +let myTypeB = typeof +let myFieldInfo1 = myTypeB.GetField("field", BindingFlags.NonPublic ||| BindingFlags.Instance) + +printfn $"The value of the public field is: '{myFieldInfo.GetValue myFieldObjectA}'" +printfn $"The value of the private field is: '{myFieldInfo1.GetValue myFieldObjectB}'" +// +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetFields/fieldinfo_isspecialname.fs b/snippets/fsharp/System/Type/GetFields/fieldinfo_isspecialname.fs new file mode 100644 index 00000000000..7dffb7fdf85 --- /dev/null +++ b/snippets/fsharp/System/Type/GetFields/fieldinfo_isspecialname.fs @@ -0,0 +1,20 @@ +module fieldinfo_isspecialname + +// +open System.ComponentModel.Design + +try + // Get the type handle of a specified class. + let myType = typeof + + // Get the fields of the specified class. + let myFields = myType.GetFields() + + printfn $"\nDisplaying fields that have SpecialName attributes:\n" + for field in myFields do + // Determine whether or not each field is a special name. + if field.IsSpecialName then + printfn $"The field {field.Name} has a SpecialName attribute." +with e -> + printfn $"Exception : {e.Message} " +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetFields/fs.fsproj b/snippets/fsharp/System/Type/GetFields/fs.fsproj new file mode 100644 index 00000000000..9738b961349 --- /dev/null +++ b/snippets/fsharp/System/Type/GetFields/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net6.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetFields/source.fs b/snippets/fsharp/System/Type/GetFields/source.fs new file mode 100644 index 00000000000..912b293c22d --- /dev/null +++ b/snippets/fsharp/System/Type/GetFields/source.fs @@ -0,0 +1,35 @@ +// +open System +open System.Reflection + +type AttributesSample() = + member _.Mymethod(int1m: int, str2m: string outref, str3m: string byref) = + str2m <- "in Mymethod" + +let printAttributes (attribType: Type) iAttribValue = + if not attribType.IsEnum then + printfn "This type is not an enum." + else + let fields = attribType.GetFields(BindingFlags.Public ||| BindingFlags.Static) + for f in fields do + let fieldvalue = f.GetValue null :?> int + if fieldvalue &&& iAttribValue = fieldvalue then + printfn $"{f.Name}" + +printfn "Reflection.MethodBase.Attributes Sample" + +// Get the type. +let MyType = Type.GetType "AttributesSample" + +// Get the method Mymethod on the type. +let Mymethodbase = MyType.GetMethod "Mymethod" + +// Display the method name. +printfn $"Mymethodbase = {Mymethodbase}" + +// Get the MethodAttribute enumerated value. +let Myattributes = Mymethodbase.Attributes + +// Display the flags that are set. +printAttributes typeof (int Myattributes) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetGenericArguments/fs.fsproj b/snippets/fsharp/System/Type/GetGenericArguments/fs.fsproj new file mode 100644 index 00000000000..f0a89cd967d --- /dev/null +++ b/snippets/fsharp/System/Type/GetGenericArguments/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetGenericArguments/source.fs b/snippets/fsharp/System/Type/GetGenericArguments/source.fs new file mode 100644 index 00000000000..1b774d76da5 --- /dev/null +++ b/snippets/fsharp/System/Type/GetGenericArguments/source.fs @@ -0,0 +1,68 @@ +module source + +// +open System +open System.Collections.Generic + +type Test() = class end + +let displayGenericTypeInfo (t: Type) = + printfn $"\n{t}" + + printfn $"\tIs this a generic type definition? {t.IsGenericTypeDefinition}" + + printfn "\tIs it a generic type? {t.IsGenericType}" + + // + if t.IsGenericType then + // If this is a generic type, display the type arguments. + let typeArguments = t.GetGenericArguments() + + printfn $"\tList type arguments ({typeArguments.Length}):" + + for tParam in typeArguments do + // If this is a type parameter, display its position. + if tParam.IsGenericParameter then + printfn $"\t\t{tParam}\t(unassigned - parameter position {tParam.GenericParameterPosition})" + else + printfn $"\t\t{tParam}" + // + +printfn "\r\n--- Display information about a constructed type, its" +printfn " generic type definition, and an ordinary type." + +// Create a Dictionary of Test objects, using strings for the keys. +let d = Dictionary() + +// Display information for the constructed type and its generic +// type definition. +displayGenericTypeInfo (d.GetType()) +displayGenericTypeInfo (d.GetType().GetGenericTypeDefinition()) + +// Display information for an ordinary type. +displayGenericTypeInfo typeof + +(* This example produces the following output: + +--- Display information about a constructed type, its + generic type definition, and an ordinary type. + +System.Collections.Generic.Dictionary[System.String,Test] + Is this a generic type definition? False + Is it a generic type? True + List type arguments (2): + System.String + Test + +System.Collections.Generic.Dictionary[TKey,TValue] + Is this a generic type definition? True + Is it a generic type? True + List type arguments (2): + TKey (unassigned - parameter position 0) + TValue (unassigned - parameter position 1) + +System.String + Is this a generic type definition? False + Is it a generic type? False + *) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetGenericTypeDefinition/fs.fsproj b/snippets/fsharp/System/Type/GetGenericTypeDefinition/fs.fsproj new file mode 100644 index 00000000000..f0a89cd967d --- /dev/null +++ b/snippets/fsharp/System/Type/GetGenericTypeDefinition/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetGenericTypeDefinition/source.fs b/snippets/fsharp/System/Type/GetGenericTypeDefinition/source.fs new file mode 100644 index 00000000000..4eda0f4ee82 --- /dev/null +++ b/snippets/fsharp/System/Type/GetGenericTypeDefinition/source.fs @@ -0,0 +1,47 @@ +// +open System +open System.Collections.Generic + +type Test() = class end + +let displayTypeInfo (t: Type) = + printfn $"\n{t}" + printfn $"\tIs this a generic type definition? {t.IsGenericTypeDefinition}" + printfn $"\tIs it a generic type? {t.IsGenericType}" + let typeArguments = t.GetGenericArguments() + printfn $"\tList type arguments ({typeArguments.Length}):" + for tParam in typeArguments do + printfn $"\t\t{tParam}" + +printfn "\n--- Get the generic type that defines a constructed type." + +// Create a Dictionary of Test objects, using strings for the keys. +let d = Dictionary() + +// Get a Type object representing the constructed type. +let constructed = d.GetType() +displayTypeInfo constructed + +let generic = constructed.GetGenericTypeDefinition() +displayTypeInfo generic + + +(* This example produces the following output: + +--- Get the generic type that defines a constructed type. + +System.Collections.Generic.Dictionary`2[System.String,Test] + Is this a generic type definition? False + Is it a generic type? True + List type arguments (2): + System.String + Test + +System.Collections.Generic.Dictionary`2[TKey,TValue] + Is this a generic type definition? True + Is it a generic type? True + List type arguments (2): + TKey + TValue + *) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetHashCode/fs.fsproj b/snippets/fsharp/System/Type/GetHashCode/fs.fsproj new file mode 100644 index 00000000000..e800424f3a2 --- /dev/null +++ b/snippets/fsharp/System/Type/GetHashCode/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net6.0-windows + true + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetHashCode/type_gethashcode_getfields.fs b/snippets/fsharp/System/Type/GetHashCode/type_gethashcode_getfields.fs new file mode 100644 index 00000000000..c3179207bc3 --- /dev/null +++ b/snippets/fsharp/System/Type/GetHashCode/type_gethashcode_getfields.fs @@ -0,0 +1,24 @@ +// +open System.Security +open System.Reflection + +let myType = typeof +let myFields = myType.GetFields(BindingFlags.Static ||| BindingFlags.NonPublic) +printfn "\nThe IPAddress class has the following nonpublic fields: " +for myField in myFields do + printfn $"{myField}" +let myType1 = typeof +let myFields1 = myType1.GetFields() +printfn "\nThe IPAddress class has the following public fields: " +for myField in myFields1 do + printfn $"{myField}" +try + printfn $"The HashCode of the System.Windows.Forms.Button type is: {typeof.GetHashCode()}" +with +| :? SecurityException as e -> + printfn "An exception occurred." + printfn $"Message: {e.Message}" +| e -> + printfn "An exception occurred." + printfn $"Message: {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetInterface/fs.fsproj b/snippets/fsharp/System/Type/GetInterface/fs.fsproj new file mode 100644 index 00000000000..5fb2d9b2982 --- /dev/null +++ b/snippets/fsharp/System/Type/GetInterface/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetInterface/type_getinterface.fs b/snippets/fsharp/System/Type/GetInterface/type_getinterface.fs new file mode 100644 index 00000000000..935d3003be7 --- /dev/null +++ b/snippets/fsharp/System/Type/GetInterface/type_getinterface.fs @@ -0,0 +1,31 @@ +open System.Collections + +// +// +// +let hashtableObj = Hashtable() +let objType = hashtableObj.GetType() +try + // Get the methods implemented in 'IDeserializationCallback' interface. + let arrayMethodInfo = objType.GetInterface("IDeserializationCallback").GetMethods() + printfn "\nMethods of 'IDeserializationCallback' Interface :" + for methodInfo in arrayMethodInfo do + printfn $"{methodInfo}" + + // Get FullName for interface by using Ignore case search. + printfn "\nMethods of 'IEnumerable' Interface" + let arrayMethodInfo = objType.GetInterface("ienumerable",true).GetMethods() + for methodInfo in arrayMethodInfo do + printfn $"{methodInfo}" + + //Get the Interface methods for 'IDictionary' interface + let interfaceMappingObj = objType.GetInterfaceMap typeof + let arrayMemberInfo = interfaceMappingObj.InterfaceMethods + printfn "\nHashtable class Implements the following IDictionary Interface methods :" + for memberInfo in arrayMemberInfo do + printfn $"{memberInfo}" +with e -> + printfn $"Exception : {e}" +// +// +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetInterfaceMap/fs.fsproj b/snippets/fsharp/System/Type/GetInterfaceMap/fs.fsproj new file mode 100644 index 00000000000..0dd17e293e6 --- /dev/null +++ b/snippets/fsharp/System/Type/GetInterfaceMap/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net48 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetInterfaceMap/interfacemapping1.fs b/snippets/fsharp/System/Type/GetInterfaceMap/interfacemapping1.fs new file mode 100644 index 00000000000..92f936ed369 --- /dev/null +++ b/snippets/fsharp/System/Type/GetInterfaceMap/interfacemapping1.fs @@ -0,0 +1,45 @@ +// +open System +open System.Globalization + +let showInterfaceMapping (intType: Type) (implType: Type) = + let map = implType.GetInterfaceMap intType + printfn $"Mapping of {map.InterfaceType} to {map.TargetType}: " + for i = 0 to map.InterfaceMethods.Length - 1 do + let im = map.InterfaceMethods[i] + let tm = map.TargetMethods[i] + printfn $" {im.Name} --> {tm.Name}" + printfn "" + +let interf = [| typeof; typeof |] +let impl = [| typeof; typeof |] + +for i = 0 to interf.Length - 1 do + showInterfaceMapping interf[i] impl[i] + +// The example displays the following output: +// Mapping of System.IFormatProvider to System.Globalization.CultureInfo: +// GetFormat --> GetFormat +// +// Mapping of System.IAppDomainSetup to System.AppDomainSetup: +// get_ApplicationBase --> get_ApplicationBase +// set_ApplicationBase --> set_ApplicationBase +// get_ApplicationName --> get_ApplicationName +// set_ApplicationName --> set_ApplicationName +// get_CachePath --> get_CachePath +// set_CachePath --> set_CachePath +// get_ConfigurationFile --> get_ConfigurationFile +// set_ConfigurationFile --> set_ConfigurationFile +// get_DynamicBase --> get_DynamicBase +// set_DynamicBase --> set_DynamicBase +// get_LicenseFile --> get_LicenseFile +// set_LicenseFile --> set_LicenseFile +// get_PrivateBinPath --> get_PrivateBinPath +// set_PrivateBinPath --> set_PrivateBinPath +// get_PrivateBinPathProbe --> get_PrivateBinPathProbe +// set_PrivateBinPathProbe --> set_PrivateBinPathProbe +// get_ShadowCopyDirectories --> get_ShadowCopyDirectories +// set_ShadowCopyDirectories --> set_ShadowCopyDirectories +// get_ShadowCopyFiles --> get_ShadowCopyFiles +// set_ShadowCopyFiles --> set_ShadowCopyFiles +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetInterfaces/fs.fsproj b/snippets/fsharp/System/Type/GetInterfaces/fs.fsproj new file mode 100644 index 00000000000..6af8eb4b425 --- /dev/null +++ b/snippets/fsharp/System/Type/GetInterfaces/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetInterfaces/type_getinterfaces1.fs b/snippets/fsharp/System/Type/GetInterfaces/type_getinterfaces1.fs new file mode 100644 index 00000000000..8c964f5cb85 --- /dev/null +++ b/snippets/fsharp/System/Type/GetInterfaces/type_getinterfaces1.fs @@ -0,0 +1,22 @@ +// +open System.Collections.Generic + +printfn "\nInterfaces implemented by Dictionary:\n" + +for tinterface in typeof>.GetInterfaces() do + printfn $"{tinterface}" + +(* This example produces output similar to the following: + +Interfaces implemented by Dictionary: + +System.Collections.Generic.IDictionary`2[System.Int32,System.String] +System.Collections.Generic.ICollection`1[System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]] +System.Collections.Generic.IEnumerable`1[System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]] +System.Collection.IEnumerable +System.Collection.IDictionary +System.Collection.ICollection +System.Runtime.Serialization.ISerializable +System.Runtime.Serialization.IDeserializationCallback + *) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetMember/fs.fsproj b/snippets/fsharp/System/Type/GetMember/fs.fsproj new file mode 100644 index 00000000000..49f510b5ec0 --- /dev/null +++ b/snippets/fsharp/System/Type/GetMember/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetMember/type_getmember.fs b/snippets/fsharp/System/Type/GetMember/type_getmember.fs new file mode 100644 index 00000000000..16525638a96 --- /dev/null +++ b/snippets/fsharp/System/Type/GetMember/type_getmember.fs @@ -0,0 +1,71 @@ +// +open System +open System.Security +open System.Reflection + +type MyMemberSample() = + member _.GetMemberInfo() = + let myString = "GetMember_String" + + let myType = myString.GetType() + // Get the members for myString starting with the letter C. + let myMembers = myType.GetMember "C*" + if myMembers.Length > 0 then + printfn $"\nThe member(s) starting with the letter C for type {myType}:" + for index = 0 to myMembers.Length - 1 do + printfn $"Member {index + 1}: {myMembers[index]}" + else + printfn "No members match the search criteria." + + // + member _.GetPublicStaticMemberInfo() = + let myString = "GetMember_String_BindingFlag" + let myType = myString.GetType() + // Get the public static members for the class myString starting with the letter C. + let myMembers = myType.GetMember("C*", BindingFlags.Public ||| BindingFlags.Static) + if myMembers.Length > 0 then + printfn $"\nThe public static member(s) starting with the letter C for type {myType}:" + for index = 0 to myMembers.Length - 1 do + printfn $"Member {index + 1}: {myMembers[index]}" + else + printfn "No members match the search criteria." + // + + // + member _.GetPublicInstanceMethodMemberInfo() = + let myString = "GetMember_String_MemberType_BindingFlag" + let myType = myString.GetType() + // Get the public instance methods for myString starting with the letter C. + let myMembers = myType.GetMember("C*", MemberTypes.Method, BindingFlags.Public ||| BindingFlags.Instance) + if myMembers.Length > 0 then + printfn $"\nThe public instance method(s) starting with the letter C for type {myType}:" + for index = 0 to myMembers.Length - 1 do + printfn $"Member {index + 1}: {myMembers[index]}" + else + printfn "No members match the search criteria." + // + +let myClass = MyMemberSample() +try + myClass.GetMemberInfo() + myClass.GetPublicStaticMemberInfo() + myClass.GetPublicInstanceMethodMemberInfo() +with +| :? ArgumentNullException as e -> + printfn "ArgumentNullException occurred." + printfn $"Source: {e.Source}" + printfn $"Message: {e.Message}" +| :? NotSupportedException as e -> + printfn $"NotSupportedException occurred." + printfn $"Source: {e.Source}" + printfn $"Message: {e.Message}" +| :? SecurityException as e -> + printfn "SecurityException occurred." + printfn $"Source: {e.Source}" + printfn $"Message: {e.Message}" +| e -> + printfn "Exception occurred." + printfn $"Source: {e.Source}" + printfn $"Message: {e.Message}" +// + diff --git a/snippets/fsharp/System/Type/GetMembers/fs.fsproj b/snippets/fsharp/System/Type/GetMembers/fs.fsproj new file mode 100644 index 00000000000..c8f4883c971 --- /dev/null +++ b/snippets/fsharp/System/Type/GetMembers/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net6.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetMembers/type_getmembers1.fs b/snippets/fsharp/System/Type/GetMembers/type_getmembers1.fs new file mode 100644 index 00000000000..8d4ddbb496b --- /dev/null +++ b/snippets/fsharp/System/Type/GetMembers/type_getmembers1.fs @@ -0,0 +1,27 @@ +module type_getmembers1 + +// +type MyClass = + val public myInt: int + val public myString: string + + new () = { myInt = 0; myString = null} + + member _.MyMethod() = () + +try + let myObject = MyClass() + + // Get the type of 'MyClass'. + let myType = myObject.GetType() + + // Get the information related to all public member's of 'MyClass'. + let myMemberInfo = myType.GetMembers() + + printfn $"\nThe members of class '{myType}' are :\n" + for i = 0 to myMemberInfo.Length - 1 do + // Display name and type of the concerned member. + printfn $"'{myMemberInfo[i].Name}' is a {myMemberInfo[i].MemberType}" +with e -> + printfn $"Exception : {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetMembers/type_getmembers2.fs b/snippets/fsharp/System/Type/GetMembers/type_getmembers2.fs new file mode 100644 index 00000000000..891440c5827 --- /dev/null +++ b/snippets/fsharp/System/Type/GetMembers/type_getmembers2.fs @@ -0,0 +1,42 @@ +module type_getmembers2 + +// +open System.Reflection +open System.Security + +type MyClass = + val public myInt: int + val public myString: string + + new () = { myInt = 0; myString = null} + + member _.MyMethod() = () + +try + let MyObject = MyClass() + + // Get the type of the class 'MyClass'. + let myType = MyObject.GetType() + + // Get the public instance members of the class 'MyClass'. + let myMemberInfo = myType.GetMembers(BindingFlags.Public ||| BindingFlags.Instance) + + printfn $"\nThe public instance members of class '{myType}' are : \n" + for i = 0 to myMemberInfo.Length - 1 do + // Display name and type of the member of 'MyClass'. + printfn $"'{myMemberInfo[i].Name}' is a {myMemberInfo[i].MemberType}" +with :? SecurityException as e -> + printfn $"SecurityException : {e.Message}" + +//Output: +//The public instance members of class 'MyClass' are : + +//'Myfunction' is a Method +//'ToString' is a Method +//'Equals' is a Method +//'GetHashCode' is a Method +//'GetType' is a Method +//'.ctor' is a Constructor +//'myInt' is a Field +//'myString' is a Field +// diff --git a/snippets/fsharp/System/Type/GetMethod/GetMethod1.fs b/snippets/fsharp/System/Type/GetMethod/GetMethod1.fs new file mode 100644 index 00000000000..e204bf74897 --- /dev/null +++ b/snippets/fsharp/System/Type/GetMethod/GetMethod1.fs @@ -0,0 +1,48 @@ +module GetMethod1 + +// +open System +open System.Collections + +let getAddMethod (typ: Type) = + let method = + // Determine if this is a generic type. + if typ.IsGenericType then + // Is it an open generic type? + if typ.ContainsGenericParameters then + typ.GetMethod("Add", typ.GetGenericArguments()) + // Get closed generic type arguments. + else + typ.GetMethod("Add", typ.GenericTypeArguments) + // This is not a generic type. + else + typ.GetMethod("Add", [| typeof |]) + + // Test if an Add method was found. + if method = null then + printfn "No Add method found." + else + let t = method.ReflectedType + printf $"{t.Namespace}.{t.Name}.{method.Name}(" + let parms = method.GetParameters() + for i = 0 to parms.Length - 1 do + printf $"""{parms[i].ParameterType.Name}{if i < parms.Length - 1 then ", " else ""}""" + printfn ")" + +// Get a Type object that represents a non-generic type. +getAddMethod typeof + +let list = ResizeArray() +// Get a Type object that represents a constructed generic type. +let closed = list.GetType() +getAddMethod closed + +// Get a Type object that represents an open generic type. +let opn = typeof>.GetGenericTypeDefinition() +getAddMethod opn + +// The example displays the following output: +// System.Collections.ArrayList.Add(Object) +// System.Collections.Generic.List`1.Add(String) +// System.Collections.Generic.List`1.Add(T) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetMethod/GetMethodWithOverloads1.fs b/snippets/fsharp/System/Type/GetMethod/GetMethodWithOverloads1.fs new file mode 100644 index 00000000000..e189a433d20 --- /dev/null +++ b/snippets/fsharp/System/Type/GetMethod/GetMethodWithOverloads1.fs @@ -0,0 +1,69 @@ +module GetMethodWithOverloads1 + +// +open System +open System.Reflection + +type TestClass() = + member _.DisplayValue(s) = + printfn $"%s{s}" + + member _.DisplayValue(s: string, []values: obj[]) = + Console.WriteLine(s, values) + + member this.Equals(t: TestClass) = + Object.ReferenceEquals(this, t) + + static member Equals(t1: TestClass, t2: TestClass) = + Object.ReferenceEquals(t1, t2) + +let retrieveMethod (t: Type) name (flags: BindingFlags) = + try + let m = t.GetMethod(name, flags) + if m <> null then + printf $"{t.Name}.{m.Name}(" + let parms = m.GetParameters() + for i = 0 to parms.Length - 1 do + printf $"{parms[i].ParameterType.Name}" + if i < parms.Length - 1 then + printf ", " + printfn ")" + else + printfn "Method not found" + with :? AmbiguousMatchException -> + printfn "The following duplicate matches were found:" + let methods = t.GetMethods flags + for method in methods do + if method.Name = name then + printf $" {t.Name}.{method.Name}(" + let parms = method.GetParameters() + for i = 0 to parms.Length - 1 do + printf $"{parms[i].ParameterType.Name}" + if i < parms.Length - 1 then + printf ", " + printfn ")" + printfn "" + +let t = typeof + +retrieveMethod t "DisplayValue" (BindingFlags.Public ||| BindingFlags.Instance) + +retrieveMethod t "Equals" (BindingFlags.Public ||| BindingFlags.Instance) + +retrieveMethod t "Equals" (BindingFlags.Public ||| BindingFlags.Instance ||| BindingFlags.DeclaredOnly) + +retrieveMethod t "Equals" (BindingFlags.Public ||| BindingFlags.Static) + +// The example displays the following output: +// The following duplicate matches were found: +// TestClass.DisplayValue(String) +// TestClass.DisplayValue(String, Object[]) +// +// The following duplicate matches were found: +// TestClass.Equals(TestClass) +// TestClass.Equals(Object) +// +// TestClass.Equals(TestClass) +// +// TestClass.Equals(TestClass, TestClass) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetMethod/GetMethodWithOverloads2.fs b/snippets/fsharp/System/Type/GetMethod/GetMethodWithOverloads2.fs new file mode 100644 index 00000000000..edd6f9ffb01 --- /dev/null +++ b/snippets/fsharp/System/Type/GetMethod/GetMethodWithOverloads2.fs @@ -0,0 +1,33 @@ +module GetMethodWithOverloads2 + +// +open System +open System.Reflection + +type Person() = + member val FirstName = "" with get, set + member val LastName = "" with get, set + + override this.ToString() = + (this.FirstName + " " + this.LastName).Trim() + +let retrieveMethod (t: Type) name = + try + let m = t.GetMethod name + if m <> null then + printfn $"""{m.ReflectedType.Name}.{m.Name}: {if m.IsStatic then "Static" else "Instance"} method""" + else + printfn $"{t.Name}.ToString method not found" + with :? AmbiguousMatchException -> + printfn $"{t.Name}.{name} has multiple public overloads." + +let t = typeof +retrieveMethod t "ToString" + +let t2 = typeof +retrieveMethod t2 "ToString" + +// The example displays the following output: +// Person.ToString: Instance method +// Int32.ToString has multiple public overloads. +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetMethod/fs.fsproj b/snippets/fsharp/System/Type/GetMethod/fs.fsproj new file mode 100644 index 00000000000..04185800699 --- /dev/null +++ b/snippets/fsharp/System/Type/GetMethod/fs.fsproj @@ -0,0 +1,17 @@ + + + Exe + net6.0 + + + + + + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetMethod/type_getmethod1.fs b/snippets/fsharp/System/Type/GetMethod/type_getmethod1.fs new file mode 100644 index 00000000000..188011b5414 --- /dev/null +++ b/snippets/fsharp/System/Type/GetMethod/type_getmethod1.fs @@ -0,0 +1,11 @@ +module type_getmethod1 + +// +type Program() = + // Method to get: + member _.MethodA() = () + +// Get MethodA() +let mInfo = typeof.GetMethod "MethodA" +printfn $"Found method: {mInfo}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetMethod/type_getmethod2.fs b/snippets/fsharp/System/Type/GetMethod/type_getmethod2.fs new file mode 100644 index 00000000000..2ee508e2219 --- /dev/null +++ b/snippets/fsharp/System/Type/GetMethod/type_getmethod2.fs @@ -0,0 +1,13 @@ +module type_getmethod2 + +// +open System.Reflection + +type Program() = + // Method to get: + member _.MethodA() = () + +// Get MethodA() +let mInfo = typeof.GetMethod("MethodA", BindingFlags.Public ||| BindingFlags.Instance) +printfn $"Found method: {mInfo}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetMethod/type_getmethod3.fs b/snippets/fsharp/System/Type/GetMethod/type_getmethod3.fs new file mode 100644 index 00000000000..30a24cd7cc8 --- /dev/null +++ b/snippets/fsharp/System/Type/GetMethod/type_getmethod3.fs @@ -0,0 +1,44 @@ +module type_getmethod3 + +// +open System.Reflection + +type Program() = + // Methods to get: + member _.MethodA(i: int, j: int) = () + + member _.MethodA(i: int[]) = () + + member _.MethodA(i: int nativeptr) = () + + member _.MethodA(r: int byref) = () + + // Method that takes an outref parameter: + member _.MethodA(i: int, o: int outref) = o <- 100 + +do + // Get MethodA(int i, int j) + let mInfo = + typeof.GetMethod("MethodA", BindingFlags.Public ||| BindingFlags.Instance, null, CallingConventions.Any, [| typeof; typeof |], null) + printfn $"Found method: {mInfo}" + + // Get MethodA(int[] i) + let mInfo = + typeof.GetMethod("MethodA", BindingFlags.Public ||| BindingFlags.Instance, null, CallingConventions.Any, [| typeof |], null) + printfn $"Found method: {mInfo}" + + // Get MethodA(int* i) + let mInfo = + typeof.GetMethod("MethodA", BindingFlags.Public ||| BindingFlags.Instance, null, CallingConventions.Any, [| typeof.MakePointerType() |], null) + printfn $"Found method: {mInfo}" + + // Get MethodA(ref int r) + let mInfo = + typeof.GetMethod("MethodA", BindingFlags.Public ||| BindingFlags.Instance, null, CallingConventions.Any, [| typeof.MakeByRefType() |], null) + printfn $"Found method: {mInfo}" + + // Get MethodA(int i, out int o) + let mInfo = + typeof.GetMethod("MethodA", BindingFlags.Public ||| BindingFlags.Instance, null, CallingConventions.Any, [| typeof; typeof.MakeByRefType() |], null) + printfn $"Found method: {mInfo}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetMethod/type_getmethod4.fs b/snippets/fsharp/System/Type/GetMethod/type_getmethod4.fs new file mode 100644 index 00000000000..4bf9758cf71 --- /dev/null +++ b/snippets/fsharp/System/Type/GetMethod/type_getmethod4.fs @@ -0,0 +1,37 @@ +module type_getmethod4 + +// +type Program() = + // Methods to get: + member _.MethodA(i: int, j: int) = () + + member _.MethodA(i: int[]) = () + + member _.MethodA(i: int nativeptr) = () + + member _.MethodA(r: int byref) = () + + // Method that takes an outref parameter: + member _.MethodA(i: int, o: int outref) = o <- 100 + +do + // member MethodA: i: int * j: int -> unit + let mInfo = typeof.GetMethod("MethodA", [| typeof; typeof |]) + printfn $"Found method: {mInfo}" + + // member MethodA: i: int[] -> unit + let mInfo = typeof.GetMethod("MethodA", [| typeof |]) + printfn $"Found method: {mInfo}" + + // member MethodA: i: nativeptr -> unit + let mInfo = typeof.GetMethod("MethodA", [| typeof.MakePointerType() |]) + printfn $"Found method: {mInfo}" + + // member MethodA: r: byref -> unit + let mInfo = typeof.GetMethod("MethodA", [| typeof.MakeByRefType() |]) + printfn $"Found method: {mInfo}" + + // member MethodA: i: int * o: outref -> unit + let mInfo = typeof.GetMethod("MethodA", [| typeof; typeof.MakeByRefType() |]) + printfn $"Found method: {mInfo}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetMethod/type_getmethod5.fs b/snippets/fsharp/System/Type/GetMethod/type_getmethod5.fs new file mode 100644 index 00000000000..4477425c88d --- /dev/null +++ b/snippets/fsharp/System/Type/GetMethod/type_getmethod5.fs @@ -0,0 +1,45 @@ +module type_getmethod6 + +// +open System +open System.Reflection + +type Program() = + // Methods to get: + member _.MethodA(i: int, j: int) = () + + member _.MethodA(i: int[]) = () + + member _.MethodA(i: int nativeptr) = () + + member _.MethodA(r: int byref) = () + + // Method that takes an outref parameter: + member _.MethodA(i: int, o: int outref) = o <- 100 + +do + // Get MethodA(int i, int j) + let mInfo = + typeof.GetMethod("MethodA",BindingFlags.Public ||| BindingFlags.Instance, null, [| typeof; typeof |], null) + printfn $"Found method: {mInfo}" + + // Get MethodA(int[] i) + let mInfo = + typeof.GetMethod("MethodA",BindingFlags.Public ||| BindingFlags.Instance, null, [| typeof |], null) + printfn $"Found method: {mInfo}" + + // Get MethodA(int* i) + let mInfo = + typeof.GetMethod("MethodA",BindingFlags.Public ||| BindingFlags.Instance, null, [| typeof.MakePointerType() |], null) + printfn $"Found method: {mInfo}" + + // Get MethodA(ref int r) + let mInfo = + typeof.GetMethod("MethodA",BindingFlags.Public ||| BindingFlags.Instance, null, [| typeof.MakeByRefType() |], null) + printfn $"Found method: {mInfo}" + + // Get MethodA(int i, out int o) + let mInfo = + typeof.GetMethod("MethodA",BindingFlags.Public ||| BindingFlags.Instance, null, [| typeof; typeof.MakeByRefType() |], null) + printfn $"Found method: {mInfo}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetProperties/fs.fsproj b/snippets/fsharp/System/Type/GetProperties/fs.fsproj new file mode 100644 index 00000000000..ea97d274801 --- /dev/null +++ b/snippets/fsharp/System/Type/GetProperties/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net6.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetProperties/type_getproperties2.fs b/snippets/fsharp/System/Type/GetProperties/type_getproperties2.fs new file mode 100644 index 00000000000..3b4ebd348a1 --- /dev/null +++ b/snippets/fsharp/System/Type/GetProperties/type_getproperties2.fs @@ -0,0 +1,86 @@ +module type_getproperties2 + +// +open System.Reflection + +// Create a class having four properties. +type PropertyClass() = + member _.Property1 = + "hello" + + member _.Property2 = + "hello" + + member private _.Property3 = + 32 + + member internal _.Property4 = + "value" + +let getVisibility (accessor: MethodInfo) = + if accessor.IsPublic then + "Public" + elif accessor.IsPrivate then + "Private" + elif accessor.IsFamily then + "Protected" + elif accessor.IsAssembly then + "Internal/Friend" + else + "Protected Internal/Friend" + +let displayPropertyInfo (propInfos: #seq) = + // Display information for all properties. + for propInfo in propInfos do + let readable = propInfo.CanRead + let writable = propInfo.CanWrite + + printfn $" Property name: {propInfo.Name}" + printfn $" Property type: {propInfo.PropertyType}" + printfn $" Read-Write: {readable && writable}" + if readable then + let getAccessor = propInfo.GetMethod + printfn $" Visibility: {getVisibility getAccessor}" + if writable then + let setAccessor = propInfo.SetMethod + printfn $" Visibility: {getVisibility setAccessor}" + printfn "" + +let t = typeof +// Get the public properties. +let propInfos = t.GetProperties(BindingFlags.Public ||| BindingFlags.Instance) +printfn $"The number of public properties: {propInfos.Length}.\n" +// Display the public properties. +displayPropertyInfo propInfos + +// Get the nonpublic properties. +let propInfos1 = t.GetProperties(BindingFlags.NonPublic ||| BindingFlags.Instance) +printfn $"The number of non-public properties: {propInfos1.Length}.\n" +// Display all the nonpublic properties. +displayPropertyInfo propInfos1 + +// The example displays the following output: +// The number of public properties: 2. +// +// Property name: Property1 +// Property type: System.String +// Read-Write: False +// Visibility: Public +// +// Property name: Property2 +// Property type: System.String +// Read-Write: False +// Visibility: Public +// +// The number of non-public properties: 2. +// +// Property name: Property3 +// Property type: System.Int32 +// Read-Write: False +// Visibility: Private +// +// Property name: Property4 +// Property type: System.String +// Read-Write: False +// Visibility: Internal/Friend +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetProperties/type_gettypecode.fs b/snippets/fsharp/System/Type/GetProperties/type_gettypecode.fs new file mode 100644 index 00000000000..d3988c9b20c --- /dev/null +++ b/snippets/fsharp/System/Type/GetProperties/type_gettypecode.fs @@ -0,0 +1,37 @@ +module type_gettypecode + +open System + +// +// Create an object of 'Type' class. +let myType1 = Type.GetType "System.Int32" +// Get the 'TypeCode' of the 'Type' class object created above. +let myTypeCode = Type.GetTypeCode myType1 +printfn $"TypeCode is: {myTypeCode}" +// +// +// Get the properties of 'Type' class object. +let myPropertyInfo = Type.GetType("System.Type").GetProperties() +printfn "Properties of System.Type are:" +for pi in myPropertyInfo do + printfn $"{pi}" +// +// +let myObject = Array.zeroCreate 3 +myObject[0] <- 66 +myObject[1] <- "puri" +myObject[2] <- 33.33 +// Get the array of 'Type' class objects. +let myTypeArray = Type.GetTypeArray myObject +printfn "Full names of the 'Type' objects in the array are:" +for h in myTypeArray do + printfn $"{h.FullName}" +// +// +try + // Throws 'TypeLoadException' because of case-sensitive search. + let myType2 = Type.GetType("sYSTem.iNT32", true, false) + printfn $"{myType2.FullName}" +with :? TypeLoadException as e -> + printfn $"{e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetProperty/fs.fsproj b/snippets/fsharp/System/Type/GetProperty/fs.fsproj new file mode 100644 index 00000000000..ef2b24c867d --- /dev/null +++ b/snippets/fsharp/System/Type/GetProperty/fs.fsproj @@ -0,0 +1,14 @@ + + + Exe + net6.0 + + + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetProperty/type_getproperty1.fs b/snippets/fsharp/System/Type/GetProperty/type_getproperty1.fs new file mode 100644 index 00000000000..123921900ad --- /dev/null +++ b/snippets/fsharp/System/Type/GetProperty/type_getproperty1.fs @@ -0,0 +1,24 @@ +module type_getproperty1 + +// +open System + +type MyClass() = + let mutable myProperty = 0 + // Declare MyProperty. + member _.MyProperty + with get () = + myProperty + and set (value) = + myProperty <- value + +try + // Get the Type object corresponding to MyClass. + let myType = typeof + // Get the PropertyInfo object by passing the property name. + let myPropInfo = myType.GetProperty "MyProperty" + // Display the property name. + printfn $"The {myPropInfo.Name} property exists in MyClass." +with :? NullReferenceException as e -> + printfn $"The property does not exist in MyClass.{e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetProperty/type_getproperty2.fs b/snippets/fsharp/System/Type/GetProperty/type_getproperty2.fs new file mode 100644 index 00000000000..808322c70be --- /dev/null +++ b/snippets/fsharp/System/Type/GetProperty/type_getproperty2.fs @@ -0,0 +1,25 @@ +module type_getproperty2 + +// +open System +open System.Reflection + +type MyClass() = + let mutable myProperty = 0 + // Declare MyProperty. + member _.MyProperty + with get () = + myProperty + and set (value) = + myProperty <- value + +try + // Get Type object of MyClass. + let myType = typeof + // Get the PropertyInfo by passing the property name and specifying the BindingFlags. + let myPropInfo = myType.GetProperty("MyProperty", BindingFlags.Public ||| BindingFlags.Instance) + // Display Name propety to console. + printfn $"{myPropInfo.Name} is a property of MyClass." +with :? NullReferenceException as e -> + printfn $"MyProperty does not exist in MyClass.{e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetProperty/type_getproperty21.fs b/snippets/fsharp/System/Type/GetProperty/type_getproperty21.fs new file mode 100644 index 00000000000..d350029e13e --- /dev/null +++ b/snippets/fsharp/System/Type/GetProperty/type_getproperty21.fs @@ -0,0 +1,28 @@ +module type_getproperty21 + +// +open System + +type MyPropertyClass() = + let myPropertyArray = Array2D.zeroCreate 10 10 + // Declare an indexed property. + member _.Item + with get (i, j) = + myPropertyArray[i, j] + and set (i, j) value = + myPropertyArray[i, j] <- value + +try + let myType = typeof + let myTypeArray = Array.zeroCreate 2 + // Create an instance of the Type array representing the number, order + // and type of the parameters for the property. + myTypeArray.SetValue(typeof, 0) + myTypeArray.SetValue(typeof, 1) + // Search for the indexed property whose parameters match the + // specified argument types and modifiers. + let myPropertyInfo = myType.GetProperty("Item", typeof, myTypeArray, null) + printfn $"{myType.FullName}.{myPropertyInfo.Name} has a property type of {myPropertyInfo.PropertyType}" +with ex -> + printfn $"An exception occurred {ex.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetProperty/type_getproperty3.fs b/snippets/fsharp/System/Type/GetProperty/type_getproperty3.fs new file mode 100644 index 00000000000..7e9f29558b0 --- /dev/null +++ b/snippets/fsharp/System/Type/GetProperty/type_getproperty3.fs @@ -0,0 +1,29 @@ +module type_getproperty3 + +// +open System + +type MyClass1() = + let myArray = array2D [[1; 2]; [3; 4]] + // Declare an indexed property. + member _.Item + with get (i, j) = + myArray[i, j] + and set (i, j) value = + myArray[i, j] <- value +try + // Get the Type object. + let myType = typeof + let myTypeArr = Array.zeroCreate 2 + // Create an instance of a Type array. + myTypeArr.SetValue(typeof, 0) + myTypeArr.SetValue(typeof, 1) + // Get the PropertyInfo object for the indexed property Item, which has two integer parameters. + let myPropInfo = myType.GetProperty("Item", myTypeArr) + // Display the property. + printfn $"The {myPropInfo} property exists in MyClass1." +with :? NullReferenceException as e -> + printfn "An exception occurred." + printfn $"Source : {e.Source}" + printfn $"Message : {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetProperty/type_getproperty_types.fs b/snippets/fsharp/System/Type/GetProperty/type_getproperty_types.fs new file mode 100644 index 00000000000..4d1503c2267 --- /dev/null +++ b/snippets/fsharp/System/Type/GetProperty/type_getproperty_types.fs @@ -0,0 +1,32 @@ +module type_getproperty_types + +// +open System +open System.Reflection + +type MyClass1() = + let mutable myMessage = "Hello World." + member _.MyProperty1 + with get () = + myMessage + and set (value) = + myMessage <- value + +try + let myType = typeof + // Get the PropertyInfo object representing MyProperty1. + let myStringProperties1 = myType.GetProperty("MyProperty1", typeof) + printfn $"The name of the first property of MyClass1 is {myStringProperties1.Name}." + printfn $"The type of the first property of MyClass1 is {myStringProperties1.PropertyType}." +with +| :? ArgumentNullException as e -> + printfn $"ArgumentNullException :{e.Message}" +| :? AmbiguousMatchException as e -> + printfn $"AmbiguousMatchException :{e.Message}" +| :? NullReferenceException as e -> + printfn $"Source : {e.Source}" + printfn $"Message : {e.Message}" +// Output: +// The name of the first property of MyClass1 is MyProperty1. +// The type of the first property of MyClass1 is System.String. +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetType/fs.fsproj b/snippets/fsharp/System/Type/GetType/fs.fsproj new file mode 100644 index 00000000000..2eda8d433d1 --- /dev/null +++ b/snippets/fsharp/System/Type/GetType/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net6.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetType/source.fs b/snippets/fsharp/System/Type/GetType/source.fs new file mode 100644 index 00000000000..9ec4c202801 --- /dev/null +++ b/snippets/fsharp/System/Type/GetType/source.fs @@ -0,0 +1,37 @@ +module source + +open System +open System.Reflection + +do + let test = "System.Collections.Generic.Dictionary`2[System.String,[MyNamespace.MyType, MyAssembly]]" + // + let t = + Type.GetType(test, + (fun aName -> + if aName.Name = "MyAssembly" then + Assembly.LoadFrom @".\MyPath\v5.0\MyAssembly.dll" + else null), + fun assem name ignr -> + if assem = null then + Type.GetType(name, false, ignr) + else + assem.GetType(name, false, ignr)) + // + printfn $"{t}" + + let test = "System.Collections.Generic.Dictionary`2[[YourNamespace.YourType, YourAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null], [MyNamespace.MyType, MyAssembly]]" + // + let t2 = + Type.GetType(test, + (fun aName -> + if aName.Name = "MyAssembly" then + Assembly.LoadFrom @".\MyPath\v5.0\MyAssembly.dll" + else Assembly.Load aName), + (fun assem name ignr -> + if assem = null then + Type.GetType(name, false, ignr) + else + assem.GetType(name, false, ignr)), true) + // + printfn $"{t2}" diff --git a/snippets/fsharp/System/Type/GetType/type_gettype.fs b/snippets/fsharp/System/Type/GetType/type_gettype.fs new file mode 100644 index 00000000000..bf02beee0ae --- /dev/null +++ b/snippets/fsharp/System/Type/GetType/type_gettype.fs @@ -0,0 +1,23 @@ +module type_gettype + +// +open System + +try + // Get the type of a specified class. + let myType1 = Type.GetType "System.Int32" + printfn $"The full name is {myType1.FullName}.\n" +with :? TypeLoadException as e -> + printfn $"{e.GetType().Name}: Unable to load type System.Int32" + +try + // Since NoneSuch does not exist in this assembly, GetType throws a TypeLoadException. + let myType2 = Type.GetType("NoneSuch", true) + printfn $"The full name is {myType2.FullName}." +with :? TypeLoadException as e -> + printfn $"{e.GetType().Name}: Unable to load type NoneSuch" +// The example displays the following output: +// The full name is System.Int32. +// +// TypeLoadException: Unable to load type NoneSuch +// diff --git a/snippets/fsharp/System/Type/GetTypeCode/fs.fsproj b/snippets/fsharp/System/Type/GetTypeCode/fs.fsproj new file mode 100644 index 00000000000..d6c57532356 --- /dev/null +++ b/snippets/fsharp/System/Type/GetTypeCode/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetTypeCode/iconvertible.fs b/snippets/fsharp/System/Type/GetTypeCode/iconvertible.fs new file mode 100644 index 00000000000..c480921ed13 --- /dev/null +++ b/snippets/fsharp/System/Type/GetTypeCode/iconvertible.fs @@ -0,0 +1,91 @@ +// +open System + +/// Class that implements IConvertible +type Complex(x, y) = + + member _.GetDoubleValue() = + x ** 2. + y ** 2. + |> sqrt + + interface IConvertible with + member _.GetTypeCode() = + TypeCode.Object + + member _.ToBoolean(provider: IFormatProvider) = + (x <> 0.) || (y <> 0.) + + member this.ToByte(provider: IFormatProvider) = + Convert.ToByte(this.GetDoubleValue()) + + member this.ToChar(provider: IFormatProvider) = + Convert.ToChar(this.GetDoubleValue()) + + member this.ToDateTime(provider: IFormatProvider) = + Convert.ToDateTime(this.GetDoubleValue()) + + member this.ToDecimal(provider: IFormatProvider) = + Convert.ToDecimal(this.GetDoubleValue()) + + member this.ToDouble(provider: IFormatProvider) = + this.GetDoubleValue() + + member this.ToInt16(provider: IFormatProvider) = + Convert.ToInt16(this.GetDoubleValue()) + + member this.ToInt32(provider: IFormatProvider) = + Convert.ToInt32(this.GetDoubleValue()) + + member this.ToInt64(provider: IFormatProvider) = + Convert.ToInt64(this.GetDoubleValue()) + + member this.ToSByte(provider: IFormatProvider) = + Convert.ToSByte(this.GetDoubleValue()) + + member this.ToSingle(provider: IFormatProvider) = + Convert.ToSingle(this.GetDoubleValue()) + + member _.ToString(provider: IFormatProvider) = + $"( {x} , {y} )" + + member this.ToType(conversionType: Type, provider: IFormatProvider) = + Convert.ChangeType(this.GetDoubleValue(), conversionType) + + member this.ToUInt16(provider: IFormatProvider) = + Convert.ToUInt16(this.GetDoubleValue()) + + member this.ToUInt32(provider: IFormatProvider) = + Convert.ToUInt32(this.GetDoubleValue()) + + member this.ToUInt64(provider: IFormatProvider) = + Convert.ToUInt64(this.GetDoubleValue()) + +// +let writeObjectInfo (testObject: obj) = + let typeCode = Type.GetTypeCode(testObject.GetType()) + match typeCode with + | TypeCode.Boolean -> + printfn $"Boolean: {testObject}" + | TypeCode.Double -> + printfn "Double: {testObject}" + | _ -> + printfn $"{typeCode}: {testObject}" +// + +let testComplex = Complex(4, 7) + +writeObjectInfo testComplex +writeObjectInfo(Convert.ToBoolean(testComplex)) +writeObjectInfo(Convert.ToDecimal(testComplex)) +writeObjectInfo(Convert.ToString(testComplex)) + +(* +This code example produces the following results: + +Object: ConsoleApplication2.Complex +Boolean: True +Decimal: 8.06225774829855 +String: ( 4 , 7 ) + +*) +// diff --git a/snippets/fsharp/System/Type/GetTypeFromCLSID/fs.fsproj b/snippets/fsharp/System/Type/GetTypeFromCLSID/fs.fsproj new file mode 100644 index 00000000000..06dd3a55c81 --- /dev/null +++ b/snippets/fsharp/System/Type/GetTypeFromCLSID/fs.fsproj @@ -0,0 +1,14 @@ + + + Exe + net6.0 + + + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.fs b/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.fs new file mode 100644 index 00000000000..ce6a9649398 --- /dev/null +++ b/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.fs @@ -0,0 +1,20 @@ +module gettypefromclsid1 + +// +open System +open System.Reflection + +let [] WORD_CLSID = "{000209FF-0000-0000-C000-000000000046}" + +// Start an instance of the Word application. +let word = Type.GetTypeFromCLSID(Guid.Parse WORD_CLSID) +printfn $"Instantiated Type object from CLSID {WORD_CLSID}" +let wordObj = Activator.CreateInstance word +printfn $"Instantiated {wordObj.GetType().FullName}" + +// Close Word. +word.InvokeMember("Quit", BindingFlags.InvokeMethod, null, wordObj, [| box 0; 0; false |]) |> ignore +// The example displays the following output: +// Instantiated Type object from CLSID {000209FF-0000-0000-C000-000000000046} +// Instantiated Microsoft.Office.Interop.Word.ApplicationClass +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.fs b/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.fs new file mode 100644 index 00000000000..2c6364d5503 --- /dev/null +++ b/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.fs @@ -0,0 +1,65 @@ +module gettypefromclsid11 + +// +open System +open System.Runtime.InteropServices + +[] +do () + +// Define two classes, and assign one an explicit GUID. +[] +type ExplicitGuid() = class end + +type NoExplicitGuid() = class end + +let explicitType = typeof +let explicitGuid = explicitType.GUID + +// Get type of ExplicitGuid from its GUID. +let explicitCOM = Type.GetTypeFromCLSID explicitGuid +printfn $"Created {explicitCOM.Name} type from CLSID {explicitGuid}" + +// Compare the two type objects. +printfn $"{explicitType.Name} and {explicitCOM.Name} equal: {explicitType.Equals explicitCOM}" + +// Instantiate an ExplicitGuid object. +try + let obj = Activator.CreateInstance explicitCOM + printfn $"Instantiated a {obj.GetType().Name} object" +with :? COMException as e -> + printfn $"COM Exception:\n{e.Message}\n" + +let notExplicit = typeof +let notExplicitGuid = notExplicit.GUID + +// Get type of ExplicitGuid from its GUID. +let notExplicitCOM = Type.GetTypeFromCLSID(notExplicitGuid) +printfn $"Created {notExplicitCOM.Name} type from CLSID {notExplicitGuid}" + +// Compare the two type objects. +printfn $"{notExplicit.Name} and {notExplicitCOM.Name} equal: {notExplicit.Equals notExplicitCOM}" + +// Instantiate an ExplicitGuid object. +try + let obj = Activator.CreateInstance notExplicitCOM + printfn $"Instantiated a {obj.GetType().Name} object" +with :? COMException as e -> + printfn $"COM Exception:\n{e.Message}\n" +// The example displays the following output: +// Created __ComObject type from CLSID d055cba3-1f83-4bd7-ba19-e22b1b8ec3c4 +// ExplicitGuid and __ComObject equal: False +// COM Exception: +// Retrieving the COM class factory for component with CLSID +// {D055CBA3-1F83-4BD7-BA19-E22B1B8EC3C4} failed due to the following error: +// 80040154 Class not registered +// (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). +// +// Created __ComObject type from CLSID 74f03346-a718-3516-ac78-f351c7459ffb +// NoExplicitGuid and __ComObject equal: False +// COM Exception: +// Retrieving the COM class factory for component with CLSID +// {74F03346-A718-3516-AC78-F351C7459FFB} failed due to the following error: +// 80040154 Class not registered +// (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.fs b/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.fs new file mode 100644 index 00000000000..3afdb81ae6c --- /dev/null +++ b/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.fs @@ -0,0 +1,23 @@ +module gettypefromclsid_ex2 + +// +open System +open System.Reflection + +let [] WORD_CLSID = "{000209FF-0000-0000-C000-000000000046}" + +try + // Start an instance of the Word application. + let word = Type.GetTypeFromCLSID(Guid.Parse WORD_CLSID, true) + printfn $"Instantiated Type object from CLSID {WORD_CLSID}" + let wordObj = Activator.CreateInstance word + printfn $"Instantiated {wordObj.GetType().FullName} from CLSID {WORD_CLSID}" + + // Close Word. + word.InvokeMember("Quit", BindingFlags.InvokeMethod, null, wordObj, [| box 0; 0; false |] ) |> ignore +with _ -> + printfn $"Unable to instantiate an object for {WORD_CLSID}" +// The example displays the following output: +// Instantiated Type object from CLSID {000209FF-0000-0000-C000-000000000046} +// Instantiated Microsoft.Office.Interop.Word.ApplicationClass +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.fs b/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.fs new file mode 100644 index 00000000000..f5f4addc7d4 --- /dev/null +++ b/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.fs @@ -0,0 +1,24 @@ +module gettypefromclsid_ex3 + +// +open System +open System.Reflection +open System.Runtime.InteropServices + +let [] WORD_CLSID = "{000209FF-0000-0000-C000-000000000046}" + +// Start an instance of the Word application. +let word = Type.GetTypeFromCLSID(Guid.Parse WORD_CLSID, "computer17.central.contoso.com") +printfn $"Instantiated Type object from CLSID {WORD_CLSID}" +try + let wordObj = Activator.CreateInstance word + printfn $"Instantiated {wordObj.GetType().FullName} from CLSID {WORD_CLSID}" + + // Close Word. + word.InvokeMember("Quit", BindingFlags.InvokeMethod, null, wordObj, [| box 0; 0; false |] ) |> ignore +with :? COMException -> + printfn "Unable to instantiate object." +// The example displays the following output: +// Instantiated Type object from CLSID {000209FF-0000-0000-C000-000000000046} +// Instantiated Microsoft.Office.Interop.Word.ApplicationClass +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.fs b/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.fs new file mode 100644 index 00000000000..1106c4cd141 --- /dev/null +++ b/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.fs @@ -0,0 +1,24 @@ +module gettypefromclsid_ex4 + +// +open System +open System.Reflection + +let [] WORD_CLSID = "{000209FF-0000-0000-C000-000000000046}" + +try + // Start an instance of the Word application. + let word = Type.GetTypeFromCLSID(Guid.Parse WORD_CLSID, "computer17.central.contoso.com", true) + printfn $"Instantiated Type object from CLSID {WORD_CLSID}" + let wordObj = Activator.CreateInstance word + printfn $"Instantiated {wordObj.GetType().FullName} from CLSID {WORD_CLSID}" + + // Close Word. + word.InvokeMember("Quit", BindingFlags.InvokeMethod, null, wordObj, [| box 0; 0; false |] ) |> ignore +// The method can throw any of a variety of exceptions. +with e -> + printfn $"{e.GetType().Name}: Unable to instantiate an object for {WORD_CLSID}" +// The example displays the following output: +// Instantiated Type object from CLSID {000209FF-0000-0000-C000-000000000046} +// Instantiated Microsoft.Office.Interop.Word.ApplicationClass +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetTypeFromHandle/fs.fsproj b/snippets/fsharp/System/Type/GetTypeFromHandle/fs.fsproj new file mode 100644 index 00000000000..1d261052256 --- /dev/null +++ b/snippets/fsharp/System/Type/GetTypeFromHandle/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetTypeFromHandle/type_gettypefromhandle.fs b/snippets/fsharp/System/Type/GetTypeFromHandle/type_gettypefromhandle.fs new file mode 100644 index 00000000000..60644cbb1d5 --- /dev/null +++ b/snippets/fsharp/System/Type/GetTypeFromHandle/type_gettypefromhandle.fs @@ -0,0 +1,9 @@ +open System + +type MyClass1() = class end +// +let myClass1 = MyClass1() +// Get the type referenced by the specified type handle. +let myClass1Type = Type.GetTypeFromHandle(Type.GetTypeHandle myClass1) +printfn $"The Names of the Attributes: {myClass1Type.Attributes}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetTypeFromProgID/fs.fsproj b/snippets/fsharp/System/Type/GetTypeFromProgID/fs.fsproj new file mode 100644 index 00000000000..e996a28ebca --- /dev/null +++ b/snippets/fsharp/System/Type/GetTypeFromProgID/fs.fsproj @@ -0,0 +1,12 @@ + + + Exe + net6.0 + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.fs b/snippets/fsharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.fs new file mode 100644 index 00000000000..0b0ed661a70 --- /dev/null +++ b/snippets/fsharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.fs @@ -0,0 +1,22 @@ +module type_gettypefromprogid2 + +// +open System + +try + // Use the ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1. + let myString1 ="DIRECT.ddPalette.3" + // Use a nonexistent ProgID WrongProgID. + let myString2 ="WrongProgID" + // Make a call to the method to get the type information of the given ProgID. + let myType1 =Type.GetTypeFromProgID(myString1, true) + printfn $"GUID for ProgID DirControl.DirList.1 is {myType1.GUID}." + // Throw an exception because the ProgID is invalid and the throwOnError + // parameter is set to True. + let myType2 =Type.GetTypeFromProgID(myString2, true) + () +with e -> + printfn "An exception occurred." + printfn $"Source: {e.Source}" + printfn $"Message: {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.fs b/snippets/fsharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.fs new file mode 100644 index 00000000000..2929eede07c --- /dev/null +++ b/snippets/fsharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.fs @@ -0,0 +1,20 @@ +module type_gettypefromprogid3 + +// +open System + +try + // Use the ProgID localhost\HKEY_CLASSES_ROOT\DirControl.DirList.1. + let theProgramID ="DirControl.DirList.1" + // Use the server name localhost. + let theServer="localhost" + // Make a call to the method to get the type information for the given ProgID. + let myType =Type.GetTypeFromProgID(theProgramID, theServer) + if myType = null then + raise (Exception "Invalid ProgID or Server.") + printfn $"GUID for ProgID DirControl.DirList.1 is {myType.GUID}." +with e -> + printfn "An exception occurred." + printfn $"Source: {e.Source}" + printfn $"Message: {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.fs b/snippets/fsharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.fs new file mode 100644 index 00000000000..2375b95e92e --- /dev/null +++ b/snippets/fsharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.fs @@ -0,0 +1,23 @@ +module type_gettypefromprogid4 + +// +open System +try + // Use server localhost. + let theServer="localhost" + // Use ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1. + let myString1 ="DirControl.DirList.1" + // Use a wrong ProgID WrongProgID. + let myString2 ="WrongProgID" + // Make a call to the method to get the type information for the given ProgID. + let myType1 =Type.GetTypeFromProgID(myString1, theServer, true) + printfn $"GUID for ProgID DirControl.DirList.1 is {myType1.GUID}." + // Throw an exception because the ProgID is invalid and the throwOnError + // parameter is set to True. + let myType2 =Type.GetTypeFromProgID(myString2, theServer, true) + () +with e -> + printfn "An exception occurred. The ProgID is wrong." + printfn $"Source: {e.Source}" + printfn $"Message: {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/HasElementType/fs.fsproj b/snippets/fsharp/System/Type/HasElementType/fs.fsproj new file mode 100644 index 00000000000..34ebe5596f4 --- /dev/null +++ b/snippets/fsharp/System/Type/HasElementType/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/HasElementType/type_haselementtype.fs b/snippets/fsharp/System/Type/HasElementType/type_haselementtype.fs new file mode 100644 index 00000000000..a095f92e7e4 --- /dev/null +++ b/snippets/fsharp/System/Type/HasElementType/type_haselementtype.fs @@ -0,0 +1,50 @@ +// +#nowarn "9" +open FSharp.NativeInterop + +type Example() = + // This method is for demonstration purposes. + member _.Test(x: int byref, y: int outref, z: int nativeptr) = + x <- 0 + y <- 0 + NativePtr.write z 0 + +// All of the following display 'True'. + +do + // Define an array, get its type, and display HasElementType. + let nums = [| 1; 1; 2; 3; 5; 8; 13 |] + let t = nums.GetType() + printfn $"HasElementType is '{t.HasElementType}' for array types." + + // Test an array type without defining an array. + let t = typeof + printfn $"HasElementType is '{t.HasElementType}' for array types." + + // When you use Reflection Emit to emit dynamic methods and + // assemblies, you can create array types using MakeArrayType. + // The following creates the type 'array of Example'. + let t = typeof.MakeArrayType() + printfn $"HasElementType is '{t.HasElementType}' for array types." + + // When you reflect over methods, HasElementType is true for + // byref, outref, and pointer parameter types. The following + // gets the Test method, defined above, and examines its + // parameters. + let mi = typeof.GetMethod "Test" + let parms = mi.GetParameters() + let t = parms[0].ParameterType + printfn $"HasElementType is '{t.HasElementType}' for ref parameter types." + let t = parms[1].ParameterType + printfn $"HasElementType is '{t.HasElementType}' for out parameter types." + let t = parms[2].ParameterType + printfn $"HasElementType is '{t.HasElementType}' for pointer parameter types." + + // When you use Reflection Emit to emit dynamic methods and + // assemblies, you can create pointer and ByRef types to use + // when you define method parameters. + let t = typeof.MakePointerType() + printfn $"HasElementType is '{t.HasElementType}' for pointer types." + let t = typeof.MakeByRefType() + printfn $"HasElementType is '{t.HasElementType}' for ByRef types." +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/HasElementTypeImpl/fs.fsproj b/snippets/fsharp/System/Type/HasElementTypeImpl/fs.fsproj new file mode 100644 index 00000000000..6daa9109f37 --- /dev/null +++ b/snippets/fsharp/System/Type/HasElementTypeImpl/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/HasElementTypeImpl/type_haselementtypeimpl.fs b/snippets/fsharp/System/Type/HasElementTypeImpl/type_haselementtypeimpl.fs new file mode 100644 index 00000000000..ba99404390a --- /dev/null +++ b/snippets/fsharp/System/Type/HasElementTypeImpl/type_haselementtypeimpl.fs @@ -0,0 +1,45 @@ +// +open System.Reflection + +type MyTypeDelegator(myType) = + inherit TypeDelegator(myType) + + [] + val mutable public myElementType: string + + // Override Type.HasElementTypeImpl(). + override this.HasElementTypeImpl() = + // Determine whether the type is an array. + if myType.IsArray then + this.myElementType <- "array" + true + // Determine whether the type is a reference. + elif myType.IsByRef then + this.myElementType <- "reference" + true + // Determine whether the type is a pointer. + elif myType.IsPointer then + this.myElementType <- "pointer" + true + // Return false if the type is not a reference, array, or pointer type. + else false + +try + let myInt = 0 + let myArray = Array.zeroCreate 5 + let myType = MyTypeDelegator(myArray.GetType()) + // Determine whether myType is an array, pointer, reference type. + printfn "\nDetermine whether a variable is an array, pointer, or reference type.\n" + if myType.HasElementType then + printfn $"The type of myArray is {myType.myElementType}." + else + printfn "myArray is not an array, pointer, or reference type." + let myType = MyTypeDelegator(myInt.GetType()) + // Determine whether myType is an array, pointer, reference type. + if myType.HasElementType then + printfn $"The type of myInt is {myType.myElementType}." + else + printfn "myInt is not an array, pointer, or reference type." +with e -> + printfn $"Exception: {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/InvokeMember/fs.fsproj b/snippets/fsharp/System/Type/InvokeMember/fs.fsproj new file mode 100644 index 00000000000..d913903c126 --- /dev/null +++ b/snippets/fsharp/System/Type/InvokeMember/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/InvokeMember/invokemem.fs b/snippets/fsharp/System/Type/InvokeMember/invokemem.fs new file mode 100644 index 00000000000..7f3ece867e2 --- /dev/null +++ b/snippets/fsharp/System/Type/InvokeMember/invokemem.fs @@ -0,0 +1,80 @@ +// +open System +open System.Reflection + +// This sample class has a field, constructor, method, and property. +type MyType() = + let mutable myField = 0 + + member _.MyType(x: int byref) = + x <- x * 5 + + override _.ToString() = + string myField + + member _.MyProp + with get () = myField + and set value = + if value < 1 then + raise (ArgumentOutOfRangeException("value", value, "value must be > 0")) + myField <- value + +let t = typeof +// Create an instance of a type. +let args = Array.zeroCreate 8 +printfn $"The value of x before the constructor is called is {args[0]}." +let obj = t.InvokeMember(null, + BindingFlags.DeclaredOnly ||| + BindingFlags.Public ||| BindingFlags.NonPublic ||| + BindingFlags.Instance ||| BindingFlags.CreateInstance, null, null, args) +printfn $"Type: {obj.GetType()}" +printfn $"The value of x after the constructor returns is {args[0]}." + +// Read and write to a field. +t.InvokeMember("myField", + BindingFlags.DeclaredOnly ||| + BindingFlags.Public ||| BindingFlags.NonPublic ||| + BindingFlags.Instance ||| BindingFlags.SetField, null, obj, Array.zeroCreate 5) |> ignore +let v = t.InvokeMember("myField", + BindingFlags.DeclaredOnly ||| + BindingFlags.Public ||| BindingFlags.NonPublic ||| + BindingFlags.Instance ||| BindingFlags.GetField, null, obj, null) :?> int +printfn $"myField: {v}" + +// Call a method. +let s = t.InvokeMember("ToString", + BindingFlags.DeclaredOnly ||| + BindingFlags.Public ||| BindingFlags.NonPublic ||| + BindingFlags.Instance ||| BindingFlags.InvokeMethod, null, obj, null) :?> string +printfn $"ToString: {s}" + +// Read and write a property. First, attempt to assign an +// invalid value then assign a valid value finally, get +// the value. +try + // Assign the value zero to MyProp. The Property Set + // throws an exception, because zero is an invalid value. + // InvokeMember catches the exception, and throws + // TargetInvocationException. To discover the real cause + // you must catch TargetInvocationException and examine + // the inner exception. + t.InvokeMember("MyProp", + BindingFlags.DeclaredOnly ||| + BindingFlags.Public ||| BindingFlags.NonPublic ||| + BindingFlags.Instance ||| BindingFlags.SetProperty, null, obj, Array.zeroCreate 0) |> ignore +with :? TargetInvocationException as e -> + // If the property assignment failed for some unexpected + // reason, rethrow the TargetInvocationException. + if e.InnerException.GetType() <> typeof then + reraise () + printfn "An invalid value was assigned to MyProp." +t.InvokeMember("MyProp", + BindingFlags.DeclaredOnly ||| + BindingFlags.Public ||| BindingFlags.NonPublic ||| + BindingFlags.Instance ||| BindingFlags.SetProperty, null, obj, Array.zeroCreate 2) |> ignore +let v2 = t.InvokeMember("MyProp", + BindingFlags.DeclaredOnly ||| + BindingFlags.Public ||| BindingFlags.NonPublic ||| + BindingFlags.Instance ||| BindingFlags.GetProperty, null, obj, null) +printfn $"MyProp: {v2}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsAbstract/fs.fsproj b/snippets/fsharp/System/Type/IsAbstract/fs.fsproj new file mode 100644 index 00000000000..615bf967d52 --- /dev/null +++ b/snippets/fsharp/System/Type/IsAbstract/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsAbstract/isabstract1.fs b/snippets/fsharp/System/Type/IsAbstract/isabstract1.fs new file mode 100644 index 00000000000..fa17e879450 --- /dev/null +++ b/snippets/fsharp/System/Type/IsAbstract/isabstract1.fs @@ -0,0 +1,49 @@ +// +[] +type AbstractClass() = class end + +type DerivedClass() = inherit AbstractClass() + +[] +type SingleClass() = class end + +type ITypeInfo = + abstract GetName: unit -> string + +type ImplementingClass() = + interface ITypeInfo with + member this.GetName() = + this.GetType().FullName + +type DiscriminatedUnion = + | Yes + | No of string + +type Record = + { Name: string + Age: int } + +type InputOutput = delegate of inp: string -> string + +let types = + [ typeof + typeof + typeof + typeof + typeof + typeof + typeof + typeof ] +for typ in types do + printfn $"{typ.Name} is abstract: {typ.IsAbstract}" + +// The example displays the following output: +// AbstractClass is abstract: True +// DerivedClass is abstract: False +// ITypeInfo is abstract: True +// SingleClass is abstract: False +// ImplementingClass is abstract: False +// DiscriminatedUnion is abstract: True +// Record is abstract: False +// InputOutput is abstract: False +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsAnsiClass/fs.fsproj b/snippets/fsharp/System/Type/IsAnsiClass/fs.fsproj new file mode 100644 index 00000000000..c66b63a77f8 --- /dev/null +++ b/snippets/fsharp/System/Type/IsAnsiClass/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsAnsiClass/type_isansiclass.fs b/snippets/fsharp/System/Type/IsAnsiClass/type_isansiclass.fs new file mode 100644 index 00000000000..7610bb075ed --- /dev/null +++ b/snippets/fsharp/System/Type/IsAnsiClass/type_isansiclass.fs @@ -0,0 +1,18 @@ +// +open System.Reflection + +type MyClass() = + let myField = "A sample private field." + +try + let myObject = MyClass() + // Get the type of the 'MyClass'. + let myType = typeof + // Get the field information and the attributes associated with MyClass. + let myFieldInfo = myType.GetField("myField", BindingFlags.NonPublic ||| BindingFlags.Instance) + printfn "\nChecking for the AnsiClass attribute for a field.\n" + // Get and display the name, field, and the AnsiClass attribute. + printfn $"Name of Class: {myType.FullName} \nValue of Field: {myFieldInfo.GetValue myObject} \nIsAnsiClass = {myType.IsAnsiClass}" +with e -> + printfn $"Exception: {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsArray/fs.fsproj b/snippets/fsharp/System/Type/IsArray/fs.fsproj new file mode 100644 index 00000000000..716080a2b9f --- /dev/null +++ b/snippets/fsharp/System/Type/IsArray/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsArray/isarray2.fs b/snippets/fsharp/System/Type/IsArray/isarray2.fs new file mode 100644 index 00000000000..c5c9d6303d8 --- /dev/null +++ b/snippets/fsharp/System/Type/IsArray/isarray2.fs @@ -0,0 +1,19 @@ +// +open System +open System.Collections + +let types = + [ typeof; typeof + typeof; typeof + typeof> + typeof> ] +for t in types do + printfn $"""{t.Name + ":",-15} IsArray = {t.IsArray}""" +// The example displays the following output: +// String: IsArray = False +// Int32[]: IsArray = True +// ArrayList: IsArray = False +// Array: IsArray = False +// List`1: IsArray = False +// IEnumerable`1: IsArray = False +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsArrayImpl/fs.fsproj b/snippets/fsharp/System/Type/IsArrayImpl/fs.fsproj new file mode 100644 index 00000000000..d03940391c8 --- /dev/null +++ b/snippets/fsharp/System/Type/IsArrayImpl/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsArrayImpl/type_isarrayimpl.fs b/snippets/fsharp/System/Type/IsArrayImpl/type_isarrayimpl.fs new file mode 100644 index 00000000000..da51ac8db81 --- /dev/null +++ b/snippets/fsharp/System/Type/IsArrayImpl/type_isarrayimpl.fs @@ -0,0 +1,39 @@ +// +open System.Reflection + +type MyTypeDelegator(myType) = + inherit TypeDelegator(myType) + + [] + val mutable public myElementType : string + + // Override IsArrayImpl(). + override this.IsArrayImpl() = + // Determine whether the type is an array. + if myType.IsArray then + this.myElementType <- "array" + true + // Return false if the type is not an array. + else false + +try + let myInt = 0 + // Create an instance of an array element. + let myArray = Array.zeroCreate 5 + let myType = MyTypeDelegator(myArray.GetType()) + printfn "\nDetermine whether the variable is an array.\n" + // Determine whether myType is an array type. + if myType.IsArray then + printfn $"The type of myArray is {myType.myElementType}." + else + printfn "myArray is not an array." + let myType = MyTypeDelegator(myInt.GetType()) + + // Determine whether myType is an array type. + if myType.IsArray then + printfn $"The type of myInt is {myType.myElementType}." + else + printfn "myInt is not an array." +with e -> + printfn $"Exception: {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsAssignableFrom/IsAssignableFrom2.fs b/snippets/fsharp/System/Type/IsAssignableFrom/IsAssignableFrom2.fs new file mode 100644 index 00000000000..e5dcda48e68 --- /dev/null +++ b/snippets/fsharp/System/Type/IsAssignableFrom/IsAssignableFrom2.fs @@ -0,0 +1,11 @@ +// +open System.IO + +type GenericWithConstraint<'T when 'T :> Stream>() = class end + +let t = typeof +let genericT = typeof>.GetGenericTypeDefinition() +let genericParam = genericT.GetGenericArguments()[0] +printfn $"{t.IsAssignableFrom genericParam}" +// Displays True. +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsAssignableFrom/IsAssignableFrom3.fs b/snippets/fsharp/System/Type/IsAssignableFrom/IsAssignableFrom3.fs new file mode 100644 index 00000000000..1565b24edf0 --- /dev/null +++ b/snippets/fsharp/System/Type/IsAssignableFrom/IsAssignableFrom3.fs @@ -0,0 +1,16 @@ +module IsAssignableFrom3 + +// +open System +open System.Collections + +let t = typeof +let c = typeof + +let mutable instanceOfT = Unchecked.defaultof +let instanceOfC = [| 1; 2; 3; 4 |] +if t.IsAssignableFrom c then + // + instanceOfT <- instanceOfC + // +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsAssignableFrom/fs.fsproj b/snippets/fsharp/System/Type/IsAssignableFrom/fs.fsproj new file mode 100644 index 00000000000..8d62ad342c4 --- /dev/null +++ b/snippets/fsharp/System/Type/IsAssignableFrom/fs.fsproj @@ -0,0 +1,13 @@ + + + Exe + net48 + + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.fs b/snippets/fsharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.fs new file mode 100644 index 00000000000..cec3d94a902 --- /dev/null +++ b/snippets/fsharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.fs @@ -0,0 +1,25 @@ +module isassignablefrom_ex1 + +// +open System +open System.Reflection + +type A() = class end + +let domain = AppDomain.CurrentDomain +let assemName = AssemblyName() +assemName.Name <- "TempAssembly" + +// Define a dynamic assembly in the current application domain. +let assemBuilder = + domain.DefineDynamicAssembly(assemName, AssemblyBuilderAccess.Run) + +// Define a dynamic module in this assembly. +let moduleBuilder = + assemBuilder.DefineDynamicModule "TempModule" + +let b1 = moduleBuilder.DefineType("B", TypeAttributes.Public, typeof) +printfn $"{typeof.IsAssignableFrom b1}" +// The example displays the following output: +// True +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsAssignableFrom/testisassignablefrom.fs b/snippets/fsharp/System/Type/IsAssignableFrom/testisassignablefrom.fs new file mode 100644 index 00000000000..aac75380fd8 --- /dev/null +++ b/snippets/fsharp/System/Type/IsAssignableFrom/testisassignablefrom.fs @@ -0,0 +1,82 @@ +module testisassignablefrom + +// +open System + +type Room() = class end + +type Kitchen() = inherit Room() + +type Bedroom() = inherit Room() + +type Guestroom() = inherit Bedroom() + +type MasterBedroom() = inherit Bedroom() + +// Demonstrate classes: +printfn "Defined Classes:" +let room1 = Room() +let kitchen1 = Kitchen() +let bedroom1 = Bedroom() +let guestroom1 = Guestroom() +let masterbedroom1 = MasterBedroom() + +let room1Type = room1.GetType() +let kitchen1Type = kitchen1.GetType() +let bedroom1Type = bedroom1.GetType() +let guestroom1Type = guestroom1.GetType() +let masterbedroom1Type = masterbedroom1.GetType() + +printfn $"room assignable from kitchen: {room1Type.IsAssignableFrom kitchen1Type}" +printfn $"bedroom assignable from guestroom: {bedroom1Type.IsAssignableFrom guestroom1Type}" +printfn $"kitchen assignable from masterbedroom: {kitchen1Type.IsAssignableFrom masterbedroom1Type}" + +// Demonstrate arrays: +printfn "\nInteger arrays:" + +let array2 = Array.zeroCreate 2 +let array10 = Array.zeroCreate 10 +let array22 = Array2D.zeroCreate 2 2 +let array24 = Array2D.zeroCreate 2 4 + +let array2Type = array2.GetType() +let array10Type = array10.GetType() +let array22Type = array22.GetType() +let array24Type = array24.GetType() + +printfn $"int[2] assignable from int[10]: {array2Type.IsAssignableFrom array10Type}" +printfn $"int[2] assignable from int[2,4]: {array2Type.IsAssignableFrom array24Type}" +printfn $"int[2,4] assignable from int[2,2]: {array24Type.IsAssignableFrom array22Type}" + +// Demonstrate generics: +printfn "\nGenerics:" + +let arrayNull = Array.zeroCreate> 10 +let genIntList = ResizeArray() +let genTList = ResizeArray() + +let arrayNullType = arrayNull.GetType() +let genIntListType = genIntList.GetType() +let genTListType = genTList.GetType() + +printfn $"int[10] assignable from int?[10]: {array10Type.IsAssignableFrom arrayNullType}" +printfn $"List assignable from List: {genIntListType.IsAssignableFrom genTListType}" +printfn $"List assignable from List: {genTListType.IsAssignableFrom genIntListType}" + +//This code example produces the following output: +// +// Defned Classes: +// room assignable from kitchen: True +// bedroom assignable from guestroom: True +// kitchen assignable from masterbedroom: False +// +// Integer arrays: +// int[2] assignable from int[10]: True +// int[2] assignable from int[2,4]: False +// int[2,4] assignable from int[2,2]: True +// +// Generics: +// int[10] assignable from int?[10]: False +// List assignable from List: False +// List assignable from List: False +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsAutoLayout/fs.fsproj b/snippets/fsharp/System/Type/IsAutoLayout/fs.fsproj new file mode 100644 index 00000000000..f6e9340d511 --- /dev/null +++ b/snippets/fsharp/System/Type/IsAutoLayout/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsAutoLayout/type_isautolayout.fs b/snippets/fsharp/System/Type/IsAutoLayout/type_isautolayout.fs new file mode 100644 index 00000000000..e1234c3831e --- /dev/null +++ b/snippets/fsharp/System/Type/IsAutoLayout/type_isautolayout.fs @@ -0,0 +1,13 @@ +// +open System.Runtime.InteropServices + +// The Demo class is attributed as AutoLayout. +[] +type Demo = class end + +// Create an instance of the Type class using the GetType method. +let myType = typeof +// Get and display the IsAutoLayout property of the +// Demoinstance. +printfn $"\nThe AutoLayout property for the Demo class is {myType.IsAutoLayout}." +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsClass/fs.fsproj b/snippets/fsharp/System/Type/IsClass/fs.fsproj new file mode 100644 index 00000000000..ae45c5a0414 --- /dev/null +++ b/snippets/fsharp/System/Type/IsClass/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsClass/type_isclass.fs b/snippets/fsharp/System/Type/IsClass/type_isclass.fs new file mode 100644 index 00000000000..67592625dd4 --- /dev/null +++ b/snippets/fsharp/System/Type/IsClass/type_isclass.fs @@ -0,0 +1,10 @@ +// +type MyDemoClass = class end + +try + let myType = typeof + // Get and display the 'IsClass' property of the 'MyDemoClass' instance. + printfn $"\nIs the specified type a class? {myType.IsClass}." +with e -> + printfn $"\nAn exception occurred: {e.Message}." +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsContextful/fs.fsproj b/snippets/fsharp/System/Type/IsContextful/fs.fsproj new file mode 100644 index 00000000000..6302c718b6f --- /dev/null +++ b/snippets/fsharp/System/Type/IsContextful/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net48 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsContextful/type_iscontextful.fs b/snippets/fsharp/System/Type/IsContextful/type_iscontextful.fs new file mode 100644 index 00000000000..0926a821586 --- /dev/null +++ b/snippets/fsharp/System/Type/IsContextful/type_iscontextful.fs @@ -0,0 +1,31 @@ +// +open System + +type ContextBoundClass() as this = + inherit ContextBoundObject() + [] + val mutable public Value : string + do + this.Value <- "The Value property." + +type Example() = class end + +// Determine whether the types can be hosted in a Context. +printfn $"The IsContextful property for the {typeof.Name} type is {typeof.IsContextful}." +printfn $"The IsContextful property for the {typeof.Name} type is {typeof.IsContextful}." + +// Determine whether the types are marshalled by reference. +printfn $"The IsMarshalByRef property of {typeof.Name} is {typeof.IsMarshalByRef}." +printfn $"The IsMarshalByRef property of {typeof.Name} is {typeof.IsMarshalByRef}." + +// Determine whether the types are primitive datatypes. +printfn $"{typeof.Name} is a primitive data type: {typeof.IsPrimitive}." +printfn $"{typeof.Name} is a primitive data type: {typeof.IsPrimitive}." +// The example displays the following output: +// The IsContextful property for the Example type is False. +// The IsContextful property for the ContextBoundClass type is True. +// The IsMarshalByRef property of Example is False. +// The IsMarshalByRef property of ContextBoundClass is True. +// Int32 is a primitive data type: True. +// String is a primitive data type: False. +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsContextfulImpl/fs.fsproj b/snippets/fsharp/System/Type/IsContextfulImpl/fs.fsproj new file mode 100644 index 00000000000..0eaf0504d82 --- /dev/null +++ b/snippets/fsharp/System/Type/IsContextfulImpl/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsContextfulImpl/type_iscontextfulimpl.fs b/snippets/fsharp/System/Type/IsContextfulImpl/type_iscontextfulimpl.fs new file mode 100644 index 00000000000..648294c1ad9 --- /dev/null +++ b/snippets/fsharp/System/Type/IsContextfulImpl/type_iscontextfulimpl.fs @@ -0,0 +1,42 @@ +// +open System +open System.Reflection + +type MyTypeDelegatorClass(myType) = + inherit TypeDelegator(myType) + member val myElementType = null with get, set + + // Override IsContextfulImpl. + override this.IsContextfulImpl() = + // Check whether the type is contextful. + if myType.IsContextful then + this.myElementType <- " is contextful " + true + else false + +// This class demonstrates IsContextfulImpl. +type MyContextBoundClass() = + inherit ContextBoundObject() + let myString = "This class is used to demonstrate members of the Type class." + +type MyTypeDemoClass() = class end + +try + printfn "Check whether MyContextBoundClass can be hosted in a context." + // Check whether MyContextBoundClass is contextful. + let myType = MyTypeDelegatorClass typeof + if myType.IsContextful then + printfn $"{typeof} can be hosted in a context." + else + printfn $"{typeof} cannot be hosted in a context." + // Check whether the int type is contextful. + let myType = MyTypeDelegatorClass typeof + printfn "\nCheck whether MyTypeDemoClass can be hosted in a context." + if myType.IsContextful then + printfn $"{typeof} can be hosted in a context." + else + printfn $"{typeof} cannot be hosted in a context." +with e -> + printfn $"Exception: {e.Message}" + +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsEnum/fs.fsproj b/snippets/fsharp/System/Type/IsEnum/fs.fsproj new file mode 100644 index 00000000000..bc158506ce6 --- /dev/null +++ b/snippets/fsharp/System/Type/IsEnum/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsEnum/testisenum.fs b/snippets/fsharp/System/Type/IsEnum/testisenum.fs new file mode 100644 index 00000000000..a435dce331a --- /dev/null +++ b/snippets/fsharp/System/Type/IsEnum/testisenum.fs @@ -0,0 +1,19 @@ +// +open System +type Color = + | Red = 0 + | Blue = 1 + | Green = 2 + +let colorType = typeof +let enumType = typeof +printfn $"Is Color an enum? {colorType.IsEnum}." +printfn $"Is Color a value type? {colorType.IsValueType}." +printfn $"Is Enum an enum Type? {enumType.IsEnum}." +printfn $"Is Enum a value type? {enumType.IsValueType}." +// The example displays the following output: +// Is Color an enum? True. +// Is Color a value type? True. +// Is Enum an enum type? False. +// Is Enum a value type? False. +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsExplicitLayout/fs.fsproj b/snippets/fsharp/System/Type/IsExplicitLayout/fs.fsproj new file mode 100644 index 00000000000..60ebffa833f --- /dev/null +++ b/snippets/fsharp/System/Type/IsExplicitLayout/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsExplicitLayout/type_isexplicitlayout.fs b/snippets/fsharp/System/Type/IsExplicitLayout/type_isexplicitlayout.fs new file mode 100644 index 00000000000..34ada682be7 --- /dev/null +++ b/snippets/fsharp/System/Type/IsExplicitLayout/type_isexplicitlayout.fs @@ -0,0 +1,20 @@ +// +open System.Runtime.InteropServices + +// Class to test for the ExplicitLayout property. +[] +type MySystemTime = + [] val public wYear: uint16 + [] val public wMonth: uint16 + [] val public wDayOfWeek: uint16 + [] val public wDay: uint16 + [] val public wHour: uint16 + [] val public wMinute: uint16 + [] val public wSecond: uint16 + [] val public wMilliseconds: uint16 + +// Create an instance of the type using the GetType method. +let t = typeof +// Get and display the IsExplicitLayout property. +printfn $"\nIsExplicitLayout for MySystemTime is {t.IsExplicitLayout}." +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsGenericParameter/fs.fsproj b/snippets/fsharp/System/Type/IsGenericParameter/fs.fsproj new file mode 100644 index 00000000000..f0a89cd967d --- /dev/null +++ b/snippets/fsharp/System/Type/IsGenericParameter/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsGenericParameter/source.fs b/snippets/fsharp/System/Type/IsGenericParameter/source.fs new file mode 100644 index 00000000000..dc8e4f86200 --- /dev/null +++ b/snippets/fsharp/System/Type/IsGenericParameter/source.fs @@ -0,0 +1,65 @@ +// +open System +open System.Collections.Generic + +type Test() = class end + +let displayGenericTypeInfo (t: Type) = + printfn $"\n{t}" + printfn $"\tIs this a generic type definition? {t.IsGenericTypeDefinition}" + printfn $"\tIs it a generic type? {t.IsGenericType}" + + // + if t.IsGenericType then + // If this is a generic type, display the type arguments. + let typeArguments = t.GetGenericArguments() + + printfn $"\tList type arguments ({typeArguments.Length}):" + + for tParam in typeArguments do + // If this is a type parameter, display its + // position. + if tParam.IsGenericParameter then + printfn $"\t\t{tParam}\t(unassigned - parameter position {tParam.GenericParameterPosition})" + else + printfn $"\t\t{tParam}" + // + +printfn "\r\n--- Display information about a constructed type, its" +printfn " generic type definition, and an ordinary type." + +// Create a Dictionary of Test objects, using strings for the keys. +let d = Dictionary() + +// Display information for the constructed type and its generic +// type definition. +displayGenericTypeInfo (d.GetType()) +displayGenericTypeInfo (d.GetType().GetGenericTypeDefinition()) + +// Display information for an ordinary type. +displayGenericTypeInfo typeof + +(* This example produces the following output: + +--- Display information about a constructed type, its + generic type definition, and an ordinary type. + +System.Collections.Generic.Dictionary[System.String,Test] + Is this a generic type definition? False + Is it a generic type? True + List type arguments (2): + System.String + Test + +System.Collections.Generic.Dictionary[TKey,TValue] + Is this a generic type definition? True + Is it a generic type? True + List type arguments (2): + TKey (unassigned - parameter position 0) + TValue (unassigned - parameter position 1) + +System.String + Is this a generic type definition? False + Is it a generic type? False + *) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsGenericType/fs.fsproj b/snippets/fsharp/System/Type/IsGenericType/fs.fsproj new file mode 100644 index 00000000000..513e36482ac --- /dev/null +++ b/snippets/fsharp/System/Type/IsGenericType/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net6.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsGenericType/remarks.fs b/snippets/fsharp/System/Type/IsGenericType/remarks.fs new file mode 100644 index 00000000000..ab3c8d5172d --- /dev/null +++ b/snippets/fsharp/System/Type/IsGenericType/remarks.fs @@ -0,0 +1,13 @@ +module remarks + +// +type Base<'T, 'U>() = class end + +type G<'T>() = class end + +type Derived<'V>() = + inherit Base() + + [] + val mutable public F : G> +// diff --git a/snippets/fsharp/System/Type/IsGenericType/source.fs b/snippets/fsharp/System/Type/IsGenericType/source.fs new file mode 100644 index 00000000000..02bfea012d9 --- /dev/null +++ b/snippets/fsharp/System/Type/IsGenericType/source.fs @@ -0,0 +1,83 @@ +// +open System + +type Base<'T, 'U>() = class end + +type G<'T>() = class end + +type Derived<'V>() = + inherit Base() + + [] + val mutable public F : G> + +let displayGenericType (t: Type) caption = + printfn $"\n{caption}" + printfn $" Type: {t}" + + printfn $"\t IsGenericType: {t.IsGenericType}" + printfn $"\t IsGenericTypeDefinition: {t.IsGenericTypeDefinition}" + printfn $"\tContainsGenericParameters: {t.ContainsGenericParameters}" + printfn $"\t IsGenericParameter: {t.IsGenericParameter}" + +// Get the generic type definition for Derived, and the base +// type for Derived. +let tDerived = typeof>.GetGenericTypeDefinition() +let tDerivedBase = tDerived.BaseType + +// Declare an array of Derived, and get its type. +let d = Array.zeroCreate> 0 +let tDerivedArray = d.GetType() + +// Get a generic type parameter, the type of a field, and a +// type that is nested in Derived. Notice that in order to +// get the nested type it is necessary to either (1) specify +// the generic type definition Derived<>, as shown here, +// or (2) specify a type parameter for Derived. +let tT = typeof>.GetGenericTypeDefinition().GetGenericArguments()[0] +let tF = tDerived.GetField("F").FieldType + +displayGenericType tDerived "Derived" +displayGenericType tDerivedBase "Base type of Derived" +displayGenericType tDerivedArray "Array of Derived" +displayGenericType tT "Type parameter T from Base" +displayGenericType tF "Field type, G>" + +(* This code example produces the following output: + +Derived + Type: Derived`1[V] + IsGenericType: True + IsGenericTypeDefinition: True + ContainsGenericParameters: True + IsGenericParameter: False + +Base type of Derived + Type: Base`2[System.String,V] + IsGenericType: True + IsGenericTypeDefinition: False + ContainsGenericParameters: True + IsGenericParameter: False + +Array of Derived + Type: Derived`1[System.Int32][] + IsGenericType: False + IsGenericTypeDefinition: False + ContainsGenericParameters: False + IsGenericParameter: False + +Type parameter T from Base + Type: T + IsGenericType: False + IsGenericTypeDefinition: False + ContainsGenericParameters: True + IsGenericParameter: True + +Field type, G> + Type: G`1[Derived`1[V]] + IsGenericType: True + IsGenericTypeDefinition: False + ContainsGenericParameters: True + IsGenericParameter: False + *) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsInstanceOfType/fs.fsproj b/snippets/fsharp/System/Type/IsInstanceOfType/fs.fsproj new file mode 100644 index 00000000000..b1a491cad17 --- /dev/null +++ b/snippets/fsharp/System/Type/IsInstanceOfType/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsInstanceOfType/testisinstanceoftype.fs b/snippets/fsharp/System/Type/IsInstanceOfType/testisinstanceoftype.fs new file mode 100644 index 00000000000..7ee03099d0c --- /dev/null +++ b/snippets/fsharp/System/Type/IsInstanceOfType/testisinstanceoftype.fs @@ -0,0 +1,28 @@ +// +open System + +type IExample = interface end + +type BaseClass() = interface IExample + +type DerivedClass() = inherit BaseClass() + +let interfaceType = typeof +let base1 = BaseClass() +let base1Type = base1.GetType() +let derived1 = DerivedClass() +let derived1Type = derived1.GetType() +let arr = Array.zeroCreate 11 + +printfn $"Is int[] an instance of the Array class? {typeof.IsInstanceOfType arr}." +printfn $"Is base1 an instance of BaseClass? {base1Type.IsInstanceOfType base1}." +printfn $"Is derived1 an instance of BaseClass? {base1Type.IsInstanceOfType derived1}." +printfn $"Is base1 an instance of IExample? {interfaceType.IsInstanceOfType base1}." +printfn $"Is derived1 an instance of IExample? {interfaceType.IsInstanceOfType derived1}." +// The example displays the following output: +// Is int[] an instance of the Array class? True. +// Is base1 an instance of BaseClass? True. +// Is derived1 an instance of BaseClass? True. +// Is base1 an instance of IExample? True. +// Is derived1 an instance of IExample? True. +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsInterface/fs.fsproj b/snippets/fsharp/System/Type/IsInterface/fs.fsproj new file mode 100644 index 00000000000..59a44efa52a --- /dev/null +++ b/snippets/fsharp/System/Type/IsInterface/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsInterface/type_isinterface.fs b/snippets/fsharp/System/Type/IsInterface/type_isinterface.fs new file mode 100644 index 00000000000..f87e8d16553 --- /dev/null +++ b/snippets/fsharp/System/Type/IsInterface/type_isinterface.fs @@ -0,0 +1,23 @@ +// +// Declare an interface. +type myIFace = interface end + +type MyIsInterface = class end + +try + // Get the IsInterface attribute for myIFace. + let myBool1 = typeof.IsInterface + //Display the IsInterface attribute for myIFace. + printfn $"Is the specified type an interface? {myBool1}." + // Get the attribute IsInterface for MyIsInterface. + let myBool2 = typeof.IsInterface + //Display the IsInterface attribute for MyIsInterface. + printfn $"Is the specified type an interface? {myBool2}." +with e -> + printfn $"\nAn exception occurred: {e.Message}." +(* The example produces the following output: + +Is the specified type an interface? True. +Is the specified type an interface? False. +*) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsLayoutSequential/fs.fsproj b/snippets/fsharp/System/Type/IsLayoutSequential/fs.fsproj new file mode 100644 index 00000000000..0f59901e500 --- /dev/null +++ b/snippets/fsharp/System/Type/IsLayoutSequential/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsLayoutSequential/type_islayoutsequential.fs b/snippets/fsharp/System/Type/IsLayoutSequential/type_islayoutsequential.fs new file mode 100644 index 00000000000..8a878198bbe --- /dev/null +++ b/snippets/fsharp/System/Type/IsLayoutSequential/type_islayoutsequential.fs @@ -0,0 +1,22 @@ +// +open System.Runtime.InteropServices + +type MyTypeSequential1 = struct end + +[] +type MyTypeSequential2 = struct end + +try + // Create an instance of myTypeSeq1. + let myObj1 = MyTypeSequential1() + let myTypeObj1 = myObj1.GetType() + // Check for and display the SequentialLayout attribute. + printfn $"\nThe object myObj1 has IsLayoutSequential: {myTypeObj1.IsLayoutSequential}." + // Create an instance of 'myTypeSeq2' class. + let myObj2 = MyTypeSequential2() + let myTypeObj2 = myObj2.GetType() + // Check for and display the SequentialLayout attribute. + printfn $"\nThe object myObj2 has IsLayoutSequential: {myTypeObj2.IsLayoutSequential}." +with e -> + printfn $"\nAn exception occurred: {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsMarshalByRefImpl/fs.fsproj b/snippets/fsharp/System/Type/IsMarshalByRefImpl/fs.fsproj new file mode 100644 index 00000000000..fcd7eabacc3 --- /dev/null +++ b/snippets/fsharp/System/Type/IsMarshalByRefImpl/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsMarshalByRefImpl/type_ismarshalbyrefimpl.fs b/snippets/fsharp/System/Type/IsMarshalByRefImpl/type_ismarshalbyrefimpl.fs new file mode 100644 index 00000000000..e69e4513faf --- /dev/null +++ b/snippets/fsharp/System/Type/IsMarshalByRefImpl/type_ismarshalbyrefimpl.fs @@ -0,0 +1,42 @@ +// +open System +open System.Reflection + +// This class is used to demonstrate the IsMarshalByRefImpl method. +type MyContextBoundClass() = + inherit ContextBoundObject() + let myString = "This class is used to demonstrate members of the Type class." + +type MyTypeDelegatorClass(myType) = + inherit TypeDelegator(myType) + [] + val mutable public myElementType : string + + // Override IsMarshalByRefImpl. + override this.IsMarshalByRefImpl() = + // Determine whether the type is marshalled by reference. + if myType.IsMarshalByRef then + this.myElementType <- " marshalled by reference" + true + else false + +try + printfn "Determine whether MyContextBoundClass is marshalled by reference." + // Determine whether MyContextBoundClass type is marshalled by reference. + let myType = MyTypeDelegatorClass typeof + if myType.IsMarshalByRef then + printfn $"{typeof} is marshalled by reference." + else + printfn $"{typeof} is not marshalled by reference." + + // Determine whether int type is marshalled by reference. + let myType = MyTypeDelegatorClass typeof + printfn "\nDetermine whether int is marshalled by reference." + if myType.IsMarshalByRef then + printfn $"{typeof} is marshalled by reference." + else + printfn $"{typeof} is not marshalled by reference." +with e -> + printfn $"Exception: {e.Message}" + +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsNotPublic/fs.fsproj b/snippets/fsharp/System/Type/IsNotPublic/fs.fsproj new file mode 100644 index 00000000000..f0a89cd967d --- /dev/null +++ b/snippets/fsharp/System/Type/IsNotPublic/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsNotPublic/source.fs b/snippets/fsharp/System/Type/IsNotPublic/source.fs new file mode 100644 index 00000000000..f8dc50bc711 --- /dev/null +++ b/snippets/fsharp/System/Type/IsNotPublic/source.fs @@ -0,0 +1,19 @@ +// +open System + +// Get the Type and MemberInfo. +let t = Type.GetType "System.IO.File" +let members = t.GetMembers() +// Get and display the DeclaringType method. +printfn $"\nThere are {members.Length} members in {t.FullName}." +printfn $"Is {t.FullName} non-public? {t.IsNotPublic}" +// The example displays output like the following: +// There are 60 members in System.IO.File. +// Is System.IO.File non-public? False +// + +// +module A = + type B() = class end + type C() = class end +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsPrimitiveImpl/fs.fsproj b/snippets/fsharp/System/Type/IsPrimitiveImpl/fs.fsproj new file mode 100644 index 00000000000..ca7471e4d05 --- /dev/null +++ b/snippets/fsharp/System/Type/IsPrimitiveImpl/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsPrimitiveImpl/type_isprimitiveimpl.fs b/snippets/fsharp/System/Type/IsPrimitiveImpl/type_isprimitiveimpl.fs new file mode 100644 index 00000000000..0d0cd428cb6 --- /dev/null +++ b/snippets/fsharp/System/Type/IsPrimitiveImpl/type_isprimitiveimpl.fs @@ -0,0 +1,34 @@ +// +open System.Reflection + +type MyTypeDelegatorClass(myType) = + inherit TypeDelegator(myType) + [] + val mutable public myElementType : string + // Override the IsPrimitiveImpl. + override this.IsPrimitiveImpl() = + // Determine whether the type is a primitive type. + if myType.IsPrimitive then + this.myElementType <- "primitive" + true + else + false + +try + printfn "Determine whether int is a primitive type." + let myType = MyTypeDelegatorClass typeof + // Determine whether int is a primitive type. + if myType.IsPrimitive then + printfn $"{typeof} is a primitive type." + else + printfn $"{typeof} is not a primitive type." + printfn "\nDetermine whether string is a primitive type." + let myType = MyTypeDelegatorClass typeof + // Determine if string is a primitive type. + if myType.IsPrimitive then + printfn $"{typeof} is a primitive type." + else + printfn $"{typeof} is not a primitive type." +with e -> + printfn $"Exception: {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsPublic/fs.fsproj b/snippets/fsharp/System/Type/IsPublic/fs.fsproj new file mode 100644 index 00000000000..2e0eb869ef2 --- /dev/null +++ b/snippets/fsharp/System/Type/IsPublic/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsPublic/type_ispublic.fs b/snippets/fsharp/System/Type/IsPublic/type_ispublic.fs new file mode 100644 index 00000000000..ba86ca0ebec --- /dev/null +++ b/snippets/fsharp/System/Type/IsPublic/type_ispublic.fs @@ -0,0 +1,12 @@ +// +type TestClass() = class end + +let testClassInstance = TestClass() +// Get the type of myTestClassInstance. +let testType = testClassInstance.GetType() +// Get the IsPublic property of testClassInstance. +let isPublic = testType.IsPublic +printfn $"Is {testType.FullName} public? {isPublic}" +// The example displays the following output: +// Is TestClass public? True +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsSealed/fs.fsproj b/snippets/fsharp/System/Type/IsSealed/fs.fsproj new file mode 100644 index 00000000000..63da9078a41 --- /dev/null +++ b/snippets/fsharp/System/Type/IsSealed/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsSealed/type_issealed.fs b/snippets/fsharp/System/Type/IsSealed/type_issealed.fs new file mode 100644 index 00000000000..6e0dd427aa4 --- /dev/null +++ b/snippets/fsharp/System/Type/IsSealed/type_issealed.fs @@ -0,0 +1,15 @@ +// +module Example +// Declare InnerClass as sealed. +[] +type InnerClass() = class end + +let inner = InnerClass() +// Get the type of InnerClass. +let innerType = inner.GetType() +// Get the IsSealed property of innerClass. +let isSealed = innerType.IsSealed +printfn $"{innerType.FullName} is sealed: {isSealed}." +// The example displays the following output: +// Example+InnerClass is sealed: True. +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsSerializable/fs.fsproj b/snippets/fsharp/System/Type/IsSerializable/fs.fsproj new file mode 100644 index 00000000000..8e8864290ba --- /dev/null +++ b/snippets/fsharp/System/Type/IsSerializable/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsSerializable/type_isserializable.fs b/snippets/fsharp/System/Type/IsSerializable/type_isserializable.fs new file mode 100644 index 00000000000..d3390e6c268 --- /dev/null +++ b/snippets/fsharp/System/Type/IsSerializable/type_isserializable.fs @@ -0,0 +1,17 @@ +// +open System + +// Declare a public class with the [Serializable] attribute. +[] +type MyTestClass() = class end + +try + let myTestClassInstance = MyTestClass() + // Get the type of myTestClassInstance. + let myType = myTestClassInstance.GetType() + // Get the IsSerializable property of myTestClassInstance. + let myBool = myType.IsSerializable + printfn $"\nIs {myType.FullName} serializable? {myBool}." +with e -> + printfn $"\nAn exception occurred: {e.Message}" +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsSubclassOf/fs.fsproj b/snippets/fsharp/System/Type/IsSubclassOf/fs.fsproj new file mode 100644 index 00000000000..d6bc14de529 --- /dev/null +++ b/snippets/fsharp/System/Type/IsSubclassOf/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net6.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsSubclassOf/issubclassof_interface1.fs b/snippets/fsharp/System/Type/IsSubclassOf/issubclassof_interface1.fs new file mode 100644 index 00000000000..6a332d9c85a --- /dev/null +++ b/snippets/fsharp/System/Type/IsSubclassOf/issubclassof_interface1.fs @@ -0,0 +1,16 @@ +module issubclassof_interface1 + +// +type IInterface = + abstract Display : unit -> unit + +type Implementation() = + interface IInterface with + member _.Display() = printfn "The implementation..." + +printfn $"Implementation is a subclass of IInterface: {typeof.IsSubclassOf typeof}" +printfn $"IInterface is assignable from Implementation: {typeof.IsAssignableFrom typeof}" +// The example displays the following output: +// Implementation is a subclass of IInterface: False +// IInterface is assignable from Implementation: True +// diff --git a/snippets/fsharp/System/Type/IsSubclassOf/testissubclassof.fs b/snippets/fsharp/System/Type/IsSubclassOf/testissubclassof.fs new file mode 100644 index 00000000000..0021d0dab3f --- /dev/null +++ b/snippets/fsharp/System/Type/IsSubclassOf/testissubclassof.fs @@ -0,0 +1,11 @@ +module testissubclassof + +// +type Class1() = class end +type DerivedC1() = inherit Class1() + +printfn $"DerivedC1 subclass of Class1: {typeof.IsSubclassOf typeof}" + +// The example displays the following output: +// DerivedC1 subclass of Class1: True +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsValueType/fs.fsproj b/snippets/fsharp/System/Type/IsValueType/fs.fsproj new file mode 100644 index 00000000000..340d77cdf42 --- /dev/null +++ b/snippets/fsharp/System/Type/IsValueType/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsValueType/type_isvaluetype.fs b/snippets/fsharp/System/Type/IsValueType/type_isvaluetype.fs new file mode 100644 index 00000000000..2e6f9e2b29d --- /dev/null +++ b/snippets/fsharp/System/Type/IsValueType/type_isvaluetype.fs @@ -0,0 +1,13 @@ +// +// Declare an enum type. +type NumEnum = One = 1 | Two = 2 + +let testEnum = NumEnum.One +// Get the type of testEnum. +let t = testEnum.GetType() +// Get the IsValueType property of the testEnum variable. +let flag = t.IsValueType +printfn $"{t.FullName} is a value type: {flag}" +// The example displays the following output: +// NumEnum is a value type: True +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsVisible/fs.fsproj b/snippets/fsharp/System/Type/IsVisible/fs.fsproj new file mode 100644 index 00000000000..f0a89cd967d --- /dev/null +++ b/snippets/fsharp/System/Type/IsVisible/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/IsVisible/source.fs b/snippets/fsharp/System/Type/IsVisible/source.fs new file mode 100644 index 00000000000..641e6391bfc --- /dev/null +++ b/snippets/fsharp/System/Type/IsVisible/source.fs @@ -0,0 +1,19 @@ +// +module internal InternalOnly = + type Nested() = class end + +module Example = + type Nested() = class end + +let t = typeof +printfn $"Is the {t.FullName} class visible outside the assembly? {t.IsVisible}" + +let t2 = typeof +printfn $"Is the {t2.FullName} class visible outside the assembly? {t2.IsVisible}" + +(* This example produces the following output: + +Is the InternalOnly+Nested class visible outside the assembly? False +Is the Example+Nested class visible outside the assembly? True + *) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/MakeByRefType/fs.fsproj b/snippets/fsharp/System/Type/MakeByRefType/fs.fsproj new file mode 100644 index 00000000000..f0a89cd967d --- /dev/null +++ b/snippets/fsharp/System/Type/MakeByRefType/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/MakeByRefType/source.fs b/snippets/fsharp/System/Type/MakeByRefType/source.fs new file mode 100644 index 00000000000..fe0c86b04b7 --- /dev/null +++ b/snippets/fsharp/System/Type/MakeByRefType/source.fs @@ -0,0 +1,62 @@ +// +type Example() = + // A sample method with a ByRef parameter. + member _.Test(e: Example byref) = () + +do + // Create a Type object that represents a one-dimensional + // array of Example objects. + let t = typeof.MakeArrayType() + printfn $"\r\nArray of Example: {t}" + + // Create a Type object that represents a two-dimensional + // array of Example objects. + let t = typeof.MakeArrayType 2 + printfn $"\r\nTwo-dimensional array of Example: {t}" + + // Demonstrate an exception when an invalid array rank is + // specified. + try + let t = typeof.MakeArrayType -1 + () + with ex -> + printfn $"\r\n{ex}" + + // Create a Type object that represents a ByRef parameter + // of type Example. + let t = typeof.MakeByRefType() + printfn $"\r\nByRef Example: {t}" + + // Get a Type object representing the Example class, a + // MethodInfo representing the "Test" method, a ParameterInfo + // representing the parameter of type Example, and finally + // a Type object representing the type of this ByRef parameter. + // Compare this Type object with the Type object created using + // MakeByRefType. + let t2 = typeof + let mi = t2.GetMethod "Test" + let pi = mi.GetParameters()[0] + let pt = pi.ParameterType + printfn $"Are the ByRef types equal? {t = pt}" + + // Create a Type object that represents a pointer to an + // Example object. + let t = typeof.MakePointerType() + printfn $"\r\nPointer to Example: {t}" + +(* This example produces output similar to the following: + +Array of Example: Example[] + +Two-dimensional array of Example: Example[,] + +System.IndexOutOfRangeException: Index was outside the bounds of the array. + at System.RuntimeType.MakeArrayType(Int32 rank) in c:\vbl\ndp\clr\src\BCL\System\RtType.cs:line 2999 + at Example.Main() + +ByRef Example: Example& +Are the ByRef types equal? True + +Pointer to Example: Example* + *) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/MakeGenericType/fs.fsproj b/snippets/fsharp/System/Type/MakeGenericType/fs.fsproj new file mode 100644 index 00000000000..513e36482ac --- /dev/null +++ b/snippets/fsharp/System/Type/MakeGenericType/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net6.0 + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/MakeGenericType/remarks.fs b/snippets/fsharp/System/Type/MakeGenericType/remarks.fs new file mode 100644 index 00000000000..bece475149a --- /dev/null +++ b/snippets/fsharp/System/Type/MakeGenericType/remarks.fs @@ -0,0 +1,5 @@ +module remarks +// +type Base<'T, 'U>() = class end +type Derived<'V>() = inherit Base() +// diff --git a/snippets/fsharp/System/Type/MakeGenericType/source.fs b/snippets/fsharp/System/Type/MakeGenericType/source.fs new file mode 100644 index 00000000000..cf44110e3f7 --- /dev/null +++ b/snippets/fsharp/System/Type/MakeGenericType/source.fs @@ -0,0 +1,55 @@ +module source + +// +open System +open System.Collections.Generic + +type Test() = class end + +let displayTypeInfo (t: Type) = + printfn $"\r\n{t}" + + printfn $"\tIs this a generic type definition? {t.IsGenericTypeDefinition}" + + printfn $"\tIs it a generic type? {t.IsGenericType}" + + let typeArguments = t.GetGenericArguments() + printfn $"\tList type arguments ({typeArguments.Length}):" + for tParam in typeArguments do + printfn $"\t\t{tParam}" + +printfn "\r\n--- Create a constructed type from the generic Dictionary type." + +// Create a type object representing the generic Dictionary +// type, by calling .GetGenericTypeDefinition(). +let generic = typeof>.GetGenericTypeDefinition() +displayTypeInfo generic + +// Create an array of types to substitute for the type +// parameters of Dictionary. The key is of type string, and +// the type to be contained in the Dictionary is Test. +let typeArgs = [| typeof; typeof |] + +// Create a Type object representing the constructed generic type. +let constructed = generic.MakeGenericType typeArgs +displayTypeInfo constructed + +(* This example produces the following output: + +--- Create a constructed type from the generic Dictionary type. + +System.Collections.Generic.Dictionary`2[TKey,TValue] + Is this a generic type definition? True + Is it a generic type? True + List type arguments (2): + TKey + TValue + +System.Collections.Generic.Dictionary`2[System.String, Test] + Is this a generic type definition? False + Is it a generic type? True + List type arguments (2): + System.String + Test + *) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/MemberType/fs.fsproj b/snippets/fsharp/System/Type/MemberType/fs.fsproj new file mode 100644 index 00000000000..f0a89cd967d --- /dev/null +++ b/snippets/fsharp/System/Type/MemberType/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/MemberType/source.fs b/snippets/fsharp/System/Type/MemberType/source.fs new file mode 100644 index 00000000000..bf2de8d5247 --- /dev/null +++ b/snippets/fsharp/System/Type/MemberType/source.fs @@ -0,0 +1,8 @@ +open System +open System.Reflection + +let func (t: Type) (mi: MemberInfo) = + // + let others = t.GetMember(mi.Name, mi.MemberType, BindingFlags.Public ||| BindingFlags.Static ||| BindingFlags.NonPublic ||| BindingFlags.Instance) + // + () \ No newline at end of file diff --git a/snippets/fsharp/System/Type/Missing/fs.fsproj b/snippets/fsharp/System/Type/Missing/fs.fsproj new file mode 100644 index 00000000000..f0961f2e150 --- /dev/null +++ b/snippets/fsharp/System/Type/Missing/fs.fsproj @@ -0,0 +1,14 @@ + + + Exe + net6.0 + + + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/Missing/source.fs b/snippets/fsharp/System/Type/Missing/source.fs new file mode 100644 index 00000000000..1b7e4e60949 --- /dev/null +++ b/snippets/fsharp/System/Type/Missing/source.fs @@ -0,0 +1,43 @@ +// +open System +open System.Reflection +open System.CodeDom.Compiler + +let generateObjectFromSource objectName (sourceLines: string) providerName = + let codeProvider = CodeDomProvider.CreateProvider providerName + let cp = CompilerParameters() + + cp.GenerateExecutable <- false + cp.GenerateInMemory <- true + + let results = codeProvider.CompileAssemblyFromSource(cp, sourceLines) + if results.Errors.Count = 0 then + results.CompiledAssembly.CreateInstance objectName + else + null + + +// VB source for example. Not all versions of CS and CPP compilers +// support optional arguments. +let codeLines = + """Imports System +Public Class OptionalArg + Public Sub MyMethod(ByVal a As Integer, _ + Optional ByVal b As Double = 1.2, _ + Optional ByVal c As Integer = 1) + + Console.WriteLine(\"a = \" & a & \" b = \" & b & \" c = \" & c) + End Sub +End Class""" + +// Generate a OptionalArg instance from the source above. +let o = generateObjectFromSource "OptionalArg" codeLines "VisualBasic" + +let t = o.GetType() +let bf = BindingFlags.Public ||| BindingFlags.Instance ||| BindingFlags.InvokeMethod ||| BindingFlags.OptionalParamBinding + +t.InvokeMember("MyMethod", bf, null, o, [| 10; 55.3; 12 |]) |> ignore +t.InvokeMember("MyMethod", bf, null, o, [| 10; 1.3; Type.Missing |]) |> ignore +t.InvokeMember("MyMethod", bf, null, o, [| 10; Type.Missing; Type.Missing |]) |> ignore + +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/Module/fs.fsproj b/snippets/fsharp/System/Type/Module/fs.fsproj new file mode 100644 index 00000000000..1704a3dcef6 --- /dev/null +++ b/snippets/fsharp/System/Type/Module/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/Module/type_tostring.fs b/snippets/fsharp/System/Type/Module/type_tostring.fs new file mode 100644 index 00000000000..b04f51b39af --- /dev/null +++ b/snippets/fsharp/System/Type/Module/type_tostring.fs @@ -0,0 +1,22 @@ +// +namespace MyNamespace + +type MyClass() = class end + +namespace global + +module Example = + let myType = typeof + printfn $"Displaying information about {myType}:" + // Get the namespace of the myClass class. + printfn $" Namespace: {myType.Namespace}." + // Get the name of the ilmodule. + printfn $" Module: {myType.Module}." + // Get the fully qualified type name. + printfn $" Fully qualified name: {myType.ToString()}." +// The example displays the following output: +// Displaying information about MyNamespace.MyClass: +// Namespace: MyNamespace. +// Module: type_tostring.exe. +// Fully qualified name: MyNamespace.MyClass. +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/Overview/Equals1.fs b/snippets/fsharp/System/Type/Overview/Equals1.fs new file mode 100644 index 00000000000..5c02f7f9dc4 --- /dev/null +++ b/snippets/fsharp/System/Type/Overview/Equals1.fs @@ -0,0 +1,23 @@ +module Equals1 + +open System + +// +let number1 = 1635429L +let number2 = 16203 +let number3 = 1639.41 +let number4 = 193685412L + +// Get the type of number1. +let t = number1.GetType() + +// Compare types of all objects with number1. +printfn $"Type of number1 and number2 are equal: {Object.ReferenceEquals(t, number2.GetType())}" +printfn $"Type of number1 and number3 are equal: {Object.ReferenceEquals(t, number3.GetType())}" +printfn $"Type of number1 and number4 are equal: {Object.ReferenceEquals(t, number4.GetType())}" + +// The example displays the following output: +// Type of number1 and number2 are equal: False +// Type of number1 and number3 are equal: False +// Type of number1 and number4 are equal: True +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/Overview/GetType1.fs b/snippets/fsharp/System/Type/Overview/GetType1.fs new file mode 100644 index 00000000000..c0ef02ad562 --- /dev/null +++ b/snippets/fsharp/System/Type/Overview/GetType1.fs @@ -0,0 +1,13 @@ +module GetType1 +// +let values: obj[] = [| "word"; true; 120; 136.34; 'a' |] +for value in values do + printfn $"{value} - type {value.GetType().Name}" + +// The example displays the following output: +// word - type String +// True - type Boolean +// 120 - type Int32 +// 136.34 - type Double +// a - type Char +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/Overview/fs.fsproj b/snippets/fsharp/System/Type/Overview/fs.fsproj new file mode 100644 index 00000000000..c7df72680ee --- /dev/null +++ b/snippets/fsharp/System/Type/Overview/fs.fsproj @@ -0,0 +1,12 @@ + + + Exe + net6.0 + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/Overview/source.fs b/snippets/fsharp/System/Type/Overview/source.fs new file mode 100644 index 00000000000..ccd1ecf752a --- /dev/null +++ b/snippets/fsharp/System/Type/Overview/source.fs @@ -0,0 +1,20 @@ +module source + +// The following code example demonstrates that Type objects are returned +// by the typeid operator, and shows how Type objects are used in reflection +// to explore information about types and to invoke members of types. +// +open System + +let t = typeof + +let substr = t.GetMethod("Substring", [| typeof; typeof |]) + +let result = substr.Invoke("Hello, World!", [| 7; 5 |]) +printfn $"{substr} returned \"{result}\"." + +(* This code example produces the following output: + +System.String Substring(Int32, Int32) returned "World". + *) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/ReflectedType/fs.fsproj b/snippets/fsharp/System/Type/ReflectedType/fs.fsproj new file mode 100644 index 00000000000..f0a89cd967d --- /dev/null +++ b/snippets/fsharp/System/Type/ReflectedType/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/ReflectedType/source.fs b/snippets/fsharp/System/Type/ReflectedType/source.fs new file mode 100644 index 00000000000..15648ac06f0 --- /dev/null +++ b/snippets/fsharp/System/Type/ReflectedType/source.fs @@ -0,0 +1,8 @@ +namespace global + +// +module MyModule = + type [] MyClass() = class end + + printfn $"Reflected type of MyClass is {typeof.ReflectedType}" // Outputs MyModule, the enclosing module. +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/StructLayoutAttribute/fs.fsproj b/snippets/fsharp/System/Type/StructLayoutAttribute/fs.fsproj new file mode 100644 index 00000000000..f0a89cd967d --- /dev/null +++ b/snippets/fsharp/System/Type/StructLayoutAttribute/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/StructLayoutAttribute/source.fs b/snippets/fsharp/System/Type/StructLayoutAttribute/source.fs new file mode 100644 index 00000000000..244b83c06aa --- /dev/null +++ b/snippets/fsharp/System/Type/StructLayoutAttribute/source.fs @@ -0,0 +1,23 @@ +// +open System.Runtime.InteropServices + +type Example = class end + +[] +type Test1 = + val B1 : byte + val S : int16 + val B2 : byte + +[] +type Test2 = + [] val B1 : byte + [] val S : int16 + [] val B2 : byte + +let displayLayoutAttribute (sla: StructLayoutAttribute) = + printfn $"\nCharSet: {sla}\n Pack: {sla.Pack}\n Size: {sla.Size}\n Value: {sla.Value}" +displayLayoutAttribute typeof.StructLayoutAttribute +displayLayoutAttribute typeof.StructLayoutAttribute +displayLayoutAttribute typeof.StructLayoutAttribute +// \ No newline at end of file diff --git a/snippets/fsharp/System/Type/TypeHandle/fs.fsproj b/snippets/fsharp/System/Type/TypeHandle/fs.fsproj new file mode 100644 index 00000000000..62ed83c8dea --- /dev/null +++ b/snippets/fsharp/System/Type/TypeHandle/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Type/TypeHandle/type_typehandle.fs b/snippets/fsharp/System/Type/TypeHandle/type_typehandle.fs new file mode 100644 index 00000000000..60e5667f155 --- /dev/null +++ b/snippets/fsharp/System/Type/TypeHandle/type_typehandle.fs @@ -0,0 +1,23 @@ +// +open System + +type MyClass() = + let myField = 10 + +let displayTypeHandle (myTypeHandle: RuntimeTypeHandle) = + // Get the type from the handle. + let myType = Type.GetTypeFromHandle myTypeHandle + // Display the type. + printfn $"\nDisplaying the type from the handle:\n" + printfn $"The type is {myType}." + +let myClass = MyClass() + +// Get the type of MyClass. +let myClassType = myClass.GetType() + +// Get the runtime handle of MyClass. +let myClassHandle = myClassType.TypeHandle + +displayTypeHandle myClassHandle +// \ No newline at end of file diff --git a/xml/System/Type.xml b/xml/System/Type.xml index c6a078b5d47..aeeb16a2271 100644 --- a/xml/System/Type.xml +++ b/xml/System/Type.xml @@ -134,6 +134,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Type/cpp/GetType1.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Type/Overview/GetType1.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/Overview/GetType1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Type/vb/GetType1.vb" id="Snippet2"::: - The static methods return a object that represents a type specified by its fully qualified name. @@ -158,7 +159,7 @@ - The method returns a object representing a constructed generic type, which is an open constructed type if its property returns `true`, and a closed constructed type otherwise. A generic type can be instantiated only if it is closed. -- The , , and methods return objects that represent, respectively, an array of a specified type, a pointer to a specified type, and the type of a reference parameter (`ref` in C#, `ByRef` in Visual Basic). +- The , , and methods return objects that represent, respectively, an array of a specified type, a pointer to a specified type, and the type of a reference parameter (`ref` in C#, 'byref' in F#, `ByRef` in Visual Basic). ## Comparing type objects for equality @@ -166,6 +167,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Type/cpp/Equals1.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/Type/Overview/Equals1.cs" interactive="try-dotnet-method" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/Overview/Equals1.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Type/vb/Equals1.vb" id="Snippet3"::: @@ -182,6 +184,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Type/cpp/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/Overview/source.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/Overview/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Type/vb/source.vb" id="Snippet1"::: ]]> @@ -366,6 +369,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_Assembly/CPP/type_assembly.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/Assembly/type_assembly.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/Assembly/type_assembly.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_Assembly/VB/type_assembly.vb" id="Snippet1"::: ]]> @@ -465,11 +469,13 @@ TopNamespace.Sub\+Namespace.ContainingClass+NestedClass, MyAssembly, Version=1.3 :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_Assembly/CPP/type_assembly.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/Assembly/type_assembly.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/Assembly/type_assembly.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_Assembly/VB/type_assembly.vb" id="Snippet1"::: The following example compares the strings returned by the method and the , , and `AssemblyQualifiedName` properties. :::code language="csharp" source="~/snippets/csharp/System/Type/AssemblyQualifiedName/fullname1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/AssemblyQualifiedName/fullname1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.tostring/vb/fullname1.vb" id="Snippet1"::: ]]> @@ -598,6 +604,7 @@ TopNamespace.Sub\+Namespace.ContainingClass+NestedClass, MyAssembly, Version=1.3 :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.type.basetype/cpp/remarks.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/BaseType/remarks.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/BaseType/remarks.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.basetype/vb/remarks.vb" id="Snippet1"::: For the constructed type `C` (`C(Of Integer)` in Visual Basic), the property returns `B`. @@ -613,11 +620,13 @@ TopNamespace.Sub\+Namespace.ContainingClass+NestedClass, MyAssembly, Version=1.3 :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/TestBaseType/CPP/testbasetype.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/BaseType/testbasetype.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/BaseType/testbasetype.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/TestBaseType/VB/testbasetype.vb" id="Snippet1"::: The following example uses recursion to list the complete inheritance hierarchy of each class found in an assembly. The example defines a class named `C` that derives from a class named `B`, which, in turn, derives from a class named `A`. :::code language="csharp" source="~/snippets/csharp/System/Type/BaseType/basetype3.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/BaseType/basetype3.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.basetype/vb/basetype3.vb" id="Snippet2"::: ]]> @@ -684,6 +693,7 @@ TopNamespace.Sub\+Namespace.ContainingClass+NestedClass, MyAssembly, Version=1.3 :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Type.HasUnboundGenericParameters/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/ContainsGenericParameters/source.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/ContainsGenericParameters/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Type.HasUnboundGenericParameters/VB/source.vb" id="Snippet1"::: ]]> @@ -758,6 +768,7 @@ TopNamespace.Sub\+Namespace.ContainingClass+NestedClass, MyAssembly, Version=1.3 :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/MethodInfo.Generics/cpp/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/DeclaringMethod/source.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/DeclaringMethod/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/MethodInfo.Generics/VB/source.vb" id="Snippet1"::: ]]> @@ -823,6 +834,7 @@ TopNamespace.Sub\+Namespace.ContainingClass+NestedClass, MyAssembly, Version=1.3 :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.type.declaringtype/cpp/remarks.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/DeclaringType/remarks.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/DeclaringType/remarks.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.declaringtype/vb/remarks.vb" id="Snippet1"::: If the current represents a type parameter in the definition of a generic type or generic method, the and properties identify the generic type definition or generic method definition where the generic type parameter was originally defined: @@ -840,6 +852,7 @@ TopNamespace.Sub\+Namespace.ContainingClass+NestedClass, MyAssembly, Version=1.3 :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.DeclaringType Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/DeclaringType/source.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/DeclaringType/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic Type.DeclaringType Example/VB/source.vb" id="Snippet1"::: ]]> @@ -924,6 +937,7 @@ TopNamespace.Sub\+Namespace.ContainingClass+NestedClass, MyAssembly, Version=1.3 :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_DefaultBinder/CPP/type_defaultbinder.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/DefaultBinder/type_defaultbinder.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/DefaultBinder/type_defaultbinder.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_DefaultBinder/VB/type_defaultbinder.vb" id="Snippet1"::: ]]> @@ -1013,6 +1027,7 @@ TopNamespace.Sub\+Namespace.ContainingClass+NestedClass, MyAssembly, Version=1.3 :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.EmptyTypes Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/EmptyTypes/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/EmptyTypes/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic Type.EmptyTypes Example/VB/source.vb" id="Snippet1"::: ]]> @@ -1096,6 +1111,7 @@ TopNamespace.Sub\+Namespace.ContainingClass+NestedClass, MyAssembly, Version=1.3 The following example uses to compare various object instances with various instances. :::code language="csharp" source="~/snippets/csharp/System/Type/Equals/EqualsEx1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/Equals/EqualsEx1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Type.Equals/vb/EqualsEx1.vb" id="Snippet1"::: Two things are particularly worth noting about the example: @@ -1174,6 +1190,7 @@ TopNamespace.Sub\+Namespace.ContainingClass+NestedClass, MyAssembly, Version=1.3 The following example uses `Equals` to compare two types. :::code language="csharp" source="~/snippets/csharp/System/Type/Equals/source.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/Equals/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic Type.Equals1 Example/VB/source.vb" id="Snippet1"::: ]]> @@ -1230,6 +1247,7 @@ TopNamespace.Sub\+Namespace.ContainingClass+NestedClass, MyAssembly, Version=1.3 :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_FilterAttribute/CPP/type_filterattribute.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/FilterAttribute/type_filterattribute.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/FilterAttribute/type_filterattribute.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_FilterAttribute/VB/type_filterattribute.vb" id="Snippet1"::: ]]> @@ -1287,6 +1305,7 @@ TopNamespace.Sub\+Namespace.ContainingClass+NestedClass, MyAssembly, Version=1.3 :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.FilterName Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/FilterName/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/FilterName/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic Type.FilterName Example/VB/source.vb" id="Snippet1"::: ]]> @@ -1344,6 +1363,7 @@ TopNamespace.Sub\+Namespace.ContainingClass+NestedClass, MyAssembly, Version=1.3 :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_FilterNameIgnoreCase/CPP/type_filternameignorecase.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/FilterNameIgnoreCase/type_filternameignorecase.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/FilterNameIgnoreCase/type_filternameignorecase.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_FilterNameIgnoreCase/VB/type_filternameignorecase.vb" id="Snippet1"::: ]]> @@ -1427,6 +1447,7 @@ TopNamespace.Sub\+Namespace.ContainingClass+NestedClass, MyAssembly, Version=1.3 :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_FindInterfaces/CPP/type_findinterfaces.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/FindInterfaces/type_findinterfaces.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/FindInterfaces/type_findinterfaces.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_FindInterfaces/VB/type_findinterfaces.vb" id="Snippet1"::: ]]> @@ -1549,6 +1570,7 @@ The `filter` argument can be a custom delegate of type @@ -1615,6 +1637,7 @@ The `filter` argument can be a custom delegate of type property are qualified by their full assembly name, even though the string representation of the generic type itself is not qualified by its full assembly name. The following example illustrates the difference in the FullName property for a type that represents generic type definition and one that represents a closed generic type. :::code language="csharp" source="~/snippets/csharp/System/Type/FullName/fullnameex1.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/FullName/fullnameex1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.fullname/vb/fullnameex1.vb" id="Snippet2"::: This property returns `null` if: @@ -1624,6 +1647,7 @@ The `filter` argument can be a custom delegate of type type and attempts to display its property. :::code language="csharp" source="~/snippets/csharp/System/Type/FullName/Fullname3.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/FullName/Fullname3.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.fullname/vb/Fullname3.vb" id="Snippet3"::: - The current object represents an array type, a pointer type, or a `byref` type that is based on a generic type parameter. @@ -1631,6 +1655,7 @@ The `filter` argument can be a custom delegate of type `, with three methods: `Display(T[])`, which is passed an array of type T; `HandleT(T)`, which is passed a T object; and `ChangeValue(ref T)`, which is passed a T object by reference. Because C# and Visual Basic do not allow us to define T as a pointer in the `HandleT` method, we have to call the method on the object that represents the method's parameter type to create a pointer to a generic type. The output from the example shows that in all three cases, the property is `null`. :::code language="csharp" source="~/snippets/csharp/System/Type/FullName/Fullname4.cs" interactive="try-dotnet" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/FullName/Fullname4.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.fullname/vb/FullName4.vb" id="Snippet4"::: - The current type contains generic type parameters that have not been replaced by specific types (that is, the property returns `true`), but the type is not a generic type definition (that is, the property returns `false` @@ -1638,6 +1663,7 @@ The `filter` argument can be a custom delegate of type ` inherits from `Base`. The property obtains the object that represents the base type of `Derived`, and its property returns `null`. :::code language="csharp" source="~/snippets/csharp/System/Type/FullName/Fullname5.cs" interactive="try-dotnet" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/FullName/Fullname5.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.fullname/vb/FullName5.vb" id="Snippet5"::: To get a that is not `null`, you can use the method to get the generic type definition, as the example illustrates. @@ -1651,11 +1677,13 @@ The `filter` argument can be a custom delegate of type method and the , `FullName`, and properties. :::code language="csharp" source="~/snippets/csharp/System/Type/AssemblyQualifiedName/fullname1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/AssemblyQualifiedName/fullname1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.tostring/vb/fullname1.vb" id="Snippet1"::: ]]> @@ -1716,6 +1744,7 @@ The `filter` argument can be a custom delegate of type @@ -1783,6 +1812,7 @@ The `filter` argument can be a custom delegate of type for `GetSomething`, and from that you can obtain the return type. When you examine the type parameters of the return type, returns 0 for both. The position of `V` is 0 because `V` is the first type parameter in the type parameter list for class `A`. The position of `X` is 0 because `X` is the first type parameter in the type parameter list for `GetSomething`. @@ -1797,6 +1827,7 @@ The `filter` argument can be a custom delegate of type @@ -1919,6 +1950,7 @@ The `filter` argument can be a custom delegate of type @@ -2058,6 +2090,7 @@ The `filter` argument can be a custom delegate of type @@ -2225,6 +2258,7 @@ The `filter` argument can be a custom delegate of type @@ -2377,6 +2411,7 @@ The `filter` argument can be a custom delegate of type @@ -2539,6 +2574,7 @@ This example shows the output of the overload :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.GetConstructors Example/CPP/source1.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetConstructors/source1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetConstructors/source1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic Type.GetConstructors Example/VB/source1.vb" id="Snippet1"::: The output of this code is: @@ -2555,6 +2591,7 @@ False :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.GetConstructors Example/CPP/source2.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetConstructors/source2.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetConstructors/source2.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic Type.GetConstructors Example/VB/source2.vb" id="Snippet2"::: Now the output is: @@ -2833,6 +2870,7 @@ If the current represents a generic type parameter, the @@ -2901,6 +2939,7 @@ If the current represents a generic type parameter, the @@ -3186,6 +3225,7 @@ If the current represents a generic type parameter, the @@ -3288,6 +3328,7 @@ If the current represents a generic type parameter, the @@ -3400,6 +3441,7 @@ If the current represents a generic type parameter, the @@ -3501,6 +3543,7 @@ If the current represents a generic type parameter, the @@ -3590,6 +3633,7 @@ If the current represents a generic type parameter, the @@ -3709,6 +3753,7 @@ If the current represents a generic type parameter, the @@ -3818,6 +3863,7 @@ If the current represents a generic type parameter, the @@ -3921,6 +3967,7 @@ The method does not return fields in a particula :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic MethodBase.Attributes Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetFields/source.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetFields/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic MethodBase.Attributes Example/VB/source.vb" id="Snippet1"::: ]]> @@ -3989,6 +4036,7 @@ The method does not return fields in a particula :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Type.IsGenericTypeDefinition/CPP/source.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsGenericParameter/source.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsGenericParameter/source.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Type.IsGenericTypeDefinition/VB/source.vb" id="Snippet2"::: ]]> @@ -4050,6 +4098,7 @@ The method does not return fields in a particula :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Type.GetGenericParameterConstraints/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GenericParameterAttributes/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GenericParameterAttributes/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Type.GetGenericParameterConstraints/VB/source.vb" id="Snippet1"::: ]]> @@ -4125,6 +4174,7 @@ The method does not return fields in a particula :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Type.GetGenericTypeDefinition/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetGenericTypeDefinition/source.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetGenericTypeDefinition/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Type.GetGenericTypeDefinition/VB/source.vb" id="Snippet1"::: ]]> @@ -4200,6 +4250,7 @@ The method does not return fields in a particula :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetHashCode_GetFields/CPP/type_gethashcode_getfields.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetHashCode/type_gethashcode_getfields.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetHashCode/type_gethashcode_getfields.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetHashCode_GetFields/VB/type_gethashcode_getfields.vb" id="Snippet1"::: ]]> @@ -4290,6 +4341,7 @@ The method does not return fields in a particula :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetInterface/CPP/type_getinterface.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetInterface/type_getinterface.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetInterface/type_getinterface.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetInterface/VB/type_getinterface.vb" id="Snippet1"::: ]]> @@ -4380,6 +4432,7 @@ The method does not return fields in a particula :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetInterface/CPP/type_getinterface.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetInterface/type_getinterface.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetInterface/type_getinterface.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetInterface/VB/type_getinterface.vb" id="Snippet2"::: ]]> @@ -4461,6 +4514,7 @@ The method does not return fields in a particula The following example calls the method to determine how the interface maps to methods, and how the interface maps to properties. Note that, because the interface defines a set of properties, the returned object includes separate objects for a property's get and set accessors. :::code language="csharp" source="~/snippets/csharp/System/Type/GetInterfaceMap/interfacemapping1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetInterfaceMap/interfacemapping1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.getinterfacemap/vb/interfacemapping1.vb" id="Snippet1"::: ]]> @@ -4555,6 +4609,7 @@ The current instance or argument is an open ge :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetInterfaces1/CPP/type_getinterfaces1.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetInterfaces/type_getinterfaces1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetInterfaces/type_getinterfaces1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetInterfaces1/VB/type_getinterfaces1.vb" id="Snippet1"::: ]]> @@ -4668,6 +4723,7 @@ The current instance or argument is an open ge :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetMember/CPP/type_getmember.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetMember/type_getmember.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetMember/type_getmember.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetMember/VB/type_getmember.vb" id="Snippet1"::: ]]> @@ -4785,6 +4841,7 @@ The current instance or argument is an open ge :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetMember/CPP/type_getmember.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetMember/type_getmember.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetMember/type_getmember.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetMember/VB/type_getmember.vb" id="Snippet2"::: ]]> @@ -4902,6 +4959,7 @@ The current instance or argument is an open ge :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetMember/CPP/type_getmember.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetMember/type_getmember.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetMember/type_getmember.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetMember/VB/type_getmember.vb" id="Snippet3"::: ]]> @@ -5021,6 +5079,7 @@ Members include properties, methods, constructors, fields, events, and nested ty :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetMembers1/CPP/type_getmembers1.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetMembers/type_getmembers1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetMembers/type_getmembers1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetMembers1/VB/type_getmembers1.vb" id="Snippet1"::: ]]> @@ -5134,6 +5193,7 @@ The method does not return members in a particu :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetMembers2/CPP/type_getmembers2.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetMembers/type_getmembers2.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetMembers/type_getmembers2.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetMembers2/VB/type_getmembers2.vb" id="Snippet1"::: ]]> @@ -5261,6 +5321,7 @@ This method can be used to find a constructed generic member given a member from If a method is overloaded and has more than one public method, the method throws an exception. In the following example, an exception is thrown because there is more than one public overload of the method. On the other hand, because the `Person.ToString` method overrides and therefore is not overloaded, the method is able to retrieve the object. :::code language="csharp" source="~/snippets/csharp/System/Type/GetMethod/GetMethodWithOverloads2.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetMethod/GetMethodWithOverloads2.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Type.GetMethod/vb/GetMethodWithOverloads2.vb" id="Snippet3"::: You can do one of the following to retrieve a specific method: @@ -5285,6 +5346,7 @@ This method can be used to find a constructed generic member given a member from :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetMethod1/CPP/type_getmethod1.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetMethod/type_getmethod1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetMethod/type_getmethod1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetMethod1/VB/type_getmethod1.vb" id="Snippet1"::: ]]> @@ -5384,6 +5446,7 @@ This method can be used to find a constructed generic member given a member from - The `TestClass` type has two public instance overloads of the `Equals` method, one of which is inherited from : `Equals(TestClass)` and `Equals(Object)`. :::code language="csharp" source="~/snippets/csharp/System/Type/GetMethod/GetMethodWithOverloads1.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetMethod/GetMethodWithOverloads1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Type.GetMethod/vb/GetMethodWithOverloads1.vb" id="Snippet2"::: You can do one of the following to retrieve a specific method: @@ -5408,6 +5471,7 @@ This method can be used to find a constructed generic member given a member from :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetMethod2/CPP/type_getmethod2.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetMethod/type_getmethod2.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetMethod/type_getmethod2.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetMethod2/VB/type_getmethod2.vb" id="Snippet1"::: ]]> @@ -5507,11 +5571,13 @@ This method can be used to find a constructed generic member given a member from :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetMethod4/CPP/type_getmethod4.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetMethod/type_getmethod4.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetMethod/type_getmethod4.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetMethod4/VB/type_getmethod4.vb" id="Snippet1"::: The following example retrieves objects that represent the `Add` methods of a non-generic type (the class), an open generic type (the class), and a closed generic type (the `List(Of String)` type. :::code language="csharp" source="~/snippets/csharp/System/Type/GetMethod/GetMethod1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetMethod/GetMethod1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Type.GetMethod/vb/GetMethod1.vb" id="Snippet1"::: The example defines a `GetAddMethod` method that retrieves the appropriate object. To provide the `types` argument for an open generic type, it calls the method. To provide the `types` argument for a closed generic type, it retrieves the value of the property. @@ -5930,6 +5996,7 @@ One of the elements in the array is @@ -6174,6 +6241,7 @@ One of the elements in the array is @@ -7197,6 +7265,7 @@ If the current represents a type parameter in the definition :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetTypeCode/CPP/type_gettypecode.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetProperties/type_gettypecode.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetProperties/type_gettypecode.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetTypeCode/VB/type_gettypecode.vb" id="Snippet2"::: ]]> @@ -7302,6 +7371,7 @@ The method does not return properties in a p :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetProperties2/CPP/type_getproperties2.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetProperties/type_getproperties2.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetProperties/type_getproperties2.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetProperties2/VB/type_getproperties2.vb" id="Snippet1"::: ]]> @@ -7410,6 +7480,7 @@ The method does not return properties in a p :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetProperty1/CPP/type_getproperty1.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetProperty/type_getproperty1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetProperty/type_getproperty1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetProperty1/VB/type_getproperty1.vb" id="Snippet1"::: Internally, this property is referred to in the metadata by the name "Item." Any attempt to get `PropertyInfo` using reflection must specify this internal name in order to correctly return the `PropertyInfo` property. @@ -7534,6 +7605,7 @@ The method does not return properties in a p :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetProperty2/CPP/type_getproperty2.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetProperty/type_getproperty2.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetProperty/type_getproperty2.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetProperty2/VB/type_getproperty2.vb" id="Snippet1"::: ]]> @@ -7629,6 +7701,7 @@ The method does not return properties in a p :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetProperty_Types/CPP/type_getproperty_types.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetProperty/type_getproperty_types.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetProperty/type_getproperty_types.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetProperty_Types/VB/type_getproperty_types.vb" id="Snippet1"::: ]]> @@ -7727,6 +7800,7 @@ The method does not return properties in a p :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetProperty3/CPP/type_getproperty3.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetProperty/type_getproperty3.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetProperty/type_getproperty3.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetProperty3/VB/type_getproperty3.vb" id="Snippet1"::: ]]> @@ -7936,6 +8010,7 @@ The method does not return properties in a p :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetProperty5/CPP/type_getproperty2.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetProperty/type_getproperty21.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetProperty/type_getproperty21.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetProperty5/VB/type_getproperty2.vb" id="Snippet1"::: ]]> @@ -8478,6 +8553,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetType/CPP/type_gettype.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetType/type_gettype.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetType/type_gettype.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetType/VB/type_gettype.vb" id="Snippet1"::: ]]> @@ -8690,6 +8766,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetType/CPP/type_gettype.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetType/type_gettype.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetType/type_gettype.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetType/VB/type_gettype.vb" id="Snippet1"::: @@ -9334,6 +9411,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs Notice that `MyType` is the only assembly-qualified type argument. The names of the and classes are not assembly-qualified. Your `typeResolver` must be able handle either an assembly or `null`, because it will receive `null` for and . It can handle that case by calling an overload of the method that takes a string, because both of the unqualified type names are in mscorlib.dll/System.Private.CoreLib.dll: :::code language="csharp" source="~/snippets/csharp/System/Type/GetType/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetType/source.fs" id="Snippet1"::: The `assemblyResolver` method is not called for the dictionary type and the string type, because those type names are not assembly-qualified. @@ -9346,6 +9424,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs Because this assembly is neither mscorlib.dll/System.Private.CoreLib.dll nor the currently executing assembly, you cannot resolve `YourType` without an assembly-qualified name. Because your `assemblyResolve` will be called recursively, it must be able to handle this case. Instead of returning `null` for assemblies other than `MyAssembly`, it now performs an assembly load using the supplied object. :::code language="csharp" source="~/snippets/csharp/System/Type/GetType/source.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetType/source.fs" id="Snippet2"::: Back to [Usage Notes](#usage_notes). @@ -9491,6 +9570,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetTypeCode/CPP/type_gettypecode.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetProperties/type_gettypecode.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetProperties/type_gettypecode.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetTypeCode/VB/type_gettypecode.vb" id="Snippet3"::: ]]> @@ -9558,6 +9638,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.TypeCode/CPP/iconvertible.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeCode/iconvertible.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetTypeCode/iconvertible.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TypeCode/VB/iconvertible.vb" id="Snippet2"::: ]]> @@ -9698,6 +9779,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs The following example uses the CLSID of the Microsoft Word [Application object](/office/vba/api/word.application) to retrieve a COM type that represents the Microsoft Word application. It then instantiates the type by calling the method, and closes it by calling the [Application.Quit](/office/vba/api/word.application.quit(method)) method. :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.gettypefromclsid/vb/gettypefromclsid1.vb" id="Snippet1"::: ]]> @@ -9706,6 +9788,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs This method is intended for use when working with COM objects, not with .NET Framework objects. All managed objects, including those that are visible to COM (that is, their attribute is ) have a GUID that is returned by the property. Although the method returns a object that corresponds to the GUID for .NET Framework objects, you can't use that object to create a type instance by calling the method, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.cs" id="Snippet11"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.fs" id="Snippet11"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.gettypefromclsid/vb/gettypefromclsid11.vb" id="Snippet11"::: Instead, the should only be used to retrieve the GUID of an unmanaged COM object, and the resulting object that is passed to the method must represent an unmanaged COM object. @@ -9795,6 +9878,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs The following example uses the CLSID of the Microsoft Word [Application object](/office/vba/api/word.application) to retrieve a COM type that represents the Microsoft Word application. It then instantiates the type by calling the method, and closes it by calling the [Application.Quit](/office/vba/api/word.application.quit(method)) method. An exception is thrown if an error occurs while loading the type. :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex2.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.gettypefromclsid/vb/gettypefromclsid_ex2.vb" id="Snippet2"::: ]]> @@ -9803,6 +9887,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs This method is intended for use when working with COM objects, not with .NET Framework objects. All managed objects, including those that are visible to COM (that is, their attribute is ) have a GUID that is returned by the property. Although the method returns a object that corresponds to the GUID for .NET Framework objects, you can't use that object to create a type instance by calling the method, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.cs" id="Snippet11"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.fs" id="Snippet11"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.gettypefromclsid/vb/gettypefromclsid11.vb" id="Snippet11"::: Instead, the should only be used to retrieve the GUID of an unmanaged COM object, and the resulting object that is passed to the method must represent an unmanaged COM object. @@ -9883,6 +9968,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs The following example uses the CLSID of the Microsoft Word [Application object](/office/vba/api/word.application) to retrieve a COM type that represents the Microsoft Word application from a server named computer17.central.contoso.com. It then instantiates the type by calling the method, and closes it by calling the [Application.Quit](/office/vba/api/word.application.quit(method)) method. :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex3.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.gettypefromclsid/vb/gettypefromclsid_ex3.vb" id="Snippet3"::: ]]> @@ -9891,6 +9977,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs This method is intended for use when working with COM objects, not with .NET Framework objects. All managed objects, including those that are visible to COM (that is, their attribute is ) have a GUID that is returned by the property. Although the method returns a object that corresponds to the GUID for .NET Framework objects, you can't use that object to create a type instance by calling the method, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.cs" id="Snippet11"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.fs" id="Snippet11"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.gettypefromclsid/vb/gettypefromclsid11.vb" id="Snippet11"::: Instead, the should only be used to retrieve the GUID of an unmanaged COM object, and the resulting object that is passed to the method must represent an unmanaged COM object. @@ -9980,6 +10067,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs The following example uses the CLSID of the Microsoft Word [Application object](/office/vba/api/word.application) to retrieve a COM type that represents the Microsoft Word application from a server named computer17.central.contoso.com. It then instantiates the type by calling the method, and closes it by calling the [Application.Quit](/office/vba/api/word.application.quit(method)) method. An exception is thrown if an error occurs while loading the type. :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid_ex4.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.gettypefromclsid/vb/gettypefromclsid_ex4.vb" id="Snippet4"::: ]]> @@ -9988,6 +10076,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs This method is intended for use when working with COM objects, not with .NET Framework objects. All managed objects, including those that are visible to COM (that is, their attribute is ) have a GUID that is returned by the property. Although the method returns a object that corresponds to the GUID for a particular managed object, you can't use that object to create a type instance by calling the method, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.cs" id="Snippet11"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.fs" id="Snippet11"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.gettypefromclsid/vb/gettypefromclsid11.vb" id="Snippet11"::: Instead, the should only be used to retrieve the GUID of an unmanaged COM object, and the resulting object that is passed to the method must represent an unmanaged COM object. @@ -10057,6 +10146,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetTypeFromHandle/CPP/type_gettypefromhandle.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeFromHandle/type_gettypefromhandle.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetTypeFromHandle/type_gettypefromhandle.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetTypeFromHandle/VB/type_gettypefromhandle.vb" id="Snippet1"::: ]]> @@ -10210,6 +10300,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetTypeFromProgID2/CPP/type_gettypefromprogid2.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetTypeFromProgID/type_gettypefromprogid2.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetTypeFromProgID2/VB/type_gettypefromprogid2.vb" id="Snippet1"::: ]]> @@ -10285,6 +10376,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetTypeFromProgID3/CPP/Type_GetTypeFromProgID3.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetTypeFromProgID/type_gettypefromprogid3.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetTypeFromProgID3/VB/type_gettypefromprogid3.vb" id="Snippet1"::: ]]> @@ -10366,6 +10458,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetTypeFromProgID4/CPP/Type_GetTypeFromProgID4.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetTypeFromProgID/type_gettypefromprogid4.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetTypeFromProgID4/VB/type_gettypefromprogid4.vb" id="Snippet1"::: ]]> @@ -10429,6 +10522,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs :::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"::: ]]> @@ -10491,6 +10585,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_Guid/CPP/type_guid.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GUID/type_guid.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GUID/type_guid.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_Guid/VB/type_guid.vb" id="Snippet1"::: ]]> @@ -10556,6 +10651,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_HasElementType/CPP/type_haselementtype.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/HasElementType/type_haselementtype.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/HasElementType/type_haselementtype.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_HasElementType/VB/type_haselementtype.vb" id="Snippet1"::: ]]> @@ -10618,6 +10714,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_HasElementTypeImpl/CPP/type_haselementtypeimpl.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/HasElementTypeImpl/type_haselementtypeimpl.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/HasElementTypeImpl/type_haselementtypeimpl.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_HasElementTypeImpl/VB/type_haselementtypeimpl.vb" id="Snippet1"::: ]]> @@ -10794,6 +10891,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/InvokeMem/CPP/invokemem.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/InvokeMember/invokemem.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/InvokeMember/invokemem.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/InvokeMem/VB/invokemem.vb" id="Snippet1"::: ]]> @@ -11352,7 +11450,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs ## Remarks The property returns `true` in the following cases: -- The current type is abstract; that is, it cannot be instantiated, but can only serve as the base class for derived classes. In C#, abstract classes are marked with the [abstract](/dotnet/csharp/language-reference/keywords/abstract) keyword; in Visual Basic, they are marked with the [MustInherit](/dotnet/visual-basic/language-reference/modifiers/mustinherit) keyword. +- The current type is abstract; that is, it cannot be instantiated, but can only serve as the base class for derived classes. In C#, abstract classes are marked with the [abstract](/dotnet/csharp/language-reference/keywords/abstract) keyword; in F#, they are marked with the [AbstractClass](/dotnet/fsharp/language-reference/abstract-classes) attribute; in Visual Basic, they are marked with the [MustInherit](/dotnet/visual-basic/language-reference/modifiers/mustinherit) keyword. - The current type is an interface. @@ -11376,6 +11474,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs The method returns `true` only for `AbstractClass`, the abstract class, and `ITypeInfo`, the interface. :::code language="csharp" source="~/snippets/csharp/System/Type/IsAbstract/isabstract1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsAbstract/isabstract1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.isabstract/vb/isabstract1.vb" id="Snippet1"::: ]]> @@ -11439,6 +11538,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_IsAnsiClass/CPP/Type_IsAnsiClass.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsAnsiClass/type_isansiclass.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsAnsiClass/type_isansiclass.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_IsAnsiClass/VB/type_isansiclass.vb" id="Snippet1"::: ]]> @@ -11520,6 +11620,7 @@ GetType(Array).IsAssignableFrom(type) The following example demonstrates using the property. :::code language="csharp" source="~/snippets/csharp/System/Type/IsArray/isarray2.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsArray/isarray2.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.isarray/vb/isarray2.vb" id="Snippet1"::: ]]> @@ -11577,6 +11678,7 @@ GetType(Array).IsAssignableFrom(type) :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_IsArrayImpl/CPP/type_isarrayimpl.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsArrayImpl/type_isarrayimpl.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsArrayImpl/type_isarrayimpl.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_IsArrayImpl/VB/type_isarrayimpl.vb" id="Snippet1"::: ]]> @@ -11660,11 +11762,13 @@ GetType(Array).IsAssignableFrom(type) The method can be used to determine whether an instance of `c` can be assigned to an instance of the current type, The method is most useful when you are handling objects whose types are not known at design time and allows for conditional assignment, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsAssignableFrom/IsAssignableFrom3.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.isassignablefrom/vb/IsAssignableFrom3.vb" id="Snippet3"::: This method thus ensures that a line of code like the following will execute at runtime without throwing an exception or a similar exception: :::code language="csharp" source="~/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom3.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsAssignableFrom/IsAssignableFrom3.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.isassignablefrom/vb/IsAssignableFrom3.vb" id="Snippet4"::: This method can be overridden by a derived class. @@ -11675,6 +11779,7 @@ GetType(Array).IsAssignableFrom(type) If the `c` parameter is of type , the result is based on the type that is to be built. The following code example demonstrates this using a built type named `B`. :::code language="csharp" source="~/snippets/csharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.isassignablefrom/vb/isassignablefrom_ex1.vb" id="Snippet1"::: @@ -11684,11 +11789,13 @@ GetType(Array).IsAssignableFrom(type) :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/TestIsAssignableFrom/cpp/testisassignablefrom.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsAssignableFrom/testisassignablefrom.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsAssignableFrom/testisassignablefrom.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/TestIsAssignableFrom/VB/testisassignablefrom.vb" id="Snippet1"::: In the following example, the current instance is a object that represents the class. `GenericWithConstraint` is a generic type whose generic type parameter must be of type . Passing its generic type parameter to the `IsAssignableFrom` method indicates that an instance of the generic type parameter can be assigned to an object. :::code language="csharp" source="~/snippets/csharp/System/Type/IsAssignableFrom/IsAssignableFrom2.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsAssignableFrom/IsAssignableFrom2.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.isassignablefrom/vb/IsAssignableFrom2.vb" id="Snippet2"::: @@ -11866,6 +11973,7 @@ GetType(Array).IsAssignableFrom(type) :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_IsAutoLayout/CPP/type_isautolayout.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsAutoLayout/type_isautolayout.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsAutoLayout/type_isautolayout.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_IsAutoLayout/VB/type_isautolayout.vb" id="Snippet1"::: ]]> @@ -11935,6 +12043,7 @@ GetType(Array).IsAssignableFrom(type) :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_HasElementTypeImpl/CPP/type_haselementtypeimpl.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/HasElementTypeImpl/type_haselementtypeimpl.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/HasElementTypeImpl/type_haselementtypeimpl.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_HasElementTypeImpl/VB/type_haselementtypeimpl.vb" id="Snippet1"::: ]]> @@ -12084,6 +12193,7 @@ Byref-like structures are declared using `ref struct` keyword in C#. An instance :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_IsClass/CPP/type_isclass.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsClass/type_isclass.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsClass/type_isclass.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_IsClass/VB/type_isclass.vb" id="Snippet1"::: ]]> @@ -12305,6 +12415,7 @@ Byref-like structures are declared using `ref struct` keyword in C#. An instance :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_IsContextful/CPP/type_iscontextful.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsContextful/type_iscontextful.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsContextful/type_iscontextful.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_IsContextful/VB/type_iscontextful.vb" id="Snippet1"::: ]]> @@ -12364,6 +12475,7 @@ Byref-like structures are declared using `ref struct` keyword in C#. An instance :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_IsContextfulImpl/CPP/type_iscontextfulimpl.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsContextfulImpl/type_iscontextfulimpl.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsContextfulImpl/type_iscontextfulimpl.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_IsContextfulImpl/VB/type_iscontextfulimpl.vb" id="Snippet1"::: ]]> @@ -12438,6 +12550,7 @@ Byref-like structures are declared using `ref struct` keyword in C#. An instance :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/TestIsEnum/CPP/TestIsEnum.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsEnum/testisenum.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsEnum/testisenum.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/TestIsEnum/VB/testisenum.vb" id="Snippet1"::: ]]> @@ -12611,6 +12724,7 @@ Byref-like structures are declared using `ref struct` keyword in C#. An instance The following example creates an instance of a type and displays the value of its property. It uses the `MySystemTime` class, which is also in the code example for . :::code language="csharp" source="~/snippets/csharp/System/Type/IsExplicitLayout/type_isexplicitlayout.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsExplicitLayout/type_isexplicitlayout.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_IsExplicitLayout/VB/type_isexplicitlayout.vb" id="Snippet1"::: ]]> @@ -12718,6 +12832,7 @@ Byref-like structures are declared using `ref struct` keyword in C#. An instance :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Type.IsGenericParameter/CPP/source.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetGenericArguments/source.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetGenericArguments/source.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Type.IsGenericParameter/VB/source.vb" id="Snippet2"::: ]]> @@ -12789,6 +12904,7 @@ Byref-like structures are declared using `ref struct` keyword in C#. An instance :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Type.IsGenericType/cpp/remarks.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsGenericType/remarks.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsGenericType/remarks.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Type.IsGenericType/vb/remarks.vb" id="Snippet2"::: The following table shows examples that use and build on the classes `Base`, `Derived`, and `G`. When the C++ and C# code is the same, only one entry is shown. @@ -12809,6 +12925,7 @@ Byref-like structures are declared using `ref struct` keyword in C#. An instance :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Type.IsGenericType/cpp/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsGenericType/source.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsGenericType/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Type.IsGenericType/vb/source.vb" id="Snippet1"::: ]]> @@ -12871,6 +12988,7 @@ Byref-like structures are declared using `ref struct` keyword in C#. An instance :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Type.IsGenericTypeDefinition/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsGenericParameter/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsGenericParameter/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Type.IsGenericTypeDefinition/VB/source.vb" id="Snippet1"::: ]]> @@ -13039,6 +13157,7 @@ Byref-like structures are declared using `ref struct` keyword in C#. An instance :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/TestIsInstanceOfType/CPP/testisinstanceoftype.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsInstanceOfType/testisinstanceoftype.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsInstanceOfType/testisinstanceoftype.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/TestIsInstanceOfType/VB/testisinstanceoftype.vb" id="Snippet1"::: ]]> @@ -13107,6 +13226,7 @@ Byref-like structures are declared using `ref struct` keyword in C#. An instance :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_IsInterface/CPP/type_isinterface.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsInterface/type_isinterface.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsInterface/type_isinterface.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_IsInterface/VB/type_isinterface.vb" id="Snippet1"::: ]]> @@ -13179,6 +13299,7 @@ Byref-like structures are declared using `ref struct` keyword in C#. An instance :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_IsLayoutSequential/CPP/type_islayoutsequential.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsLayoutSequential/type_islayoutsequential.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsLayoutSequential/type_islayoutsequential.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_IsLayoutSequential/VB/type_islayoutsequential.vb" id="Snippet1"::: ]]> @@ -13236,6 +13357,7 @@ Byref-like structures are declared using `ref struct` keyword in C#. An instance :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_IsContextful/CPP/type_iscontextful.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsContextful/type_iscontextful.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsContextful/type_iscontextful.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_IsContextful/VB/type_iscontextful.vb" id="Snippet1"::: ]]> @@ -13293,6 +13415,7 @@ Byref-like structures are declared using `ref struct` keyword in C#. An instance :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_IsMarshalByRefImpl/CPP/type_ismarshalbyrefimpl.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsMarshalByRefImpl/type_ismarshalbyrefimpl.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsMarshalByRefImpl/type_ismarshalbyrefimpl.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_IsMarshalByRefImpl/VB/type_ismarshalbyrefimpl.vb" id="Snippet1"::: ]]> @@ -13803,12 +13926,14 @@ Byref-like structures are declared using `ref struct` keyword in C#. An instance :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.IsNotPublic Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsNotPublic/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsNotPublic/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic Type.IsNotPublic Example/VB/source.vb" id="Snippet1"::: The following code example demonstrates why you cannot use `IsPublic` and `IsNotPublic` for nested classes. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.IsNotPublic Example/CPP/source.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsNotPublic/source.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsNotPublic/source.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic Type.IsNotPublic Example/VB/source.vb" id="Snippet2"::: For nested classes, ignore the results of `IsPublic` and `IsNotPublic` and pay attention only to the results of `IsNestedPublic` and `IsNestedPrivate`. The reflection output for this code fragment would be as follows: @@ -13885,6 +14010,7 @@ Byref-like structures are declared using `ref struct` keyword in C#. An instance :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_HasElementTypeImpl/CPP/type_haselementtypeimpl.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/HasElementTypeImpl/type_haselementtypeimpl.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/HasElementTypeImpl/type_haselementtypeimpl.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_HasElementTypeImpl/VB/type_haselementtypeimpl.vb" id="Snippet1"::: ]]> @@ -13987,6 +14113,7 @@ Byref-like structures are declared using `ref struct` keyword in C#. An instance :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_IsContextful/CPP/type_iscontextful.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsContextful/type_iscontextful.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsContextful/type_iscontextful.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_IsContextful/VB/type_iscontextful.vb" id="Snippet1"::: ]]> @@ -14056,6 +14183,7 @@ Byref-like structures are declared using `ref struct` keyword in C#. An instance :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_IsPrimitiveImpl/CPP/type_isprimitiveimpl.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsPrimitiveImpl/type_isprimitiveimpl.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsPrimitiveImpl/type_isprimitiveimpl.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_IsPrimitiveImpl/VB/type_isprimitiveimpl.vb" id="Snippet1"::: ]]> @@ -14137,6 +14265,7 @@ Byref-like structures are declared using `ref struct` keyword in C#. An instance :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type.IsPublic/CPP/type_ispublic.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsPublic/type_ispublic.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsPublic/type_ispublic.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type.IsPublic/VB/type_ispublic.vb" id="Snippet1"::: For nested classes, ignore the results of `IsPublic` and `IsNotPublic` and pay attention only to the results of and . @@ -14198,6 +14327,7 @@ Byref-like structures are declared using `ref struct` keyword in C#. An instance :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_IsSealed/CPP/type_issealed.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsSealed/type_issealed.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsSealed/type_issealed.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_IsSealed/VB/type_issealed.vb" id="Snippet1"::: ]]> @@ -14442,6 +14572,7 @@ Types that are defined in the .NET Standard are not marked with @@ -14611,6 +14742,7 @@ A signature type is a restricted type that can be passed to the method cannot be used to determine whether an interface derives from another interface, or whether a class implements an interface. Use the method for that purpose, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System/Type/IsSubclassOf/issubclassof_interface1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsSubclassOf/issubclassof_interface1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.issubclassof/vb/issubclassof_interface1.vb" id="Snippet1"::: If the current represents a type parameter in the definition of a generic type or generic method, it derives from its class constraint or from if it has no class constraint. @@ -14626,6 +14758,7 @@ A signature type is a restricted type that can be passed to the method to show that `DerivedC1` is a subclass of `Class1`. :::code language="csharp" source="~/snippets/csharp/System/Type/IsSubclassOf/testissubclassof.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsSubclassOf/testissubclassof.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/TestIsSubclassOf/VB/testissubclassof.vb" id="Snippet1"::: ]]> @@ -14824,6 +14957,7 @@ A signature type is a restricted type that can be passed to the @@ -14988,6 +15122,7 @@ If the value of this property is `true` for an array type, it can be used to cre :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Type.IsVisible/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/IsVisible/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/IsVisible/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Type.IsVisible/VB/source.vb" id="Snippet1"::: ]]> @@ -15013,6 +15148,7 @@ If the value of this property is `true` for an array type, it can be used to cre :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Type.MakeXxxType/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/MakeByRefType/source.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/MakeByRefType/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Type.MakeXxxType/VB/source.vb" id="Snippet1"::: ]]> @@ -15213,6 +15349,7 @@ If the value of this property is `true` for an array type, it can be used to cre :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Type.MakeXxxType/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/MakeByRefType/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/MakeByRefType/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Type.MakeXxxType/VB/source.vb" id="Snippet1"::: ]]> @@ -15378,6 +15515,7 @@ If the value of this property is `true` for an array type, it can be used to cre :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.type.makegenerictype/cpp/remarks.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/MakeGenericType/remarks.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/MakeGenericType/remarks.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.makegenerictype/vb/remarks.vb" id="Snippet1"::: To generate `Derived` in a dynamic assembly, it is necessary to construct its base type. To do this, call the method on a object representing the class `Base`, using the generic type arguments and the type parameter `V` from `Derived`. Because types and generic type parameters are both represented by objects, an array containing both can be passed to the method. @@ -15436,6 +15574,7 @@ If the value of this property is `true` for an array type, it can be used to cre :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Type.BindGenericParameters/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/MakeGenericType/source.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/MakeGenericType/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Type.BindGenericParameters/VB/source.vb" id="Snippet1"::: ]]> @@ -15521,6 +15660,7 @@ If the value of this property is `true` for an array type, it can be used to cre :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Type.MakeXxxType/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/MakeByRefType/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/MakeByRefType/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Type.MakeXxxType/VB/source.vb" id="Snippet1"::: ]]> @@ -15590,6 +15730,7 @@ If the value of this property is `true` for an array type, it can be used to cre :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.MemberType Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/MemberType/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/MemberType/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic Type.MemberType Example/VB/source.vb" id="Snippet1"::: ]]> @@ -15648,6 +15789,7 @@ If the value of this property is `true` for an array type, it can be used to cre :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.Missing Example/cpp/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/Missing/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/Missing/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic Type.Missing Example/VB/source.vb" id="Snippet1"::: This code produces the following output: @@ -15716,6 +15858,7 @@ If the value of this property is `true` for an array type, it can be used to cre :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_ToString/CPP/type_tostring.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/Module/type_tostring.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/Module/type_tostring.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_ToString/VB/type_tostring.vb" id="Snippet1"::: ]]> @@ -15813,6 +15956,7 @@ If the value of this property is `true` for an array type, it can be used to cre :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_ToString/CPP/type_tostring.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/Module/type_tostring.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/Module/type_tostring.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_ToString/VB/type_tostring.vb" id="Snippet1"::: ]]> @@ -15975,6 +16119,7 @@ If the value of this property is `true` for an array type, it can be used to cre :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic Type.ReflectedType Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/ReflectedType/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/ReflectedType/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic Type.ReflectedType Example/VB/source.vb" id="Snippet1"::: ]]> @@ -16154,6 +16299,7 @@ If the value of this property is `true` for an array type, it can be used to cre :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type.StructLayoutAttribute/CPP/Type.StructLayoutAttribute.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/StructLayoutAttribute/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/StructLayoutAttribute/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type.StructLayoutAttribute/VB/source.vb" id="Snippet1"::: ]]> @@ -16422,11 +16568,13 @@ If the value of this property is `true` for an array type, it can be used to cre :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_ToString/CPP/type_tostring.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/Module/type_tostring.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/Module/type_tostring.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_ToString/VB/type_tostring.vb" id="Snippet1"::: The following example compares the strings returned by the `ToString` method and the , , and properties. :::code language="csharp" source="~/snippets/csharp/System/Type/AssemblyQualifiedName/fullname1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/AssemblyQualifiedName/fullname1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.tostring/vb/fullname1.vb" id="Snippet1"::: ]]> @@ -16492,6 +16640,7 @@ If the value of this property is `true` for an array type, it can be used to cre :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_TypeHandle/CPP/type_typehandle.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Type/TypeHandle/type_typehandle.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Type/TypeHandle/type_typehandle.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_TypeHandle/VB/type_typehandle.vb" id="Snippet1"::: ]]> From 23f26b99a1ad1489d2bae21c26a47c03185e6ee5 Mon Sep 17 00:00:00 2001 From: albert-du <52804499+albert-du@users.noreply.github.com> Date: Wed, 20 Apr 2022 19:59:15 -0700 Subject: [PATCH 2/2] fix snippets --- .../Type/GenericParameterAttributes/source.fs | 14 ++++++-------- .../Type/IsAssignableFrom/isassignablefrom_ex1.fs | 1 + 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/snippets/fsharp/System/Type/GenericParameterAttributes/source.fs b/snippets/fsharp/System/Type/GenericParameterAttributes/source.fs index ab24a1fe59c..4c2bde09cd5 100644 --- a/snippets/fsharp/System/Type/GenericParameterAttributes/source.fs +++ b/snippets/fsharp/System/Type/GenericParameterAttributes/source.fs @@ -35,7 +35,7 @@ let listGenericParameterAttributes (t: Type) = if variance = GenericParameterAttributes.None then "No variance flag" else - if variance &&& GenericParameterAttributes.Covariant <> 0 then + if variance &&& GenericParameterAttributes.Covariant |> int <> 0 then "Covariant" else "Contravariant" @@ -45,19 +45,17 @@ let listGenericParameterAttributes (t: Type) = if constraints = GenericParameterAttributes.None then retval <- retval + " No special constraints" else - if constraints &&& GenericParameterAttributes.ReferenceTypeConstraint <> 0 then + if constraints &&& GenericParameterAttributes.ReferenceTypeConstraint |> int <> 0 then retval <- retval + " ReferenceTypeConstraint" - if constraints &&& GenericParameterAttributes.NotNullableValueTypeConstraint <> 0 then + if constraints &&& GenericParameterAttributes.NotNullableValueTypeConstraint |> int <> 0 then retval <- retval + " NotNullableValueTypeConstraint" - if constraints &&& GenericParameterAttributes.DefaultConstructorConstraint <> 0 then + if constraints &&& GenericParameterAttributes.DefaultConstructorConstraint |> int <> 0 then retval <- retval + " DefaultConstructorConstraint" retval -// To get the generic type definition, omit the type -// arguments but retain the comma to indicate the number -// of type arguments. -let def = typeof>.GetGenericTypeDefinition() +// To get the generic type definition, call .GetGenericTypeDefinition(). +let def = typeof>.GetGenericTypeDefinition() printfn $"\nExamining generic type {def}" // Get the type parameters of the generic type definition, diff --git a/snippets/fsharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.fs b/snippets/fsharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.fs index cec3d94a902..f18fdf4cc1e 100644 --- a/snippets/fsharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.fs +++ b/snippets/fsharp/System/Type/IsAssignableFrom/isassignablefrom_ex1.fs @@ -3,6 +3,7 @@ // open System open System.Reflection +open System.Reflection.Emit type A() = class end