私はtwitch chatボットに取り組んでいます。私のCommand.csクラスでは、私は奇妙な問題に遭遇しました。私はAction<string, User, Channel>
を取る1つのコンストラクタとFunc<string, User, Channel, bool>
を取るコンストラクタを持っています。最初のコンストラクタは、Action
を呼び出してtrueを返すFunc
で2番目のコンストラクタを呼び出すことになっています。これは両方のコンストラクタで7つのパラメータを使用していたときにうまくいきましたが、8番目のパラメータを追加するとコンパイルが中止されました。異なる量のコンストラクタパラメータを持つFuncとActionの間に不一致がありますか?
私が得るエラーはCS8030 "代理人を返す無効な関数は値を返すことができません"です。しかし、私が8番目のパラメータを追加する前に、コードはちょうど良いコンパイルでした
2つのスニペットの唯一の違いは、追加のdescription
パラメータを追加したことです。後
public class Command
{
public Command(string name, Action<string, User, Channel> action, bool adminOnly = false, bool modOnly = false, bool ownerOnly = false, bool hasUserCooldown = true, TimeSpan? cooldown = null, bool allowOtherCommands = false)
: this(name, (m, u, c) => { action(m, u, c); return true; }, adminOnly, modOnly, ownerOnly, hasUserCooldown, cooldown)
{
}
public Command(string name, Func<string, User, Channel, bool> action, bool adminOnly = false, bool modOnly = false, bool ownerOnly = false, bool hasUserCooldown = true, TimeSpan? cooldown = null, bool allowOtherCommands = false)
{
}
}
public class User { }
public class Channel { }
::前
public class Command
{
public Command(string name, Action<string, User, Channel> action, bool adminOnly = false, bool modOnly = false, bool ownerOnly = false, bool hasUserCooldown = true, TimeSpan? cooldown = null, bool allowOtherCommands = false, string description = null)
: this(name, (m, u, c) => { action(m, u, c); return true; }, adminOnly, modOnly, ownerOnly, hasUserCooldown, cooldown, description)
{
}
public Command(string name, Func<string, User, Channel, bool> action, bool adminOnly = false, bool modOnly = false, bool ownerOnly = false, bool hasUserCooldown = true, TimeSpan? cooldown = null, bool allowOtherCommands = false, string description = null)
{
}
}
public class User { }
public class Channel { }
はどうもありがとうございました。
はしかし、あなたの前と後のコードの間に違いを参照してくださいしないでください。 – Rahul
@Rahul allowOtherCommandsの後に "string description = null"というコンストラクタの最後にパラメータを追加しました – four