public static SgfProperty ParseValuesAndCreate(string identifier, params string[] serializedValues) { if (identifier == null) { throw new ArgumentNullException(nameof(identifier)); } if (serializedValues == null) { throw new ArgumentNullException(nameof(serializedValues)); } var knownProperty = SgfKnownProperties.Get(identifier); if (knownProperty != null) { //parse as known if (knownProperty.ValueMultiplicity == SgfValueMultiplicity.None) { if (serializedValues.Length > 0) { if (serializedValues.Length != 1 || serializedValues[0] != "") { throw new SgfParseException($"Property {identifier} has none multiplicity and can't be given values."); } } return(new SgfProperty(identifier)); } if (knownProperty.ValueMultiplicity == SgfValueMultiplicity.Single) { if (serializedValues.Length != 1) { throw new SgfParseException($"Property {identifier} has single multiplicity and must be given exactly one value."); } return(new SgfProperty(identifier, knownProperty.Parser(serializedValues[0]))); } if (knownProperty.ValueMultiplicity == SgfValueMultiplicity.EList) { if (serializedValues.Length == 1 && serializedValues[0] == "") { return(new SgfProperty(identifier)); } } //default - multiple values return(new SgfProperty(identifier, serializedValues.Select(v => knownProperty.Parser(v)).ToArray())); } else { var values = serializedValues.Select( v => (ISgfPropertyValue)SgfUnknownValue.Parse(v) ).ToArray(); return(new SgfProperty(identifier, values)); } }
/// <summary> /// Returns the type of property /// </summary> /// <param name="propertyIdentifier">Property identifier</param> /// <returns>Type of property</returns> public static SgfPropertyType GetPropertyType(string propertyIdentifier) { if (propertyIdentifier == null) { return(SgfPropertyType.Invalid); } //check if the property identifier is known SgfKnownProperty property = SgfKnownProperties.Get(propertyIdentifier); if (property != null) { return(property.Type); } //check if the property identifier is valid if (IsPropertyIdentifierValid(propertyIdentifier)) { return(SgfPropertyType.Unknown); } //invalid property return(SgfPropertyType.Invalid); }