dotnet / dotnet/dotnet-api-docs
Type.GUID missing GuidAttribute example
- 主要言語
- C#
- スター
- 950
- フォーク
- 1.7k
- 平均マージ
- 2日 19時間
- マージ済み PR(30日)
- 52
説明
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
}
```
コントリビューションガイド
調査の方向性
この issue は Type.GUID API ドキュメントに関するものです。Type.GUID リファレンス ページから始め、現在の例と解説を確認してください。issue で示されている GuidAttribute との関係を扱う、焦点を絞った C# のガイダンスを追加し、その後、レンダリングされたドキュメントと参照されているリンクを確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- csharp
- 領域
- documentation
- issue の種類
- ドキュメント
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100