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.
C# Private Access Modifier In c#, the private modifier is used to specify that access is limited to the containing type, so the defined type or member can only be accessed by the code in the same class or structure. Following is the example of defining members with a private modifier in the c# programming language.
In Kotlin, we can define a class member as private, internal, public or protected. These are also called visibility modifiers. It defines the scope from where we can access a member. In this tutorial, we will learn how these visibility modifiers works with examples.
There are total 3 types of visibility mode in C++ that are: We will learn more in detail using the examples: 1. Private visibility mode: When we inherit a derived class from the base class with private visibility mode then the public and protected members of the base class become private members of the derived class.
Private visibility mode: When we inherit a derived class from the base class with private visibility mode then the public and protected members of the base class become private members of the derived class. 2. Protected visibility mode:
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
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With