.NET上的SignalR无法将派生类或接口的实现发送给客户端

时间:2019-02-27 20:27:13

标签: c# inheritance interface signalr

每个人。我目前正在尝试将派生类(或接口的实现)从服务器发送到客户端。我无法执行此操作,因为它不会在客户端中调用该方法。我试过取出继承并发送它,并且它确实可以正常工作,所以问题出在试图将派生类发送给客户端。预先感谢

以下是课程:

接口:

public interface ISquare
{
    Uri Image
    {
        get;
        set;
    }

    List<Player> PlayerList
    {
        get;
        set;
    }
}

实施方式:

public class Property: ISquare
{
    private Uri image { get; set; }
    private List<Player> playerList { get; set; }
    public int price { get; set; }
    public int nHouses { get; set; }
    public bool hasHotel { get; set; }
    public bool isBought { get; set; }
    public ColorProperty color { get; set; }
    public int moneyToPay { get; set; }
    public Player buyer { get; set; }
    public int squarePosition { get; set; }
    public Uri Image
    {
        get
        {
            return image;
        }

        set
        {
            image = value;
        }
    }
    public List<Player> PlayerList
    {
        get
        {
            return playerList;
        }

        set
        {
            playerList = value;
        }
    }

    public Property(int price, int nHouses, bool hasHotel, bool isBought, ColorProperty color, int moneyToPay, Player buyer, int squarePosition, Uri image, List<Player> playerList)
    {
        this.price = price;
        this.nHouses = nHouses;
        this.hasHotel = hasHotel;
        this.isBought = isBought;
        this.color = color;
        this.dineroAPagar = moneyToPay;
        this.buyer = buyer;
        this.squarePosition = squarePosition;
        this.image = image;
        this.playerList = playerList;
    }

    public Property(int price, ColorPropiedad color, int squarePosition)
    {
        this.price = price;
        this.nHouses = 0;
        this.hasHotel = false;
        this.isBought = false;
        this.color = color;
        this.dineroAPagar = 0;
        this.buyer = null;
        this.squarePosition = squarePosition;
        this.image = image;
        this.playerList = new List<Player>();
    }
}

public class Square : ISquare
{
    private Uri image { get; set; }
    public SquareType type { get; set; }
    private List<Player> playerList { get; set; }
    public Uri Image
    {
        get
        {
            return image;
        }

        set
        {
            image = value;
        }
    }
    public List<Player> playerList 
    {
        get
        {
            return playerList ;
        }

        set
        {
            playerList = value;
        }
    }

    public Square(SquareType type, List<Player> playerList)
    {
        this.type = type;
        this.playerList = playerList;
    }

    public Square(SquareType type)
    {
        this.image = null;
        this.type = type;
        this.playerList= new List<Player>();
    }

    public Square()
    {
        this.image = null;
        this.type = SquareType.PROPERTY;
        this.playerList = new List<Player>();
    }
}

这是客户端的样子:

private async void joinGame(Player playerServer)
    {
        await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
        () =>
        {
            if (playerServer != null)
            {
                _navigationService.Navigate(
                    typeof(GameView),
                    new PlayerWithLobby()
                    {
                        player = playerServer,
                        lobby = _lobby
                    }
                );
            }
            else
            {
                throw new NotImplementedException("Player is null");
            }
        }
        );
    }

0 个答案:

没有答案