view datagear/command/CommandType.cs @ 17:4a3115ba746d

fix CommandType enum
author riono <e165729@ie.u-ryukyu.ac.jp>
date Tue, 24 Nov 2020 03:11:50 +0900
parents 7352793b5dbe
children 8fe565f8acb8
line wrap: on
line source

using System;
using System.Collections.Generic;

namespace Christie_net.datagear.command {
public class CommandType {
    private static int lastId = 0; // コマンドの総数
    public readonly int id = ++lastId; // コマンドのid コンストラクタが呼ばれるたびにlastIdが++される
    public static readonly Dictionary<int, CommandType> hash = new Dictionary<int, CommandType>();

    private CommandType() {
        hash.Add(this.id, this);
    }

    /// <summary>
    /// idよりCommandTypeを返す
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    public static CommandType GetCommandTypeFromId(int id) {
        return hash[id];
    }

    public static readonly CommandType PUT = new CommandType();
    public static readonly CommandType TAKE = new CommandType();
    public static readonly CommandType PEEK = new CommandType();
    public static readonly CommandType REMOTETAKE = new CommandType();
    public static readonly CommandType REMOTEPEEK = new CommandType();
    public static readonly CommandType REPLY = new CommandType();
    public static readonly CommandType CLOSE = new CommandType();
    public static readonly CommandType FINISH = new CommandType();
}
}