static private AttributeValue GetAttributeValue(IfcPropertyBoundedValue ifcPropertyBoundedValue)
        {
            var ifcValue = ifcPropertyBoundedValue.LowerBoundValue;

            //only upper and lowwer bounds are supported by COBie on integer and decimal values
            if (ifcValue.UnderlyingSystemType == typeof(int) || ifcValue.UnderlyingSystemType == typeof(long) || ifcValue.UnderlyingSystemType == typeof(short) || ifcValue.UnderlyingSystemType == typeof(byte) ||
                ifcValue.UnderlyingSystemType == typeof(int?) || ifcValue.UnderlyingSystemType == typeof(long?) || ifcValue.UnderlyingSystemType == typeof(short?) || ifcValue.UnderlyingSystemType == typeof(byte?))
            {
                var integerValue = new IntegerAttributeValue();
                if (ifcPropertyBoundedValue.UpperBoundValue != null)
                {
                    integerValue.MaximalValue = Convert.ToInt32(ifcPropertyBoundedValue.UpperBoundValue.Value);
                }
                if (ifcPropertyBoundedValue.LowerBoundValue != null)
                {
                    integerValue.MinimalValue = Convert.ToInt32(ifcPropertyBoundedValue.LowerBoundValue.Value);
                }
                return(integerValue);
            }
            if (ifcValue.UnderlyingSystemType == typeof(double) || ifcValue.UnderlyingSystemType == typeof(float) ||
                ifcValue.UnderlyingSystemType == typeof(double?) || ifcValue.UnderlyingSystemType == typeof(float?))
            {
                var decimalValue = new DecimalAttributeValue();
                if (ifcPropertyBoundedValue.UpperBoundValue != null)
                {
                    decimalValue.MaximalValue = (double)ifcPropertyBoundedValue.UpperBoundValue.Value;
                }
                if (ifcPropertyBoundedValue.LowerBoundValue != null)
                {
                    decimalValue.MinimalValue = (double)ifcPropertyBoundedValue.LowerBoundValue.Value;
                }
                return(decimalValue);
            }
            return(null);
        }
Exemple #2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
                                        JsonSerializer serializer)
        {
            var jObject = JObject.Load(reader);

            if (jObject == null)
            {
                return(null);
            }

            var result = new Attribute();

            //remove this converter to do regular conversion
            serializer.Converters.Remove(this);
            try
            {
                //this will populate everything except the value itself
                serializer.Populate(jObject.CreateReader(), result);

                //get value property, populate it into proper type and add to attribute
                AttributeValue value;
                var            strType = jObject.GetValue("StringAttributeValue");
                if (strType != null)
                {
                    value = new StringAttributeValue();
                    serializer.Populate(strType.CreateReader(), value);
                    result.Value = value;
                    return(result);
                }
                var decType = jObject.GetValue("DecimalAttributeValue");
                if (decType != null)
                {
                    value = new DecimalAttributeValue();
                    serializer.Populate(decType.CreateReader(), value);
                    result.Value = value;
                    return(result);
                }
                var boolType = jObject.GetValue("BooleanAttributeValue");
                if (boolType != null)
                {
                    value = new BooleanAttributeValue();
                    serializer.Populate(boolType.CreateReader(), value);
                    result.Value = value;
                    return(result);
                }
                var intType = jObject.GetValue("IntegerAttributeValue");
                if (intType != null)
                {
                    value = new IntegerAttributeValue();
                    serializer.Populate(intType.CreateReader(), value);
                    result.Value = value;
                    return(result);
                }
                var dateType = jObject.GetValue("DateTimeAttributeValue");
                if (dateType != null)
                {
                    value = new DateTimeAttributeValue();
                    serializer.Populate(dateType.CreateReader(), value);
                    result.Value = value;
                    return(result);
                }
            }
            finally
            {
                //add converter back again
                serializer.Converters.Add(this);
            }
            return(result);
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
            JsonSerializer serializer)
        {
            var jObject = JObject.Load(reader);
            if (jObject == null) return null;

            var result = new Attribute();

            //remove this converter to do regular conversion
            serializer.Converters.Remove(this);
            try
            {
                //this will populate everything except the value itself
                serializer.Populate(jObject.CreateReader(), result);

                //get value property, populate it into proper type and add to attribute
                AttributeValue value;
                var strType = jObject.GetValue("StringAttributeValue");
                if (strType != null)
                {
                    value = new StringAttributeValue();
                    serializer.Populate(strType.CreateReader(), value);
                    result.Value = value;
                    return result;
                }
                var decType = jObject.GetValue("DecimalAttributeValue");
                if (decType != null)
                {
                    value = new DecimalAttributeValue();
                    serializer.Populate(decType.CreateReader(), value);
                    result.Value = value;
                    return result;
                }
                var boolType = jObject.GetValue("BooleanAttributeValue");
                if (boolType != null)
                {
                    value = new BooleanAttributeValue();
                    serializer.Populate(boolType.CreateReader(), value);
                    result.Value = value;
                    return result;
                }
                var intType = jObject.GetValue("IntegerAttributeValue");
                if (intType != null)
                {
                    value = new IntegerAttributeValue();
                    serializer.Populate(intType.CreateReader(), value);
                    result.Value = value;
                    return result;
                }
                var dateType = jObject.GetValue("DateTimeAttributeValue");
                if (dateType != null)
                {
                    value = new DateTimeAttributeValue();
                    serializer.Populate(dateType.CreateReader(), value);
                    result.Value = value;
                    return result;
                }
            }
            finally
            {
                //add converter back again
                serializer.Converters.Add(this);
            }
            return result;
        }