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); }
public void CobieAttributesCreation() { int i = 1; var attI = AttributeValue.CreateFromObject(i); Int16 i16 = 13; attI = AttributeValue.CreateFromObject(i16); Int32 i32 = 13; attI = AttributeValue.CreateFromObject(i32); DateTime d = DateTime.Now; var attD = AttributeValue.CreateFromObject(i); string s = "Yes"; var attS = AttributeValue.CreateFromObject(s); bool b = true; var attB = AttributeValue.CreateFromObject(b); double dbl = 3.14; var attDbl = AttributeValue.CreateFromObject(dbl); AttributeValue dAt = new DecimalAttributeValue() { Value = Math.E }; var fromA = AttributeValue.CreateFromObject(dAt); }
/// <summary> /// /// </summary> /// <param name="ifcProperty"></param> /// <returns></returns> public static AttributeValue GetAttributeValueType(IIfcPropertySingleValue ifcProperty) { var ifcValue = (IExpressValueType)ifcProperty.NominalValue; if (ifcValue == null) { return(null); } if (ifcValue is IfcMonetaryMeasure) { var moneyAttribute = new DecimalAttributeValue { Value = (double)ifcValue.Value }; if (!(ifcProperty.Unit is IIfcMonetaryUnit)) { return(null); } var mu = (IIfcMonetaryUnit)ifcProperty.Unit; moneyAttribute.Unit = mu.ToString(); } else if (ifcValue is IfcTimeStamp) { var timeStamp = (IfcTimeStamp)ifcValue; return(new DateTimeAttributeValue { Value = timeStamp.ToDateTime() }); } else if (ifcValue.UnderlyingSystemType == typeof(int) || ifcValue.UnderlyingSystemType == typeof(long) || ifcValue.UnderlyingSystemType == typeof(short) || ifcValue.UnderlyingSystemType == typeof(byte)) { return(new IntegerAttributeValue { Value = Convert.ToInt32(ifcValue.Value) }); } else if (ifcValue.UnderlyingSystemType == typeof(double) || ifcValue.UnderlyingSystemType == typeof(float)) { return(new DecimalAttributeValue { Value = (double)ifcValue.Value }); } else if (ifcValue.UnderlyingSystemType == typeof(string)) { return(new StringAttributeValue { Value = ifcValue.ToString() }); } else if (ifcValue.UnderlyingSystemType == typeof(bool) || ifcValue.UnderlyingSystemType == typeof(bool?)) { if (ifcValue.Value != null && (bool)ifcValue.Value) { return(new BooleanAttributeValue { Value = (bool)ifcValue.Value }); } return(new BooleanAttributeValue());//return an undefined } return(null); }
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; }