コード例 #1
0
        /// <summary>
        /// Serialises all properties. The output will be a dictionary containing the
        /// objects properties in a form that can easily be converted to Json.
        /// </summary>
        ///
        /// <returns>The serialised object in dictionary form.</returns>
        public IDictionary <string, object> Serialise()
        {
            var dictionary = new Dictionary <string, object>();

            // Match Id
            dictionary.Add("MatchID", MatchId);

            // State
            dictionary.Add("State", State);

            // Turn Type
            dictionary.Add("TurnType", TurnType);

            // Turn Number
            if (TurnNumber != null)
            {
                dictionary.Add("TurnNumber", TurnNumber);
            }

            // Turn Timeout
            if (TurnTimeout != null)
            {
                dictionary.Add("TurnTimeout", TurnTimeout.Serialise());
            }

            // Waiting Timeout
            if (WaitingTimeout != null)
            {
                dictionary.Add("WaitingTimeout", WaitingTimeout.Serialise());
            }

            // Players
            if (Players != null)
            {
                var serialisedPlayers = JsonSerialisation.Serialise(Players, (Player element) =>
                {
                    return(element.Serialise());
                });
                dictionary.Add("Players", serialisedPlayers);
            }

            // Can Submit Turn
            dictionary.Add("CanSubmitTurn", CanSubmitTurn);

            // Date Created
            dictionary.Add("DateCreated", JsonSerialisation.Serialise(DateCreated));

            return(dictionary);
        }
コード例 #2
0
ファイル: Match.cs プロジェクト: zhangxinyu1120/Samples
        /// <summary>
        /// Serialises all properties. The output will be a dictionary containing the
        /// objects properties in a form that can easily be converted to Json.
        /// </summary>
        ///
        /// <returns>The serialised object in dictionary form.</returns>
        public IDictionary <string, object> Serialise()
        {
            var dictionary = new Dictionary <string, object>();

            // Match Id
            dictionary.Add("MatchID", MatchId);

            // Match Type Key
            dictionary.Add("MatchTypeKey", MatchTypeKey);

            // State
            dictionary.Add("State", State);

            // Write Lock
            dictionary.Add("WriteLock", WriteLock);

            // Properties
            if (Properties != null)
            {
                var serialisedProperties = JsonSerialisation.Serialise(Properties, (MultiTypeValue element) =>
                {
                    return(element.Serialise());
                });
                dictionary.Add("Properties", serialisedProperties);
            }

            // State Data
            if (StateData != null)
            {
                dictionary.Add("StateData", StateData.Serialise());
            }

            // Outcome Data
            if (OutcomeData != null)
            {
                dictionary.Add("OutcomeData", OutcomeData.Serialise());
            }

            // Turn Timeout
            if (TurnTimeout != null)
            {
                dictionary.Add("TurnTimeout", TurnTimeout.Serialise());
            }

            // Waiting Timeout
            if (WaitingTimeout != null)
            {
                dictionary.Add("WaitingTimeout", WaitingTimeout.Serialise());
            }

            // Turn Type
            dictionary.Add("TurnType", TurnType);

            // Turn Order Type
            if (TurnOrderType != null)
            {
                dictionary.Add("TurnOrderType", TurnOrderType);
            }

            // Player Limit
            if (PlayerLimit != null)
            {
                dictionary.Add("PlayerLimit", PlayerLimit);
            }

            // Players
            if (Players != null)
            {
                var serialisedPlayers = JsonSerialisation.Serialise(Players, (Player element) =>
                {
                    return(element.Serialise());
                });
                dictionary.Add("Players", serialisedPlayers);
            }

            // Auto Start
            dictionary.Add("AutoStart", AutoStart);

            // Is Private
            dictionary.Add("IsPrivate", IsPrivate);

            // Turn Number
            if (TurnNumber != null)
            {
                dictionary.Add("TurnNumber", TurnNumber);
            }

            // Last Turn
            if (LastTurn != null)
            {
                dictionary.Add("LastTurn", LastTurn.Serialise());
            }

            // Current Turn
            if (CurrentTurn != null)
            {
                dictionary.Add("CurrentTurn", CurrentTurn.Serialise());
            }

            // Created By
            if (CreatedBy != null)
            {
                dictionary.Add("CreatedBy", CreatedBy.Serialise());
            }

            // Date Created
            dictionary.Add("DateCreated", JsonSerialisation.Serialise(DateCreated));

            return(dictionary);
        }