Click here to Skip to main content
13,191,124 members (66,563 online)
Rate this:
Please Sign up or sign in to vote.
See more:
In the following code, why do the methods Register and Unregister require a type parameter?
using System.Runtime.InteropServices;
namespace Foo {
    public class Bar {
        private static void Register  (Type type) { ... }
        private static void Unregister(Type type) { ... }

I thought that perhaps it was because you only need one such function per assembly to register all of the types in that assembly, but that is not the case. No matter what I try (a class inheriting from Bar that is COM exportable, a subclass of Bar that is COM exportable, other unrelated classes that are COM exportable), the methods are only ever called once with (type == typeof(Bar)). I doubt the designers would require a useless parameter, so my question is, why is the type parameter required on these methods? Am I missing a case where the type parameter could differ from the class containing the method? Thanks,
Posted 1-Feb-12 15:19pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You are missing the case where the type parameter differs from the class containing the method.

using System.Runtime.InteropServices;
namespace Test {
    public abstract class A {
        public static void Register(Type type) {
        public static void Unregister(Type type) {
    public class B : A {

When registerring, the following method will be called:


Since the Register method is part of the class A, the call will be translated to


You may get problems when using typeof(class) instead of type argument.

Hope this help to someone.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171016.2 | Last Updated 21 May 2015
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100