Esempio n. 1
0
        // $G$ CSS-010 (-5) Bad public/protected method name. Should be PascalCased.
        public override void setProperty(int i_Property, string i_InputFromUserStr)
        {
            eFuelEngineProperties property = (eFuelEngineProperties)i_Property;
            float inputFromUserFloat;
            int   inputFromUserInt;

            switch (property)
            {
            case eFuelEngineProperties.FuelType:
            {
                if (int.TryParse(i_InputFromUserStr, out inputFromUserInt))
                {
                    if (Enum.IsDefined(typeof(eFuelType), inputFromUserInt))
                    {
                        if ((eFuelType)inputFromUserInt != m_FuelType)
                        {
                            throw new ArgumentException("Wrong fuel type!");
                        }
                    }
                    else
                    {
                        throw new ValueOutOfRangeException(1, Enum.GetNames(typeof(eFuelType)).Length, "You have enterd out of range input!");
                    }
                }
                else
                {
                    throw new FormatException("You have enterd wrong input!");
                }

                break;
            }

            case eFuelEngineProperties.CurrentAmount:
            {
                if (float.TryParse(i_InputFromUserStr, out inputFromUserFloat))
                {
                    // $G$ SFN-999 (-2) You need to ensure the input is positive.
                    CurrenteEnergy = inputFromUserFloat;
                }
                else
                {
                    throw new FormatException("You have enterd wrong input!");
                }

                break;
            }
            }
        }
Esempio n. 2
0
        public override void SetProperty(int i_Property, string i_InputFromUser)
        {
            eFuelEngineProperties property = (eFuelEngineProperties)i_Property;
            float inputFromUserFloat;
            int   inputFromUserInt;

            switch (property)
            {
            case eFuelEngineProperties.FuelType:
                if (int.TryParse(i_InputFromUser, out inputFromUserInt))
                {
                    if (Enum.IsDefined(typeof(eFuelKind), inputFromUserInt))
                    {
                        if ((eFuelKind)inputFromUserInt != r_FuelKind)
                        {
                            throw new ArgumentException("Wrong fuel type!");
                        }
                    }
                    else
                    {
                        throw new ValueOutOfRangeException(1, Enum.GetNames(typeof(eFuelKind)).Length, "You have entered out of range input!");
                    }
                }
                else
                {
                    throw new FormatException("You have entered wrong input!");
                }

                break;

            case eFuelEngineProperties.CurrentAmount:
                if (float.TryParse(i_InputFromUser, out inputFromUserFloat) && inputFromUserFloat >= 0)
                {
                    CurrentEnergy = inputFromUserFloat;
                }
                else
                {
                    throw new FormatException("You have entered wrong input!");
                }

                break;
            }
        }