Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

GuidConverter Class

Provides a type converter to convert Guid objects to and from various other representations.

For a list of all members of this type, see GuidConverter Members.

System.Object
   System.ComponentModel.TypeConverter
      System.ComponentModel.GuidConverter

[Visual Basic]
Public Class GuidConverter
   Inherits TypeConverter
[C#]
public class GuidConverter : TypeConverter
[C++]
public __gc class GuidConverter : public TypeConverter
[JScript]
public class GuidConverter extends TypeConverter

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

This converter can only convert a globally unique identifier (GUID) object to and from a string.

For more information about type converters, see the TypeConverter base class and Implementing a Type Converter.

CAUTION   You should never create an instance of a GuidConverter. Instead, call the GetConverter method of TypeDescriptor. For more information, see the examples in the TypeConverter base class.

Example

[Visual Basic, C#, C++] The following sample converts a variable of type Guid to a string, and vice versa.

[Visual Basic] 
Dim myGuid As New Guid("B80D56EC-5899-459d-83B4-1AE0BB8418E4")
Dim myGuidString As String = "1AA7F83F-C7F5-11D0-A376-00C04FC9DA04"
Console.WriteLine(TypeDescriptor.GetConverter(myGuid).ConvertTo(myGuid, GetType(String)))
Console.WriteLine(TypeDescriptor.GetConverter(myGuid).ConvertFrom(myGuidString))

[C#] 
Guid myGuid = new Guid("B80D56EC-5899-459d-83B4-1AE0BB8418E4");
string myGuidString = "1AA7F83F-C7F5-11D0-A376-00C04FC9DA04";
Console.WriteLine(TypeDescriptor.GetConverter(myGuid).ConvertTo(myGuid, typeof(string))); 
Console.WriteLine(TypeDescriptor.GetConverter(myGuid).ConvertFrom(myGuidString));    

[C++] 
Guid myGuid(S"B80D56EC-5899-459d-83B4-1AE0BB8418E4");
String* myGuidString = S"1AA7F83F-C7F5-11D0-A376-00C04FC9DA04";
Console::WriteLine(TypeDescriptor::GetConverter(__box(myGuid))->ConvertTo(__box(myGuid), __typeof(String)));
Console::WriteLine(TypeDescriptor::GetConverter(__box(myGuid))->ConvertFrom(myGuidString));

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.ComponentModel

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

GuidConverter Members | System.ComponentModel Namespace

Show:
© 2014 Microsoft