dotnet / dotnet/dotnet-api-docs
Type.GUID missing GuidAttribute example
- Lingua principale
- C#
- Stelle
- 949
- Fork
- 1.7k
- Merge medio
- 2g 19h
- PR unite (30g)
- 52
Descrizione
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
}
```
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
La issue riguarda la documentazione dell'API di Type.GUID; inizia dalla pagina di riferimento di Type.GUID e rivedi gli esempi e le osservazioni attuali. Aggiungi indicazioni mirate per C# sulla relazione con GuidAttribute illustrata dalla issue, quindi verifica la documentazione renderizzata e i link referenziati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- csharp
- Ambito
- documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100