private string ConvertToString(IIfcPropertySingleValue ifcProperty) { IIfcValue ifcValue = ifcProperty.NominalValue; if (ifcValue == null) { return(null); } var expressValue = (IExpressValueType)ifcValue; var underlyingType = expressValue.UnderlyingSystemType; if (ifcValue is Xbim.Ifc4.DateTimeResource.IfcTimeStamp) { var timeStamp = (Xbim.Ifc4.DateTimeResource.IfcTimeStamp)ifcValue; return(WriteDateTime(timeStamp.ToDateTime())); } if (underlyingType == typeof(bool) || underlyingType == typeof(bool?)) { if (expressValue.Value != null && (bool)expressValue.Value) { return("yes"); } return("no"); } // all other cases will convert to a string return(expressValue.Value.ToString()); }
public static DataConcept ToDataConcept(this IIfcValue v, DataOp dataOp = DataOp.Equals) { if (v.UnderlyingSystemType.IsPrimitive) { if (v.UnderlyingSystemType == typeof(double) || v.UnderlyingSystemType == typeof(float)) { return new DataConcept { Op = dataOp, Digit = (double)v.Value, Type = DataType.Decimal } } ; else if (v.UnderlyingSystemType == typeof(long) || v.UnderlyingSystemType == typeof(int)) { return new DataConcept { Op = dataOp, Digit = (double)v.Value, Type = DataType.Integer } } ; else if (v.UnderlyingSystemType == typeof(string)) { return new DataConcept { Op = dataOp, Serialized = v.Value?.ToString(), Type = DataType.String } } ; } throw new NotImplementedException($"Missing implementation for '{v.GetType().Name}'"); } }
public static string getDefaultIfcUnitStr(IIfcValue value) { // Initialize the static Dicts, if it is still empty upon the first use. These Dicts do not need to be reset setupUnitRep(); if (value != null) { return(getDefaultIfcUnitStr(value.GetType())); } else { return(null); } }
private static AttributeValueType GetAttributeValue(IIfcPropertyBoundedValue ifcPropertyBoundedValue) { var attributeValueType = new AttributeValueType(); IIfcValue ifcValue = ifcPropertyBoundedValue.LowerBoundValue; var expressValue = (IExpressValueType)ifcValue; var underlyingType = expressValue.UnderlyingSystemType; //only upper and lowwer bounds are supported by COBie on integer and decimal values if (underlyingType == typeof(int) || underlyingType == typeof(long) || underlyingType == typeof(short) || underlyingType == typeof(byte) || underlyingType == typeof(int?) || underlyingType == typeof(long?) || underlyingType == typeof(short?) || underlyingType == typeof(byte?)) { var integerValue = new AttributeIntegerValueType(); if (ifcPropertyBoundedValue.UpperBoundValue != null) { integerValue.MaxValueInteger = Convert.ToInt32(((IExpressValueType)ifcPropertyBoundedValue.UpperBoundValue).Value); } if (ifcPropertyBoundedValue.LowerBoundValue != null) { integerValue.MinValueInteger = Convert.ToInt32(((IExpressValueType)ifcPropertyBoundedValue.LowerBoundValue).Value); } attributeValueType.Item = integerValue; attributeValueType.ItemElementName = ItemChoiceType.AttributeIntegerValue; } else if (underlyingType == typeof(double) || underlyingType == typeof(float) || underlyingType == typeof(double?) || underlyingType == typeof(float?)) { var decimalValue = new AttributeDecimalValueType(); if (ifcPropertyBoundedValue.UpperBoundValue != null) { decimalValue.MaxValueDecimal = (double)((IExpressValueType)ifcPropertyBoundedValue.UpperBoundValue).Value; decimalValue.MaxValueDecimalSpecified = true; } if (ifcPropertyBoundedValue.LowerBoundValue != null) { decimalValue.MinValueDecimal = (double)((IExpressValueType)ifcPropertyBoundedValue.LowerBoundValue).Value; decimalValue.MinValueDecimalSpecified = true; } attributeValueType.Item = decimalValue; attributeValueType.ItemElementName = ItemChoiceType.AttributeDecimalValue; } else { attributeValueType = null; } return(attributeValueType); }
public static TValue ConvertToSimpleType <TValue>(IIfcPropertySingleValue ifcProperty) where TValue : struct { IIfcValue ifcValue = ifcProperty.NominalValue; var expressValue = (IExpressValueType)ifcValue; var underlyingType = expressValue.UnderlyingSystemType; var value = new TValue(); if (ifcValue is Xbim.Ifc4.MeasureResource.IfcMonetaryMeasure) { value = (TValue)Convert.ChangeType(expressValue.Value, typeof(TValue)); } else if (ifcValue is Xbim.Ifc4.DateTimeResource.IfcTimeStamp) { var timeStamp = (Xbim.Ifc4.DateTimeResource.IfcTimeStamp)ifcValue; value = (TValue)Convert.ChangeType(timeStamp.ToDateTime(), typeof(TValue)); } else if (value is DateTime) //sometimes these are written as strings in the ifc file { value = (TValue)Convert.ChangeType(ReadDateTime(expressValue.Value.ToString()), typeof(TValue)); } else if (underlyingType == typeof(int) || underlyingType == typeof(long) || underlyingType == typeof(short) || underlyingType == typeof(byte)) { value = (TValue)Convert.ChangeType(expressValue.Value, typeof(TValue)); } else if (underlyingType == typeof(double) || underlyingType == typeof(float)) { value = (TValue)Convert.ChangeType(expressValue.Value, typeof(TValue)); } else if (underlyingType == typeof(string)) { value = (TValue)Convert.ChangeType(expressValue.Value, typeof(TValue)); } else if (underlyingType == typeof(bool) || underlyingType == typeof(bool?)) { if (ifcValue != null) { value = (TValue)Convert.ChangeType(expressValue.Value, typeof(TValue)); } } return(value); }
public static IfcValue ToIfc3(this IIfcValue member) { if (member == null) { return(null); } var name = member.GetType().Name; switch (name) { case "IfcAbsorbedDoseMeasure": return(new IfcAbsorbedDoseMeasure((MeasureResource.IfcAbsorbedDoseMeasure)member)); case "IfcAccelerationMeasure": return(new IfcAccelerationMeasure((MeasureResource.IfcAccelerationMeasure)member)); case "IfcAngularVelocityMeasure": return(new IfcAngularVelocityMeasure((MeasureResource.IfcAngularVelocityMeasure)member)); case "IfcAreaDensityMeasure": return(null); case "IfcCompoundPlaneAngleMeasure": return(new IfcCompoundPlaneAngleMeasure((MeasureResource.IfcCompoundPlaneAngleMeasure)member)); case "IfcCurvatureMeasure": return(new IfcCurvatureMeasure((MeasureResource.IfcCurvatureMeasure)member)); case "IfcDoseEquivalentMeasure": return(new IfcDoseEquivalentMeasure((MeasureResource.IfcDoseEquivalentMeasure)member)); case "IfcDynamicViscosityMeasure": return(new IfcDynamicViscosityMeasure((MeasureResource.IfcDynamicViscosityMeasure)member)); case "IfcElectricCapacitanceMeasure": return(new IfcElectricCapacitanceMeasure((MeasureResource.IfcElectricCapacitanceMeasure)member)); case "IfcElectricChargeMeasure": return(new IfcElectricChargeMeasure((MeasureResource.IfcElectricChargeMeasure)member)); case "IfcElectricConductanceMeasure": return(new IfcElectricConductanceMeasure((MeasureResource.IfcElectricConductanceMeasure)member)); case "IfcElectricResistanceMeasure": return(new IfcElectricResistanceMeasure((MeasureResource.IfcElectricResistanceMeasure)member)); case "IfcElectricVoltageMeasure": return(new IfcElectricVoltageMeasure((MeasureResource.IfcElectricVoltageMeasure)member)); case "IfcEnergyMeasure": return(new IfcEnergyMeasure((MeasureResource.IfcEnergyMeasure)member)); case "IfcForceMeasure": return(new IfcForceMeasure((MeasureResource.IfcForceMeasure)member)); case "IfcFrequencyMeasure": return(new IfcFrequencyMeasure((MeasureResource.IfcFrequencyMeasure)member)); case "IfcHeatFluxDensityMeasure": return(new IfcHeatFluxDensityMeasure((MeasureResource.IfcHeatFluxDensityMeasure)member)); case "IfcHeatingValueMeasure": return(new IfcHeatingValueMeasure((MeasureResource.IfcHeatingValueMeasure)member)); case "IfcIlluminanceMeasure": return(new IfcIlluminanceMeasure((MeasureResource.IfcIlluminanceMeasure)member)); case "IfcInductanceMeasure": return(new IfcInductanceMeasure((MeasureResource.IfcInductanceMeasure)member)); case "IfcIntegerCountRateMeasure": return(new IfcIntegerCountRateMeasure((MeasureResource.IfcIntegerCountRateMeasure)member)); case "IfcIonConcentrationMeasure": return(new IfcIonConcentrationMeasure((MeasureResource.IfcIonConcentrationMeasure)member)); case "IfcIsothermalMoistureCapacityMeasure": return(new IfcIsothermalMoistureCapacityMeasure((MeasureResource.IfcIsothermalMoistureCapacityMeasure)member)); case "IfcKinematicViscosityMeasure": return(new IfcKinematicViscosityMeasure((MeasureResource.IfcKinematicViscosityMeasure)member)); case "IfcLinearForceMeasure": return(new IfcLinearForceMeasure((MeasureResource.IfcLinearForceMeasure)member)); case "IfcLinearMomentMeasure": return(new IfcLinearMomentMeasure((MeasureResource.IfcLinearMomentMeasure)member)); case "IfcLinearStiffnessMeasure": return(new IfcLinearStiffnessMeasure((MeasureResource.IfcLinearStiffnessMeasure)member)); case "IfcLinearVelocityMeasure": return(new IfcLinearVelocityMeasure((MeasureResource.IfcLinearVelocityMeasure)member)); case "IfcLuminousFluxMeasure": return(new IfcLuminousFluxMeasure((MeasureResource.IfcLuminousFluxMeasure)member)); case "IfcLuminousIntensityDistributionMeasure": return(new IfcLuminousIntensityDistributionMeasure((MeasureResource.IfcLuminousIntensityDistributionMeasure)member)); case "IfcMagneticFluxDensityMeasure": return(new IfcMagneticFluxDensityMeasure((MeasureResource.IfcMagneticFluxDensityMeasure)member)); case "IfcMagneticFluxMeasure": return(new IfcMagneticFluxMeasure((MeasureResource.IfcMagneticFluxMeasure)member)); case "IfcMassDensityMeasure": return(new IfcMassDensityMeasure((MeasureResource.IfcMassDensityMeasure)member)); case "IfcMassFlowRateMeasure": return(new IfcMassFlowRateMeasure((MeasureResource.IfcMassFlowRateMeasure)member)); case "IfcMassPerLengthMeasure": return(new IfcMassPerLengthMeasure((MeasureResource.IfcMassPerLengthMeasure)member)); case "IfcModulusOfElasticityMeasure": return(new IfcModulusOfElasticityMeasure((MeasureResource.IfcModulusOfElasticityMeasure)member)); case "IfcModulusOfLinearSubgradeReactionMeasure": return(new IfcModulusOfLinearSubgradeReactionMeasure((MeasureResource.IfcModulusOfLinearSubgradeReactionMeasure)member)); case "IfcModulusOfRotationalSubgradeReactionMeasure": return(new IfcModulusOfRotationalSubgradeReactionMeasure((MeasureResource.IfcModulusOfRotationalSubgradeReactionMeasure)member)); case "IfcModulusOfSubgradeReactionMeasure": return(new IfcModulusOfSubgradeReactionMeasure((MeasureResource.IfcModulusOfSubgradeReactionMeasure)member)); case "IfcMoistureDiffusivityMeasure": return(new IfcMoistureDiffusivityMeasure((MeasureResource.IfcMoistureDiffusivityMeasure)member)); case "IfcMolecularWeightMeasure": return(new IfcMolecularWeightMeasure((MeasureResource.IfcMolecularWeightMeasure)member)); case "IfcMomentOfInertiaMeasure": return(new IfcMomentOfInertiaMeasure((MeasureResource.IfcMomentOfInertiaMeasure)member)); case "IfcMonetaryMeasure": return(new IfcMonetaryMeasure((MeasureResource.IfcMonetaryMeasure)member)); case "IfcPHMeasure": return(new IfcPHMeasure((MeasureResource.IfcPHMeasure)member)); case "IfcPlanarForceMeasure": return(new IfcPlanarForceMeasure((MeasureResource.IfcPlanarForceMeasure)member)); case "IfcPowerMeasure": return(new IfcPowerMeasure((MeasureResource.IfcPowerMeasure)member)); case "IfcPressureMeasure": return(new IfcPressureMeasure((MeasureResource.IfcPressureMeasure)member)); case "IfcRadioActivityMeasure": return(new IfcRadioActivityMeasure((MeasureResource.IfcRadioActivityMeasure)member)); case "IfcRotationalFrequencyMeasure": return(new IfcRotationalFrequencyMeasure((MeasureResource.IfcRotationalFrequencyMeasure)member)); case "IfcRotationalMassMeasure": return(new IfcRotationalMassMeasure((MeasureResource.IfcRotationalMassMeasure)member)); case "IfcRotationalStiffnessMeasure": return(new IfcRotationalStiffnessMeasure((MeasureResource.IfcRotationalStiffnessMeasure)member)); case "IfcSectionModulusMeasure": return(new IfcSectionModulusMeasure((MeasureResource.IfcSectionModulusMeasure)member)); case "IfcSectionalAreaIntegralMeasure": return(new IfcSectionalAreaIntegralMeasure((MeasureResource.IfcSectionalAreaIntegralMeasure)member)); case "IfcShearModulusMeasure": return(new IfcShearModulusMeasure((MeasureResource.IfcShearModulusMeasure)member)); case "IfcSoundPowerLevelMeasure": return(new IfcSoundPowerMeasure((IfcSoundPowerLevelMeasure)member)); case "IfcSoundPowerMeasure": return(new IfcSoundPowerMeasure((MeasureResource.IfcSoundPowerMeasure)member)); case "IfcSoundPressureLevelMeasure": return(new IfcSoundPressureMeasure((IfcSoundPressureLevelMeasure)member)); case "IfcSoundPressureMeasure": return(new IfcSoundPressureMeasure((MeasureResource.IfcSoundPressureMeasure)member)); case "IfcSpecificHeatCapacityMeasure": return(new IfcSpecificHeatCapacityMeasure((MeasureResource.IfcSpecificHeatCapacityMeasure)member)); case "IfcTemperatureGradientMeasure": return(new IfcTemperatureGradientMeasure((MeasureResource.IfcTemperatureGradientMeasure)member)); case "IfcTemperatureRateOfChangeMeasure": return(null); case "IfcThermalAdmittanceMeasure": return(new IfcThermalAdmittanceMeasure((MeasureResource.IfcThermalAdmittanceMeasure)member)); case "IfcThermalConductivityMeasure": return(new IfcThermalConductivityMeasure((MeasureResource.IfcThermalConductivityMeasure)member)); case "IfcThermalExpansionCoefficientMeasure": return(new IfcThermalExpansionCoefficientMeasure((MeasureResource.IfcThermalExpansionCoefficientMeasure)member)); case "IfcThermalResistanceMeasure": return(new IfcThermalResistanceMeasure((MeasureResource.IfcThermalResistanceMeasure)member)); case "IfcThermalTransmittanceMeasure": return(new IfcThermalTransmittanceMeasure((MeasureResource.IfcThermalTransmittanceMeasure)member)); case "IfcTorqueMeasure": return(new IfcTorqueMeasure((MeasureResource.IfcTorqueMeasure)member)); case "IfcVaporPermeabilityMeasure": return(new IfcVaporPermeabilityMeasure((MeasureResource.IfcVaporPermeabilityMeasure)member)); case "IfcVolumetricFlowRateMeasure": return(new IfcVolumetricFlowRateMeasure((MeasureResource.IfcVolumetricFlowRateMeasure)member)); case "IfcWarpingConstantMeasure": return(new IfcWarpingConstantMeasure((MeasureResource.IfcWarpingConstantMeasure)member)); case "IfcWarpingMomentMeasure": return(new IfcWarpingMomentMeasure((MeasureResource.IfcWarpingMomentMeasure)member)); case "IfcAmountOfSubstanceMeasure": return(new IfcAmountOfSubstanceMeasure((MeasureResource.IfcAmountOfSubstanceMeasure)member)); case "IfcAreaMeasure": return(new IfcAreaMeasure((MeasureResource.IfcAreaMeasure)member)); case "IfcComplexNumber": return(new IfcComplexNumber((MeasureResource.IfcComplexNumber)member)); case "IfcContextDependentMeasure": return(new IfcContextDependentMeasure((MeasureResource.IfcContextDependentMeasure)member)); case "IfcCountMeasure": return(new IfcCountMeasure((MeasureResource.IfcCountMeasure)member)); case "IfcDescriptiveMeasure": return(new IfcDescriptiveMeasure((MeasureResource.IfcDescriptiveMeasure)member)); case "IfcElectricCurrentMeasure": return(new IfcElectricCurrentMeasure((MeasureResource.IfcElectricCurrentMeasure)member)); case "IfcLengthMeasure": return(new IfcLengthMeasure((MeasureResource.IfcLengthMeasure)member)); case "IfcLuminousIntensityMeasure": return(new IfcLuminousIntensityMeasure((MeasureResource.IfcLuminousIntensityMeasure)member)); case "IfcMassMeasure": return(new IfcMassMeasure((MeasureResource.IfcMassMeasure)member)); case "IfcNonNegativeLengthMeasure": return(null); case "IfcNormalisedRatioMeasure": return(new IfcNormalisedRatioMeasure((MeasureResource.IfcNormalisedRatioMeasure)member)); case "IfcNumericMeasure": return(new IfcNumericMeasure((MeasureResource.IfcNumericMeasure)member)); case "IfcParameterValue": return(new IfcParameterValue((MeasureResource.IfcParameterValue)member)); case "IfcPlaneAngleMeasure": return(new IfcPlaneAngleMeasure((MeasureResource.IfcPlaneAngleMeasure)member)); case "IfcPositiveLengthMeasure": return(new IfcPositiveLengthMeasure((MeasureResource.IfcPositiveLengthMeasure)member)); case "IfcPositivePlaneAngleMeasure": return(new IfcPositivePlaneAngleMeasure((MeasureResource.IfcPositivePlaneAngleMeasure)member)); case "IfcPositiveRatioMeasure": return(new IfcPositiveRatioMeasure((MeasureResource.IfcPositiveRatioMeasure)member)); case "IfcRatioMeasure": return(new IfcRatioMeasure((MeasureResource.IfcRatioMeasure)member)); case "IfcSolidAngleMeasure": return(new IfcSolidAngleMeasure((MeasureResource.IfcSolidAngleMeasure)member)); case "IfcThermodynamicTemperatureMeasure": return(new IfcThermodynamicTemperatureMeasure((MeasureResource.IfcThermodynamicTemperatureMeasure)member)); case "IfcTimeMeasure": return(new IfcTimeMeasure((MeasureResource.IfcTimeMeasure)member)); case "IfcVolumeMeasure": return(new IfcVolumeMeasure((MeasureResource.IfcVolumeMeasure)member)); case "IfcBoolean": return(new IfcBoolean((MeasureResource.IfcBoolean)member)); case "IfcDate": return(null); case "IfcDateTime": return(null); case "IfcDuration": return(null); case "IfcIdentifier": return(new IfcIdentifier((MeasureResource.IfcIdentifier)member)); case "IfcInteger": return(new IfcInteger((MeasureResource.IfcInteger)member)); case "IfcLabel": return(new IfcLabel((MeasureResource.IfcLabel)member)); case "IfcLogical": return(new IfcLogical((MeasureResource.IfcLogical)member)); case "IfcPositiveInteger": return(null); case "IfcReal": return(new IfcReal((MeasureResource.IfcReal)member)); case "IfcText": return(new IfcText((MeasureResource.IfcText)member)); case "IfcTime": return(null); case "IfcTimeStamp": return(new IfcTimeStamp((DateTimeResource.IfcTimeStamp)member)); default: throw new NotSupportedException(); } }
public static AttributeValueType GetAttributeValueType(IIfcPropertySingleValue ifcProperty) { IIfcValue ifcValue = ifcProperty.NominalValue; var attributeValueType = new AttributeValueType(); if (ifcValue == null) { return(null); } var expressValue = (IExpressValueType)ifcValue; var underlyingType = expressValue.UnderlyingSystemType; if (ifcValue is Xbim.Ifc4.MeasureResource.IfcMonetaryMeasure) { attributeValueType.ItemElementName = ItemChoiceType.AttributeMonetaryValue; var monetaryValue = new AttributeMonetaryValueType { MonetaryValue = Convert.ToDecimal((double)expressValue.Value) }; attributeValueType.Item = monetaryValue; if (!(ifcProperty.Unit is IIfcMonetaryUnit)) { return(attributeValueType); } var mu = (IIfcMonetaryUnit)ifcProperty.Unit; CurrencyUnitSimpleType cu; if (Enum.TryParse(mu.Currency.ToString(), true, out cu)) { monetaryValue.MonetaryUnit = cu; } else { logger.LogWarning("Invalid monetary unit: {currency} ", mu.Currency); } } else if (ifcValue is Xbim.Ifc4.DateTimeResource.IfcTimeStamp) { attributeValueType.ItemElementName = ItemChoiceType.AttributeDateTimeValue; var timeStamp = (Xbim.Ifc4.DateTimeResource.IfcTimeStamp)ifcValue; attributeValueType.Item = timeStamp.ToDateTime(); } else if (underlyingType == typeof(int) || underlyingType == typeof(long) || underlyingType == typeof(short) || underlyingType == typeof(byte)) { var integerValue = new AttributeIntegerValueType { IntegerValue = Convert.ToInt32(expressValue.Value) }; attributeValueType.Item = integerValue; attributeValueType.ItemElementName = ItemChoiceType.AttributeIntegerValue; } else if (underlyingType == typeof(double) || underlyingType == typeof(float)) { var decimalValue = new AttributeDecimalValueType { DecimalValue = (double)expressValue.Value, DecimalValueSpecified = true }; attributeValueType.Item = decimalValue; attributeValueType.ItemElementName = ItemChoiceType.AttributeDecimalValue; } else if (underlyingType == typeof(string)) { var stringValue = new AttributeStringValueType { StringValue = ifcValue.ToString() }; attributeValueType.Item = stringValue; attributeValueType.ItemElementName = ItemChoiceType.AttributeStringValue; } else if (underlyingType == typeof(bool) || underlyingType == typeof(bool?)) { var boolValue = new BooleanValueType(); if (expressValue.Value != null && (bool)expressValue.Value) { var theBool = (bool)expressValue.Value; boolValue.BooleanValue = theBool; boolValue.BooleanValueSpecified = true; } attributeValueType.Item = boolValue; attributeValueType.ItemElementName = ItemChoiceType.AttributeBooleanValue; } else { attributeValueType = null; } return(attributeValueType); }
private static void SetCoBieAttributeValue <TCoBieValueBaseType>(TCoBieValueBaseType result, IIfcValue ifcValue) where TCoBieValueBaseType : ValueBaseType { var stringValueType = result as StringValueType; var decimalValueType = result as DecimalValueType; var booleanValueType = result as BooleanValueType; var integerValueType = result as IntegerValueType; var expressValue = (IExpressValueType)ifcValue; if (stringValueType != null) { stringValueType.StringValue = ifcValue.ToString(); } else if (decimalValueType != null) { try { decimalValueType.DecimalValue = Convert.ToDouble(expressValue.Value); decimalValueType.DecimalValueSpecified = true; } catch (ArgumentNullException) { logger.LogWarning("Decimal Conversion: String is null."); } catch (FormatException) { logger.LogWarning("Decimal Conversion: value {strValue} is not correctly formatted", expressValue.Value); } catch (OverflowException) { logger.LogWarning("Decimal Conversion: Overflow in string to decimal conversion."); } } else if (booleanValueType != null) { try { booleanValueType.BooleanValue = Convert.ToBoolean(expressValue.Value); booleanValueType.BooleanValueSpecified = true; } catch (ArgumentNullException) { logger.LogWarning("Boolean Conversion: String is null."); } catch (FormatException) { logger.LogWarning("Boolean Conversion: value {strValue} is not correctly formatted", expressValue.Value); } } else if (integerValueType != null) { try { //this looks like an error in COBieLite, suggest should be same as Decimal and Boolean integerValueType.IntegerValue = Convert.ToInt32(expressValue.Value); } catch (ArgumentNullException) { logger.LogWarning("Integer Conversion: String is null."); } catch (FormatException) { logger.LogWarning("Integer Conversion: value {strValue} is not correctly formatted", expressValue.Value); } catch (OverflowException) { logger.LogWarning("Integer Conversion: Overflow in string to int conversion."); } } else { logger.LogWarning("Unexpected ValueBaseType {valueType}", ifcValue); } }
private static void SetCoBieAttributeValue <TCoBieValueBaseType>(TCoBieValueBaseType result, IIfcValue ifcValue) where TCoBieValueBaseType : ValueBaseType { var stringValueType = result as StringValueType; var decimalValueType = result as DecimalValueType; var booleanValueType = result as BooleanValueType; var integerValueType = result as IntegerValueType; var expressValue = (IExpressValueType)ifcValue; if (stringValueType != null) { stringValueType.StringValue = ifcValue.ToString(); } else if (decimalValueType != null) { try { decimalValueType.DecimalValue = Convert.ToDouble(expressValue.Value); decimalValueType.DecimalValueSpecified = true; } catch (ArgumentNullException) { CoBieLiteHelper.Logger.WarnFormat("Decimal Conversion: String is null."); } catch (FormatException) { CoBieLiteHelper.Logger.WarnFormat("Decimal Conversion: String does not consist of an " + "optional sign followed by a series of digits."); } catch (OverflowException) { CoBieLiteHelper.Logger.WarnFormat("Decimal Conversion: Overflow in string to int conversion."); } } else if (booleanValueType != null) { try { booleanValueType.BooleanValue = Convert.ToBoolean(expressValue.Value); booleanValueType.BooleanValueSpecified = true; } catch (ArgumentNullException) { CoBieLiteHelper.Logger.WarnFormat("Boolean Conversion: String is null."); } catch (FormatException) { CoBieLiteHelper.Logger.WarnFormat("Boolean Conversion: String does not consist of an " + "optional sign followed by a series of digits."); } catch (OverflowException) { CoBieLiteHelper.Logger.WarnFormat("Boolean Conversion: Overflow in string to int conversion."); } } else if (integerValueType != null) { try { //this looks like an error in COBieLite, suggest should be same as Decimal and Boolean integerValueType.IntegerValue = Convert.ToInt32(expressValue.Value); } catch (ArgumentNullException) { CoBieLiteHelper.Logger.WarnFormat("Integer Conversion: String is null."); } catch (FormatException) { CoBieLiteHelper.Logger.WarnFormat("Integer Conversion: String does not consist of an " + "optional sign followed by a series of digits."); } catch (OverflowException) { CoBieLiteHelper.Logger.WarnFormat("Integer Conversion: Overflow in string to int conversion."); } } else { CoBieLiteHelper.Logger.Warn("Unexpected ValueBaseType"); } }