Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any VBNET equivalence of C# where generic constraint keyword?

First, I wish to write myself a generic type for operations against the underlying Active Directory.

For those of you who know about AD and the System.DirectoryServices namespace, the DirectoryEntry class is the top most important along with the DirectorySearcher class.

When speaking the AD language, everything is a DirectoryEntry. With that said, my application needs to manage Users, Groups and Organizational Units (OU). Each of these objects are AD entries. Then, this sounds to me a good candidate for GenericTypes.

What I wish to accomplish is this:

public interface ITop {
    string Path { get; set; }
    string ObjectClass { get; }
    string ContainerName { get; set; }
    // [...]
}

public interface IGroup : ITop {
    // Speciality properties here...
}

public interface IUser : ITop {
    // Speciality properties here...
}

// And so forth...

public sealed class DirectorySource<T> where T : ITop {
    // Methods against AD here...
}

My class library MUST respond to the following organical criterion:

  1. VS2005 VBNET
  2. .NET 2.0
  3. Active Directory
  4. Windows Forms

Well, I guess I have already given too much details for the purpose of my question, but any suggestion on the architecture and design patterns are welcome as well. My question is:

Is there a VBNET 2.0 equivalence of C# where (generic type constraint) keyword, or any best practice workarounds?

The results of my searches seem to end with the undoable conclusion. So I'm asking...

like image 466
Will Marcouiller Avatar asked May 10 '10 15:05

Will Marcouiller


People also ask

Is VB.NET the same as C#?

VB.NET and C# are syntactically different programming languages with different history but both the languages are part of the . NET framework development platform and maintained by Microsoft. Both these .

Which is better VB.NET or C#?

When you will go for a job in Programming then C# will be the better choice. If you first want to learn then VB could be the better choice - it depends on what is better readable for you. In both cases : what you have to learn is not the programming-language - what you have to learn is the use of the .

What's the C# equivalent to the WITH statement in VB?

Aside from object initializers (usable only in constructor calls), the best you can get is: var it = Stuff.

Can you convert VB to C?

The VB to C# code converter from the SharpDevelop team is now a standalone extension to Visual Studio. Once installed, you can convert an entire VB.NET project to C# by opening the solution, right clicking the solution node in the Solution Explorer and selecting Convert to C#.


1 Answers

Like this:

Public Class DirectorySource(Of T As ITop)

Multiple constraints are enclosed by braces, like this:

Public Class DirectorySource(Of T As { ITop, IDisposable, Class, New })
like image 149
SLaks Avatar answered Sep 23 '22 05:09

SLaks