C# - 缺少类对象的定义 - 怎么写?

时间:2014-02-19 11:01:28

标签: c# object definition overloading

这是我的源代码的一部分:

var result = DiceWebAPI.PlaceAutomatedBets(
                Session, baseBet, guessLow, guessHigh,
                betCount > Session.MaxBetBatchSize ? Session.MaxBetBatchSize : betCount,
                resetOnWin, resetOnLoss,
                increaseOnWin, increaseOnLoss,
                maxBet, resetOnMaxLoss, stopOnMaxLoss, stopMaxBalance);

viusal c#studio 2010表示:

Error   1   No overload for method 'PlaceAutomatedBets' takes 13 arguments  D:\Downloads\SampleBot_NET_3_5\SampleBot_NET_Source\Dice.Sample.Bot.3_5\Main.cs 359 30  DiceSampleBot35

我发现除了Session 1之外,方法的所有参数都有定义。谁能告诉我如何写作以及在何处放置定义?

也许这会有所帮助:

在另一个档案中

readonly SessionInfo Session;

和另一个

namespace Dice.Client.Web
{
public sealed class SessionInfo : INotifyPropertyChanged
{
    public string AccountCookie { get; }
    public long AccountId { get; }
    public decimal Balance { get; }
    public long BetCount { get; }
    public decimal BetPayIn { get; }
    public decimal BetPayOut { get; }
    public long BetWinCount { get; }
    public long ClientSeed { get; }
    public string DepositAddress { get; }
    public string Email { get; }
    public string EmergencyAddress { get; }
    public int MaxBetBatchSize { get; }
    public string SessionCookie { get; }
    public string Username { get; }

    public event PropertyChangedEventHandler PropertyChanged;
}
}

更新:

PlaceAutomatedBets ..定义

public static PlaceAutomatedBetsResponse PlaceAutomatedBets(SessionInfo session, AutomatedBetsSettings settings);

4 个答案:

答案 0 :(得分:0)

你需要去PlaceAutomatedBets方法,你会发现你的PlaceAutomatedBets只需要12个参数,你需要添加一个缺失的参数。

答案 1 :(得分:0)

你正在传递额外的论点。例外是自我解释的。并且无需重新定义HttpContext.Session Property System.Web已经存在于Using System.Web;中,如果您尚未包含此内容,请将此行放在您的课​​程{{1}}上

答案 2 :(得分:0)

这里的问题是你正在调用一个具有两个参数签名的方法:

public static PlaceAutomatedBetsResponse PlaceAutomatedBets(
             SessionInfo session,     
             AutomatedBetsSettings settings);

但是,你用12:

来调用它
var result = DiceWebAPI.PlaceAutomatedBets(
            Session, baseBet, guessLow, guessHigh,
            betCount > Session.MaxBetBatchSize ? Session.MaxBetBatchSize : betCount,
            resetOnWin, resetOnLoss,
            increaseOnWin, increaseOnLoss,
            maxBet, resetOnMaxLoss, stopOnMaxLoss, stopMaxBalance);

C#无法获取您的12个参数并自动将它们形成对象。相反,您必须构建一个AutomatedBetsSettings对象并将其传递给Session。这在软件设计中非常标准,您希望减少参数的数量。具有所有细节的对象通常称为上下文。

例如,您需要执行以下操作:

// I am guessing the content of AutomatedBetsSettings here, you will need
// to check the actual property values.
var betSettingsContext = new AutomatedBetsSettings() {
            BaseBet = baseBet, 
            GuessLow = guessLow, 
            GuessHigh = guessHigh,
            BestCount = betCount > Session.MaxBetBatchSize ? Session.MaxBetBatchSize : betCount,
            ResetOnWin = resetOnWin, 
            ResetOnLoss = resetOnLoss,
            IncreaseOnWin = increaseOnWin, 
            IncreaseOnLoss = increaseOnLoss,
            MaxBet = maxBet, 
            ResetOnMaxLoss = resetOnMaxLoss, 
            StopOnMaxLoss =  stopOnMaxLoss, 
            StopMaxBalance = stopMaxBalance
};
var result = DiceWebAPI.PlaceAutomatedBets(Session, betSettingsContext);

答案 3 :(得分:0)

尝试使用这样的方法。

var result = DiceWebAPI.PlaceAutomatedBets(
            HttpContext.Current.Session, baseBet, guessLow, guessHigh,
            betCount > Session["MaxBetBatchSize"] ? Session["MaxBetBatchSize"] : betCount,
            resetOnWin, resetOnLoss,
            increaseOnWin, increaseOnLoss,
            maxBet, resetOnMaxLoss, stopOnMaxLoss, stopMaxBalance);