CodeTypeDeclaration.BaseTypes Property

Gets the base types of the type.

Namespace:  System.CodeDom
Assembly:  System (in System.dll)

public CodeTypeReferenceCollection BaseTypes { get; }

Property Value

Type: System.CodeDom.CodeTypeReferenceCollection
A CodeTypeReferenceCollection object that indicates the base types of the type.

To generate a class in Visual Basic that does not inherit from a base type, but that does implement one or more interfaces, you must include Object as the first item in the BaseTypes collection.

NoteNote

In the .NET Framework version 2.0 you do not need the CodeTypeReference for Object if the interface you are implementing already exists and you are referring to it by type. For example, if you are implementing the ICollection interface and add it to the collection with this statement, ctd.BaseTypes.Add(New CodeTypeReference(typeof(ICollection))), you do not need the preceding ctd.BaseTypes.Add(New CodeTypeReference(GetType(Object))) statement.

The following code illustrates the addition of a CodeTypeReference to the collection that refers to Object.

[Visual Basic]

Dim ctd As New CodeTypeDeclaration("Class1")
ctd.IsClass = True
ctd.BaseTypes.Add(New CodeTypeReference(GetType(Object)))
ctd.BaseTypes.Add(New CodeTypeReference("Interface1"))

[C#]

CodeTypeDeclaration ctd = new CodeTypeDeclaration("Class1");
ctd.IsClass = true;
ctd.BaseTypes.Add(new CodeTypeReference(typeof(Object)));
ctd.BaseTypes.Add(new CodeTypeReference("Interface1"));

The preceding code generates the equivalent of the following Visual Basic code.

Public Class Class1
Implements Interface1

However, the Visual Basic code actually generated is the following.

Public Class Class1
Inherits Object
Implements Interface1

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft