dotnet / dotnet/dotnet-api-docs
Type.GUID missing GuidAttribute example
- Vorherrschende Sprache
- C#
- Sterne
- 949
- Forks
- 1.7k
- Ø Merge
- 2 T. 19 Std.
- Gemergte PRs (30 T.)
- 52
Beschreibung
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
}
```
Beitragsleitfaden
Rechercherichtung
Das Issue betrifft die API-Dokumentation von Type.GUID. Beginne auf der Referenzseite zu Type.GUID und überprüfe die aktuellen Beispiele und Anmerkungen. Füge gezielte C#-Hinweise zur im Issue dargestellten Beziehung zu GuidAttribute hinzu und überprüfe anschließend die gerenderte Dokumentation und die verlinkten Verweise.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- csharp
- Bereich
- documentation
- Issue-Typ
- Dokumentation
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100