/// <summary> /// Returns the <see cref="AttributeValue"/> representation of the value of a <see cref="SimpleParameterValue"/> /// </summary> /// <param name="parameterType">The <see cref="ParameterType"/></param> /// <param name="attributeDefinition">The associated <see cref="AttributeDefinition"/></param> /// <param name="valuearray">The <see cref="ValueArray{String}"/> containing the values</param> /// <param name="scale">The scale used</param> /// <returns>The <see cref="AttributeValue"/></returns> private AttributeValue ToReqIfAttributeValue(ParameterType parameterType, AttributeDefinition attributeDefinition, ValueArray <string> valuearray, MeasurementScale scale = null) { if (parameterType == null) { throw new ArgumentNullException("parameterType"); } if (parameterType is EnumerationParameterType) { var enumParameterType = (EnumerationParameterType)parameterType; var concatEnumValue = valuearray.Single(); var enumValues = concatEnumValue.Split(parameterEnumSeparator).Select(x => x.Trim()); // retrieve the list of litteral var valueDefinitions = enumParameterType.ValueDefinition.Where(x => enumValues.Contains(x.ShortName)).ToList(); // Assuming the model is not wrong the values in the SimpleParameterValue references the ValueDefinition by its ShortName var attributeValue = new AttributeValueEnumeration { Definition = (AttributeDefinitionEnumeration)attributeDefinition }; var reqIfEnumValues = ((DatatypeDefinitionEnumeration)attributeDefinition.DatatypeDefinition).SpecifiedValues; attributeValue.Values.AddRange(valueDefinitions.Select(x => reqIfEnumValues.Single(e => e.Properties.OtherContent == x.ShortName))); return(attributeValue); } if (parameterType is DateParameterType || parameterType is DateTimeParameterType || parameterType is TimeOfDayParameterType) { var value = valuearray.SingleOrDefault(); DateTime date; if (!DateTime.TryParse(value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out date)) { throw new InvalidOperationException(string.Format("The string {0} cannot be parsed to a DateTime", value)); } return(new AttributeValueDate { TheValue = date, Definition = (AttributeDefinitionDate)attributeDefinition }); } if (parameterType is TextParameterType) { var value = valuearray.Single(); return(new AttributeValueString { TheValue = value, Definition = (AttributeDefinitionString)attributeDefinition }); } if (parameterType is BooleanParameterType) { var value = valuearray.Single(); var boolean = Boolean.Parse(value); return(new AttributeValueBoolean { TheValue = boolean, Definition = (AttributeDefinitionBoolean)attributeDefinition }); } if (parameterType is QuantityKind) { var value = valuearray.Single(); return(new AttributeValueString { TheValue = string.Format("{0} [{1}]", value, scale != null ? scale.ShortName : "-"), Definition = (AttributeDefinitionString)attributeDefinition }); } // CompoundParameterType var compoundType = (CompoundParameterType)parameterType; var theValue = "Error: The value could not be parsed."; if (valuearray.Count() == compoundType.Component.Count) { var values = new List <string>(); for (var i = 0; i < valuearray.Count(); i++) { var component = compoundType.Component[i].Scale != null ? compoundType.Component[i].Scale.ShortName : "-"; values.Add(string.Format("{0}: {1} [{2}]", compoundType.Component[i].ShortName, valuearray[i], component)); } theValue = string.Format("{{ {0} }}", string.Join(", ", values)); } return(new AttributeValueString { TheValue = theValue, Definition = (AttributeDefinitionString)attributeDefinition }); }