今回もChatGPTの話です。
自分が作成したソースコードをChatGPTに与えてどのようなことが出来るか試しました。
本家ChatGPTとBingChatで試しています。
(1)XMLコメントを作成
質問内容
以下のC#コードのXMLコメントを日本語で作成して
public static Color Blend(this Color color, Color blendColor, double ratio) {
if (ratio.IsBetween(0.0, 1.0).Not()) throw new FormatException();
int a, r, g, b;
a = color.A + ((blendColor.A - color.A).ToDbl() * ratio).ToInt();
r = color.R + ((blendColor.R - color.R).ToDbl() * ratio).ToInt();
g = color.G + ((blendColor.G - color.G).ToDbl() * ratio).ToInt();
b = color.B + ((blendColor.B - color.B).ToDbl() * ratio).ToInt();
return Color.FromArgb(a, r, g, b);
}
結果 ChatGPT

結果 BingChat

ちゃんとコードを理解してXMLコメントを作成できています。
すばらしいです。
(2)サンプルコードを作成
質問内容
以下のC#のBlendメソッドの使用例を作成して
public static Color Blend(this Color color, Color blendColor, double ratio) {
if (ratio.IsBetween(0.0, 1.0).Not()) throw new FormatException();
int a, r, g, b;
a = color.A + ((blendColor.A - color.A).ToDbl() * ratio).ToInt();
r = color.R + ((blendColor.R - color.R).ToDbl() * ratio).ToInt();
g = color.G + ((blendColor.G - color.G).ToDbl() * ratio).ToInt();
b = color.B + ((blendColor.B - color.B).ToDbl() * ratio).ToInt();
return Color.FromArgb(a, r, g, b);
}
結果 ChatGPT

結果 BingChat

これも完璧です。
—–
このようなことが出来るのであれば、自力でドキュメントやサンプルコードなどを用意しなくても良くなるので、今よりも開発に専念できます。
とりあえずは、ChatGPTを使用して自動でXMLコメントを挿入するVisualStudioプラグインを作成したいですね。