/// <summary> /// Creates a new value spceification with a string type. /// </summary> /// <param name="value">Initial value</param> public ValueSpecification(string value) { NUml.Uml2.LiteralString literal = NUml.Uml2.Create.LiteralString(); literal.Value = value; adaptedElement = literal; valueType = ValueTypes.String; }
/// <summary> /// Creates a new value specification with a given type. /// </summary> /// <param name="value">String representation of the value</param> /// <param name="type">Type of the value</param> /// <remarks> /// If the type is not known (i.e. it is not emong ValueTypes values, /// the value is treated like a string. /// </remarks> /// <exception cref="NullReferenceException">Type is null</exception> /// <exception cref="FormatException">Value cannot be parsed to the given type instance</exception> public ValueSpecification(string value, DataType type) { //if (type == null) // throw new NullReferenceException("Type cannot be null!"); string typeName = type != null?type.Name.ToLower() : "null"; switch (typeName) { case "integer": case "int": { NUml.Uml2.LiteralInteger literal = NUml.Uml2.Create.LiteralInteger(); literal.Value = int.Parse(value); adaptedElement = literal; valueType = ValueTypes.Integer; break; } case "boolean": case "bool": { NUml.Uml2.LiteralBoolean literal = NUml.Uml2.Create.LiteralBoolean(); literal.Value = bool.Parse(value); adaptedElement = literal; valueType = ValueTypes.Boolean; break; } case "object": { if (value.ToLower().Equals("null")) { NUml.Uml2.ElementValue elVal = NUml.Uml2.Create.ElementValue(); elVal.Element = null; adaptedElement = elVal; valueType = ValueTypes.Element; } break; } default: { NUml.Uml2.LiteralString literal = NUml.Uml2.Create.LiteralString(); literal.Value = value; adaptedElement = literal; valueType = ValueTypes.String; break; } } }