Note that there are some explanatory texts on larger screens.

plurals
  1. POImplement Generic Interface via CodeDom
    primarykey
    data
    text
    <p>The CodeDom is not generating legal VB for me when I try to implement a generic interface.</p> <p>Here is my VB code to generate the VB code.</p> <pre><code>Private Sub RunTest() Dim compileUnit = New CodeCompileUnit Dim ns As New CodeNamespace() compileUnit.Namespaces.Add(ns) ns.Imports.Add(New CodeNamespaceImport("System")) ns.Imports.Add(New CodeNamespaceImport("System.Collections.Generic")) Dim fooCollection = New CodeTypeDeclaration("FooCollection") ns.Types.Add(fooCollection) fooCollection.TypeAttributes = Reflection.TypeAttributes.Public fooCollection.IsClass = True fooCollection.BaseTypes.Add(New CodeTypeReference(GetType(System.Object))) fooCollection.BaseTypes.Add(New CodeTypeReference( _ "System.Collections.Generic.IEnumerable" _ , New CodeTypeReference() {New CodeTypeReference("Foo")} _ )) Dim method = New CodeMemberMethod fooCollection.Members.Add(method) method.Attributes = MemberAttributes.Private method.Name = "GetEnumerator" method.ReturnType = New CodeTypeReference( _ "System.Collections.Generic.IEnumerable" _ , New CodeTypeReference() {New CodeTypeReference("Foo")} _ ) method.PrivateImplementationType = New CodeTypeReference( _ "System.Collections.Generic.IEnumerable" _ , New CodeTypeReference() {New CodeTypeReference("Foo")} _ ) Dim provider = New Microsoft.VisualBasic.VBCodeProvider Dim options = New Compiler.CodeGeneratorOptions Dim writer = New IO.StringWriter provider.GenerateCodeFromCompileUnit(compileUnit, writer, options) Console.WriteLine(writer.ToString) End Sub </code></pre> <p>And that will generate:</p> <pre><code>Public Class FooCollection Inherits Object Implements System.Collections.Generic.IEnumerable(Of Foo) Function System_Collections_Generic_IEnumerable`1_GetEnumerator() _ As System.Collections.Generic.IEnumerable(Of Foo) _ Implements System.Collections.Generic.IEnumerable(Of Foo).GetEnumerator End Function End Class </code></pre> <p>The problem is the name of the function. The tick mark in the function name doesn't make for a legal function name.</p> <p>It seems that when using the PrivateImplentationType property of the CodeMethodMethod the Name property gets used as the name of the method you are implementing, not the name of the function.</p> <p>How do you explicitly set the function name or at least how do I get it to be something legal?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload