From b8ef7a04b5943ea684cbcdfb0b425dd539b15e92 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Tue, 12 Mar 2024 23:04:39 -0700 Subject: [PATCH 1/3] Import System.Guid and System.Type.Guid documentation - Clarify that Type.Guid is COM-interop specific - Delete COM-interop specific sample from System.Guid. This sample is not directly relevant to Guid type and there are other similar samples on GuidAttribute. --- xml/System/Guid.xml | 12 ------------ xml/System/Type.xml | 4 ++-- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/xml/System/Guid.xml b/xml/System/Guid.xml index 348ad9abf17..500292f411c 100644 --- a/xml/System/Guid.xml +++ b/xml/System/Guid.xml @@ -114,18 +114,6 @@ ## Remarks A GUID is a 128-bit integer (16 bytes) that can be used across all computers and networks wherever a unique identifier is required. Such an identifier has a very low probability of being duplicated. - - -## Examples - The following example uses the class to assign a GUID to an interface and to a user-defined class. It retrieves the value of the GUID by calling the method, and compares it with two other GUIDs to determine whether they are equal. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Guid/CPP/Guids.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/Guid/Overview/Guids.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Guid/Overview/Guids.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Guid/VB/Guids.vb" id="Snippet1"::: - - Note that the attribute is typically used in an application to expose a type to COM. If you compile this example, you can run the [Assembly Registration tool (Regasm.exe)](/dotnet/framework/tools/regasm-exe-assembly-registration-tool) on the generated assembly to create registry (.reg) and type library (.tlb) files. The .reg file can be used to register the coclass in the registry, and the .tlb file can provide metadata for COM interop. - ]]> diff --git a/xml/System/Type.xml b/xml/System/Type.xml index c2f017a9861..b95c56095cf 100644 --- a/xml/System/Type.xml +++ b/xml/System/Type.xml @@ -11063,9 +11063,9 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs attribute. - + This property returns a GUID associated with a type using the attribute. If the attribute is omitted, a GUID is assigned automatically. + The GUID returned by this property is typically used to expose a type to COM. It is not meant to be used as a unique identifier of the type. ## Examples The following example creates the class `MyClass1` with a public method, creates a `Type` object corresponding to `MyClass1`, and gets the structure using the `GUID` property of the `Type` class. From 99cd9e850857dec742e399eceecdbd3f2913d57c Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Fri, 15 Mar 2024 10:23:04 -0700 Subject: [PATCH 2/3] Delete unused snippets --- .../cpp/VS_Snippets_CLR/Guid/CPP/Guids.cpp | 52 ------------------- snippets/csharp/System/Guid/Overview/Guids.cs | 45 ---------------- .../System/Guid/Overview/Project.csproj | 8 --- snippets/fsharp/System/Guid/Overview/Guids.fs | 41 --------------- .../fsharp/System/Guid/Overview/fs.fsproj | 10 ---- .../VS_Snippets_CLR/Guid/VB/Guids.vb | 50 ------------------ 6 files changed, 206 deletions(-) delete mode 100644 snippets/cpp/VS_Snippets_CLR/Guid/CPP/Guids.cpp delete mode 100644 snippets/csharp/System/Guid/Overview/Guids.cs delete mode 100644 snippets/csharp/System/Guid/Overview/Project.csproj delete mode 100644 snippets/fsharp/System/Guid/Overview/Guids.fs delete mode 100644 snippets/fsharp/System/Guid/Overview/fs.fsproj delete mode 100644 snippets/visualbasic/VS_Snippets_CLR/Guid/VB/Guids.vb diff --git a/snippets/cpp/VS_Snippets_CLR/Guid/CPP/Guids.cpp b/snippets/cpp/VS_Snippets_CLR/Guid/CPP/Guids.cpp deleted file mode 100644 index 05b6fb9f0e8..00000000000 --- a/snippets/cpp/VS_Snippets_CLR/Guid/CPP/Guids.cpp +++ /dev/null @@ -1,52 +0,0 @@ - -// -using namespace System; -using namespace System::Runtime::InteropServices; - -// Guid for the interface IMyInterface. -[Guid("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4")] -public interface class IMyInterface -{ -public: - void MyMethod(); -}; - - -// Guid for the coclass MyTestClass. -[Guid("936DA01F-9ABD-4d9d-80C7-02AF85C822A8")] -public ref class MyTestClass: public IMyInterface -{ -public: - virtual void MyMethod(){} -}; - -int main() -{ - Attribute^ IMyInterfaceAttribute = Attribute::GetCustomAttribute( IMyInterface::typeid, GuidAttribute::typeid ); - - // The Value property of GuidAttribute returns a string. - System::Console::WriteLine( String::Concat( "IMyInterface Attribute: ", (dynamic_cast(IMyInterfaceAttribute))->Value ) ); - - // Using the string to create a guid. - Guid myGuid1 = Guid(dynamic_cast(IMyInterfaceAttribute)->Value); - - // Using a byte array to create a guid. - Guid myGuid2 = Guid(myGuid1.ToByteArray()); - - // Equals is overridden to perform a value comparison. - if ( myGuid1.Equals( myGuid2 ) ) - System::Console::WriteLine( "myGuid1 equals myGuid2" ); - else - System::Console::WriteLine( "myGuid1 not equals myGuid2" ); - - // Equality operator can also be used to determine if two guids have same value. - if ( myGuid1 == myGuid2 ) - System::Console::WriteLine( "myGuid1 == myGuid2" ); - else - System::Console::WriteLine( "myGuid1 != myGuid2" ); -} -// The example displays the following output: -// IMyInterface Attribute: F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4 -// myGuid1 equals myGuid2 -// myGuid1 == myGuid2 -// diff --git a/snippets/csharp/System/Guid/Overview/Guids.cs b/snippets/csharp/System/Guid/Overview/Guids.cs deleted file mode 100644 index 417955c5753..00000000000 --- a/snippets/csharp/System/Guid/Overview/Guids.cs +++ /dev/null @@ -1,45 +0,0 @@ -// -using System; -using System.Runtime.InteropServices; - -// Guid for the interface IMyInterface. -[Guid("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4")] -interface IMyInterface -{ - void MyMethod(); -} - -// Guid for the coclass MyTestClass. -[Guid("936DA01F-9ABD-4d9d-80C7-02AF85C822A8")] -public class MyTestClass : IMyInterface -{ - public void MyMethod() {} - - public static void Main( string []args ) - { - GuidAttribute IMyInterfaceAttribute = (GuidAttribute) Attribute.GetCustomAttribute(typeof(IMyInterface), typeof(GuidAttribute)); - - System.Console.WriteLine("IMyInterface Attribute: " + IMyInterfaceAttribute.Value ); - - // Use the string to create a guid. - Guid myGuid1 = new Guid(IMyInterfaceAttribute.Value ); - // Use a byte array to create a guid. - Guid myGuid2 = new Guid(myGuid1.ToByteArray()); - - if (myGuid1.Equals(myGuid2)) - System.Console.WriteLine("myGuid1 equals myGuid2"); - else - System.Console.WriteLine("myGuid1 does not equal myGuid2" ); - - // Equality operator can also be used to determine if two guids have same value. - if ( myGuid1 == myGuid2 ) - System.Console.WriteLine( "myGuid1 == myGuid2" ); - else - System.Console.WriteLine( "myGuid1 != myGuid2" ); - } -} -// The example displays the following output: -// IMyInterface Attribute: F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4 -// myGuid1 equals myGuid2 -// myGuid1 == myGuid2 -// diff --git a/snippets/csharp/System/Guid/Overview/Project.csproj b/snippets/csharp/System/Guid/Overview/Project.csproj deleted file mode 100644 index aa9fd2ecaaf..00000000000 --- a/snippets/csharp/System/Guid/Overview/Project.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - - Exe - net6.0 - - - \ No newline at end of file diff --git a/snippets/fsharp/System/Guid/Overview/Guids.fs b/snippets/fsharp/System/Guid/Overview/Guids.fs deleted file mode 100644 index 3dcee1c3731..00000000000 --- a/snippets/fsharp/System/Guid/Overview/Guids.fs +++ /dev/null @@ -1,41 +0,0 @@ -// -open System -open System.Runtime.InteropServices - -// Guid for the interface IMyInterface. -[] -type IMyInterface = - abstract MyMethod: unit -> unit - -// Guid for the coclass MyTestClass. -[] -type MyTestClass() = - interface IMyInterface with - member _.MyMethod() = () - -let IMyInterfaceAttribute = - Attribute.GetCustomAttribute(typeof, typeof) :?> GuidAttribute - -printfn $"IMyInterface Attribute: {IMyInterfaceAttribute.Value}" - -// Use the string to create a guid. -let myGuid1 = Guid IMyInterfaceAttribute.Value -// Use a byte array to create a guid. -let myGuid2 = Guid(myGuid1.ToByteArray()) - -if myGuid1.Equals myGuid2 then - printfn "myGuid1 equals myGuid2" -else - printfn "myGuid1 does not equal myGuid2" - -// Equality operator can also be used to determine if two guids have same value. -if myGuid1 = myGuid2 then - printfn "myGuid1 == myGuid2" -else - printfn "myGuid1 <> myGuid2" - -// The example displays the following output: -// IMyInterface Attribute: F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4 -// myGuid1 equals myGuid2 -// myGuid1 == myGuid2 -// \ No newline at end of file diff --git a/snippets/fsharp/System/Guid/Overview/fs.fsproj b/snippets/fsharp/System/Guid/Overview/fs.fsproj deleted file mode 100644 index 44b5d4a7b82..00000000000 --- a/snippets/fsharp/System/Guid/Overview/fs.fsproj +++ /dev/null @@ -1,10 +0,0 @@ - - - Exe - net6.0 - - - - - - \ No newline at end of file diff --git a/snippets/visualbasic/VS_Snippets_CLR/Guid/VB/Guids.vb b/snippets/visualbasic/VS_Snippets_CLR/Guid/VB/Guids.vb deleted file mode 100644 index 078d451daeb..00000000000 --- a/snippets/visualbasic/VS_Snippets_CLR/Guid/VB/Guids.vb +++ /dev/null @@ -1,50 +0,0 @@ -' Visual Basic .NET Document -Option Strict On - -' -Imports System.Runtime.InteropServices - -' Guid for the interface IMyInterface. - _ -Interface IMyInterface - Sub MyMethod() -End Interface - -' Guid for the coclass MyTestClass. - _ -Public Class MyTestClass - Implements IMyInterface - - Public Sub MyMethod() Implements IMyInterface.MyMethod - End Sub - - Public Shared Sub Main() - Dim IMyInterfaceAttribute As GuidAttribute = CType(Attribute.GetCustomAttribute(GetType(IMyInterface), GetType(GuidAttribute)), - GuidAttribute) - - Console.WriteLine("IMyInterface Attribute: " + IMyInterfaceAttribute.Value) - - ' Use the string to create a guid. - Dim myGuid1 As New Guid(IMyInterfaceAttribute.Value) - ' Use a byte array to create a guid. - Dim myGuid2 As New Guid(myGuid1.ToByteArray()) - - If myGuid1.Equals(myGuid2) Then - Console.WriteLine("myGuid1 equals myGuid2") - Else - Console.WriteLine("myGuid1 does not equal myGuid2") - End If - - ' The equality operator can also be used to determine if two guids have same value. - If myGuid1.ToString() = myGuid2.ToString() Then - Console.WriteLine("myGuid1 == myGuid2") - Else - Console.WriteLine("myGuid1 != myGuid2") - End If - End Sub -End Class -' The example displays the following output: -' IMyInterface Attribute: F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4 -' myGuid1 equals myGuid2 -' myGuid1 == myGuid2 -' From 654d78a0e70db967552e681c1a441536945ffab1 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Fri, 15 Mar 2024 10:27:47 -0700 Subject: [PATCH 3/3] FB --- xml/System/Type.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xml/System/Type.xml b/xml/System/Type.xml index 1ba915acb7b..f55b1f0a202 100644 --- a/xml/System/Type.xml +++ b/xml/System/Type.xml @@ -11038,7 +11038,7 @@ Calling this method overload is the same as calling the attribute. If the attribute is omitted, a GUID is assigned automatically. + This property returns a GUID that's associated with a type using the attribute. If the attribute is omitted, a GUID is assigned automatically. The GUID returned by this property is typically used to expose a type to COM. It is not meant to be used as a unique identifier of the type.