Click here to Skip to main content
15,891,375 members

Why Does a Method with the ComRegisterFunctionAttribute Take a Type Parameter?

Skippums asked:

Open original thread
In the following code, why do the methods Register and Unregister require a type parameter?
using System.Runtime.InteropServices;

namespace Foo {
    [Guid("...")]
    [ComVisible(true)]
    public class Bar {
        [ComRegisterFunction]
        private static void Register  (Type type) { ... }

        [ComUnregisterFunction]
        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,
Tags: COM, DLL

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900