示例#1
0
        public virtual void AddSubstance(ISubstance substance, int sortOrder, IUnitValue quanity)
        {
            if (ContainsSubstance(substance))
            {
                return;
            }

            _substances.Add(ProductSubstance.Create(sortOrder, this, (Substance)substance, (UnitValue)quanity));
        }
示例#2
0
        /// <summary> 获取显示值 </summary>
        public string GetView(double value)
        {
            IUnitValue uv = Activator.CreateInstance(this.UnitType) as IUnitValue;

            if (uv == null)
            {
                return(value.ToString());
            }

            return(uv.GetView(value));
        }
示例#3
0
        /// <summary> 根据当前单位返回值 </summary>
        bool TryGetValue(string value, out double d, out string message)
        {
            message = string.Empty;

            d = double.NaN;

            if (string.IsNullOrEmpty(value))
            {
                message = "参数不能为空";
                return(false);
            }

            IUnitValue uv = Activator.CreateInstance(this.UnitType) as IUnitValue;

            if (uv == null)
            {
                if (!double.TryParse(value?.ToString(), out d))
                {
                    message = "不是double的有效类型";
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            bool result = uv.TryParse(value, out d, out message);

            if (!result)
            {
                if (string.IsNullOrEmpty(message))
                {
                    message = "转换限制类型错误" + this.UnitType;
                }
                return(false);
            }

            return(true);
        }