コード例 #1
0
        public override void SetSafetyNumberVariable(int index, int value)
        {
            switch (index)
            {
            case 1:
            {
                var bytes = value.ToBytes(Endian.Environment);
                IsElseCase = (bytes[0] & 0xF0) != 0;
                ConditionList.AdjustLength(bytes[0] & 0x0F);
                return;
            }

            default:
                // 選択肢1~15のLeftSide/RightSide/ConditionFlag

                var exception = new ArgumentOutOfRangeException(
                    ErrorMessage.OutOfRange(nameof(index), 0, NumberVariableCount - 1, index));

                var caseNum = (index - 2) / 3;
                if (caseNum >= ConditionList.Count)
                {
                    throw exception;
                }

                var propNum = (index - 2) % 3;

                switch (propNum)
                {
                case 0:
                    ConditionList[caseNum].LeftSide = value;
                    return;

                case 1:
                    ConditionList[caseNum].RightSide = value;
                    return;

                default:         // case 2
                {
                    var bytes = value.ToBytes(Endian.Environment);
                    ConditionList[caseNum].IsNotReferX = (bytes[0] & 0xF0) != 0;
                    ConditionList[caseNum].Condition   =
                        NumberConditionalOperator.FromByte((byte)(bytes[0] & 0x0F));
                    return;
                }
                }
            }
        }