O'Reilly logo

Professional .NET 2.0 Generics by Tod Golding

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

9.3. Remoting

Generics can also be incorporated into solutions that access remote objects. In fact, generics have some fairly useful applications for remoting solutions. Consider, for example, the interfaces you define for your remote types. The application of generic interfaces to these types allows you to have a single interface that can support a much broader range of types. So, instead of building separate interfaces or overloading methods heavily, your generic interface can support a wider spectrum of possible data types with a single interface.

To illustrate this point, assemble a simple example that employs a generic remote interface. The first step in this process is to create a generic interface that will become the interface you use for interacting with a remote object:

[VB code]
Namespace RemoteGenericInterfaces
    Public Interface IRemoteGenericInterface(Of T)
        Function RemoteMethod(ByVal param As T) As T
    End Interface
End Namespace
[C# code]
namespace RemoteGenericInterfaces {
    public interface IRemoteGenericInterface<T> {
        T RemoteMethod(T param);
    }
}

This generic interface exposes a single method that accepts a parameter of type T and returns a value of type T. As you can see, this interface is the same as any other generic interface you might have seen. There's certainly nothing you need to do to make it usable for remote objects. Now, let's look at a class that will implement this class on a remote server:

[VB code] Namespace RemoteGenerics Friend Class RemoteClass(Of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required