だから私はいくつかの重いオーバーロードを伴うメソッドを持っています。ただし、概念はかなり単純です。「最初の引数としてXデータ型のいずれかを受け入れ、次に残りの2つの引数に対してこれら2つのデータ型のいずれかを受け入れます」。これを行うためのより簡単な方法はありますか?これは非常に速く手に負えなくなっています。
//Declared MyMethod(byte[], SpecializedArgumentType, SpecializedArgumentType) and a string-> SpecializedArgumentType version of it.
public static MyReturnType MyMethod(bool data, SpecializedArgumentType firstArg, SpecializedArgumentType secondArg)
{
return MyMethod(BitConverter.GetBytes(data), firstArg, secondArg);
}
public static MyReturnType MyMethod(bool data, String firstArg, String secondArg)
{
return MyMethod(BitConverter.GetBytes(data), firstArg, secondArg);
}
public static MyReturnType MyMethod(short data, SpecializedArgumentType firstArg, SpecializedArgumentType secondArg)
{
return MyMethod(BitConverter.GetBytes(data), firstArg, secondArg);
}
public static MyReturnType MyMethod(short data, String firstArg, String secondArg)
{
return MyMethod(BitConverter.GetBytes(data), firstArg, secondArg);
}
public static MyReturnType MyMethod(ushort data, SpecializedArgumentType firstArg, SpecializedArgumentType secondArg)
{
return MyMethod(BitConverter.GetBytes(data), firstArg, secondArg);
}
public static MyReturnType MyMethod(ushort data, String firstArg, String secondArg)
{
return MyMethod(BitConverter.GetBytes(data), firstArg, secondArg);
}
public static MyReturnType MyMethod(int data, SpecializedArgumentType firstArg, SpecializedArgumentType secondArg)
{
return MyMethod(BitConverter.GetBytes(data), firstArg, secondArg);
}
public static MyReturnType MyMethod(int data, String firstArg, String secondArg)
{
return MyMethod(BitConverter.GetBytes(data), firstArg, secondArg);
}
public static MyReturnType MyMethod(uint data, SpecializedArgumentType firstArg, SpecializedArgumentType secondArg)
{
return MyMethod(BitConverter.GetBytes(data), firstArg, secondArg);
}
public static MyReturnType MyMethod(uint data, String firstArg, String secondArg)
{
return MyMethod(BitConverter.GetBytes(data), firstArg, secondArg);
}
public static MyReturnType MyMethod(long data, SpecializedArgumentType firstArg, SpecializedArgumentType secondArg)
{
return MyMethod(BitConverter.GetBytes(data), firstArg, secondArg);
}
public static MyReturnType MyMethod(long data, String firstArg, String secondArg)
{
return MyMethod(BitConverter.GetBytes(data), firstArg, secondArg);
}
public static MyReturnType MyMethod(ulong data, SpecializedArgumentType firstArg, SpecializedArgumentType secondArg)
{
return MyMethod(BitConverter.GetBytes(data), firstArg, secondArg);
}
public static MyReturnType MyMethod(ulong data, String firstArg, String secondArg)
{
return MyMethod(BitConverter.GetBytes(data), firstArg, secondArg);
}
public static MyReturnType MyMethod(float data, SpecializedArgumentType firstArg, SpecializedArgumentType secondArg)
{
return MyMethod(BitConverter.GetBytes(data), firstArg, secondArg);
}
public static MyReturnType MyMethod(float data, String firstArg, String secondArg)
{
return MyMethod(BitConverter.GetBytes(data), firstArg, secondArg);
}
public static MyReturnType MyMethod(double data, SpecializedArgumentType firstArg, SpecializedArgumentType secondArg)
{
return MyMethod(BitConverter.GetBytes(data), firstArg, secondArg);
}
public static MyReturnType MyMethod(double data, String firstArg, String secondArg)
{
return MyMethod(BitConverter.GetBytes(data), firstArg, secondArg);
}
public static MyReturnType MyMethod(char data, SpecializedArgumentType firstArg, SpecializedArgumentType secondArg)
{
return MyMethod(BitConverter.GetBytes(data), firstArg, secondArg);
}
public static MyReturnType MyMethod(char data, String firstArg, String secondArg)
{
return MyMethod(BitConverter.GetBytes(data), firstArg, secondArg);
}
データ型として任意のオブジェクトを取り込もうとしましたが、オートコンプリート(Visual studioのctrl-space)で明示的なデータ型を取得できません。これは本当に冗長で維持するのが難しい必要がありますか?たぶん、最初の問題への私のアプローチは修正が必要ですか?