Pregunta

The Background

I have converted the C# code below (found in TreeViewAdv file TreeColumn.cs) into VB.net code using the converter found at DeveloperFusion.com.

C#

using System;
//...(other using calls)

namespace Aga.Controls.Tree
{
    [TypeConverter(typeof(TreeColumn.TreeColumnConverter)), DesignTimeVisible(false), ToolboxItem(false)]
    public class TreeColumn : Component
    {
        private class TreeColumnConverter : ComponentConverter
        {
            public TreeColumnConverter()
                : base(typeof(TreeColumn))
            {
            }

            public override bool GetPropertiesSupported(ITypeDescriptorContext context)
            {
                return false;
            }
        }
     }
    //…Some, I believe, unrelated code
}

VB

Imports System.Collections.Generic
‘...(other Imports calls)

Namespace Aga.Controls.Tree

    <TypeConverter(GetType(TreeColumn.TreeColumnConverter)), DesignTimeVisible(False), ToolboxItem(False)> _
    Public Class TreeColumn
        Inherits Component

        Private Class TreeColumnConverter
            Inherits ComponentConverter

            Public Sub New()
                MyBase.New(GetType(TreeColumn))
            End Sub

            Public Overrides Function GetPropertiesSupported(ByVal context As ITypeDescriptorContext) As Boolean
                Return False
            End Function
        End Class
    ‘...some, I believe, unrelated code
End Class

The Problem

Access to TreeColumn.TreeColumnConverter in this line of the C# code is fine. [TypeConverter(typeof(TreeColumn.TreeColumnConverter)), DesignTimeVisible(false), ToolboxItem(false)]

However, VB.Net does not allow access to that member in the converted line:

The error description reads: Aga.Controls.Tree.TreeColumn.TreeColumnConverter' is not accessible in this context because it is 'Private'. However, in both cases TreeColumn.TreeColumnConverter is declared Private.

The Question(s)

1.) The Why. As this is a learning project for me, I would like to know WHY the scopes are acting differently among the two languages. This is the more important question among the 2 of them.

2.) The How. What is the best way(s) to change the VB code to allow access of TreeColumnConverter to the identified line of code without opening up the scope to the point that it potentially creates naming confusions elsewhere? I COULD just declare it Public, but I imagine there is a more correct approach to this.

Things To Keep In Mind When Answering

1.) I know that in VB.net Private members are not available external to the object in which they were declared. So telling me this will not be helpful and in my mind is not an answer.

¿Fue útil?

Solución

To me, it looks like that the different compilers use different philosophies when dealing with nested private types. C# says its OK to access it from an attribute on the higher level type, VB.NET says it's not. Maybe those philosophies weren't even intentional.

Anyway, to fix it in VB.NET you could use the TypeConverterAttribute constructor that uses a string instead of a Type, and put the fully-qualified nested type name as a string:

<TypeConverter("Aga.Controls.Tree.TreeColumn.TreeColumnConverter"), DesignTimeVisible(False), ToolboxItem(False)> _
Public Class TreeColumn
  ...

Otros consejos

Ah, I believe I see your problem.

It's the namespaces.

VB.NET Chains the Namespaces.

Namespace Aga.Controls.Tree in vb.net would actually be your project's default namespace concatenated with the namespace declared in the file.

It would actually be Aga.Controls.Tree.Aga.Controls.Tree so it likely just can't get to the scope it needs to be because it's pointing to the wrong namespace.

C#, you fully qualify namespaces... DevFusion's converter (same as the one used in SharpDevelop IDE) doesn't know this.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top