how to "implements an interface" using CodeDom

  • Thread starter Thread starter sql chen
  • Start date Start date
S

sql chen

'Hello
'i have generate such a simple class by CodeDom
'==========================================

Public Class A

Public Function B()

End Class

'==========================================
'But i want improve these code as follow:
'==========================================

Public Class A
Implements IData

Public Function B() implements IData.B

End Class

'==========================================

i tried "CodeTypeDeclaration.BaseTypes", but it can only let me "Inherits".
can you give me some good idea? thanks
 
sql chen said:
i tried "CodeTypeDeclaration.BaseTypes", but it can only let me "Inherits".

Well, the following code

Code:
typeDef as CodeTypeDeclaration = new CodeTypeDeclaration("SomeClass")
typeDef.BaseTypes.Add(new CodeTypeReference(typeof(IComparable)))
typeDef.BaseTypes.Add(new CodeTypeReference(typeof(Attribute)))

produces the output:

Code:
Public Class SomeClass
Implements System.IComparable
Inherits System.Attribute
End Class

Mark
 
Back
Top