dotnet / dotnet/dotnet-api-docs
Type.GUID missing GuidAttribute example
- Lenguaje dominante
- C#
- Estrellas
- 950
- Forks
- 1.7k
- Merge medio
- 2 d 19 h
- PR fusionados (30 d)
- 52
Descripción
A common use case in writing COM add-ins for Excel is to use ComRegisterFunctionAttribute, and register/un-register the add-in. While the below code sample is non-exemplary and has many dubious practices, it does illustrate a problem I'm stuck with in some code I have to maintain, and my hope is better documentation for `Type.GUID` will maybe save one other engineer some trouble at some point in the future.
Other relevant documentation: [CLSID Key](https://docs.microsoft.com/en-us/windows/win32/com/clsid-key-hklm)
```c#
[ClassInterface(ClassInterfaceType.AutoDual), ComVisible(true)]
public class SynchronousClient
{
#region Just for debugging
public int MyTest(int a, int b)
{
return (a + b);
}
#endregion
#region Excel Addin Registry realted functions
[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type type)
{
Registry.ClassesRoot.CreateSubKey(GetSubKeyName(type));
}
[ComUnregisterFunctionAttribute]
public static void UnregisterFunction(Type type)
{
Registry.ClassesRoot.DeleteSubKey(GetSubKeyName(type), false);
}
private static string GetSubKeyName(Type type)
{
// (!) This is really bad, because this type's GUID doesn't have [GuidAttribute], so we have know way to know which CLSID in the registry this dll will get registered under.
string s = @"CLSID\{" + type.GUID.ToString().ToUpper() + @"}\Programmable";
return s;
}
#endregion
}
```
Guía de contribución
Línea de trabajo
El issue se refiere a la documentación de la API de Type.GUID; comienza en la página de referencia de Type.GUID y revisa sus ejemplos y observaciones actuales. Añade orientación específica para C# sobre la relación con GuidAttribute ilustrada por el issue y, a continuación, verifica la documentación renderizada y los enlaces referenciados.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- csharp
- Área
- documentation
- Tipo de issue
- Documentación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100