CA1410: Metody registrace modelu COM by si měly odpovídat
Název_typu |
ComRegistrationMethodsShouldBeMatched |
CheckId |
CA1410 |
Kategorie |
Microsoft.interoperability |
Změnit rozdělení |
Bez rozdělení |
Příčina
Typ deklaruje metodu, která je označena ComRegisterFunctionAttribute atribut ale nedeklaruje metodu, která je označena ComUnregisterFunctionAttribute atribut, nebo naopak.
Popis pravidla
Objekt modelu COM (Component) klientům vytvořit .NET Framework typu, typ musí být nejprve registrována.Pokud je k dispozici, metoda, která je označena ComRegisterFunctionAttribute atributu se nazývá během procesu registrace spustit kód zadaný uživatelem.Odpovídající metodě, která je označena ComUnregisterFunctionAttribute atributu se nazývá během proces zrušení registrace ke stornování operace způsob registrace.
Jak opravit porušení
Porušení tohoto pravidla odstranit, přidáte odpovídající registraci nebo rušení registrace metody.
Při potlačení upozornění
Nepotlačovat upozornění od tohoto pravidla.
Příklad
Následující příklad ukazuje typ, který porušuje pravidlo.S komentářem kód ukazuje oprava porušení.
Imports System
Imports System.Runtime.InteropServices
<Assembly: ComVisibleAttribute(True)>
Namespace InteroperabilityLibrary
Public Class ClassToRegister
End Class
Public Class ComRegistration
<ComRegisterFunctionAttribute> _
Friend Shared Sub RegisterFunction(typeToRegister As Type)
End Sub
' <ComUnregisterFunctionAttribute> _
' Friend Shared Sub UnregisterFunction(typeToRegister As Type)
' End Sub
End Class
End Namespace
using System;
using System.Runtime.InteropServices;
[assembly: ComVisible(true)]
namespace InteroperabilityLibrary
{
public class ClassToRegister
{
}
public class ComRegistration
{
[ComRegisterFunction]
internal static void RegisterFunction(Type typeToRegister) {}
// [ComUnregisterFunction]
// internal static void UnregisterFunction(Type typeToRegister) {}
}
}
Souvisejících pravidel
CA1411: Metody registrace modelu COM by neměly být viditelné
Viz také
Referenční dokumentace
Regasm.exe (nástroj registrace sestavení)