private Property LoadProperty(Annotation annotation, Context context, DocEntry entry, Property prop, SetLiteral literal) { SetValue values = (SetValue)literal.interpret(context); IType itemType = values.ItemType; if (itemType is TypeType) { HashSet <IType> types = new HashSet <IType>(); foreach (IValue val in values.getItems()) { if (val == NullValue.Instance) { continue; } types.Add(resolveType(annotation, context, ((TypeValue)val).GetValue())); } if (types.Contains(null)) { return(null); // something went wrong } prop.SetValidator(new TypeSetValidator(types)); prop.SetRequired(types.Count == values.Length()); // no null filtered out return(prop); } else if (itemType == AnyType.Instance || itemType == TextType.Instance) { HashSet <String> texts = new HashSet <String>(); foreach (IValue val in values.getItems()) { if (val == NullValue.Instance) { continue; } texts.Add(val.ToString()); } prop.SetValidator(new ValueSetValidator(texts)); prop.SetRequired(texts.Count == values.Length()); // no null filtered out return(prop); } else { throw new SyntaxError("Expected a set of Types."); } }
private Property LoadProperty(Annotation annotation, Context context, DocEntry entry, Property prop, DocumentLiteral doc) { foreach (DocEntry child in doc.GetEntries()) { String name = child.GetKey().ToString(); Object value = child.GetValue(); switch (name) { case "required": if (value is BooleanLiteral) { prop.SetRequired(((BooleanLiteral)value).interpret(context) == BooleanValue.TRUE); break; } throw new SyntaxError("Expected a Boolean value for 'required'."); case "help": if (value is TextLiteral) { prop.SetHelp((String)((TextLiteral)value).getValue().GetStorableData()); break; } throw new SyntaxError("Expected a Text value for 'help'."); case "type": if (value is TypeLiteral) { IType type = resolveType(annotation, context, (TypeLiteral)value); if (type == null) { return(null); } prop.SetValidator(new TypeValidator(type)); break; } else if (value is DocumentLiteral) { PropertyMap embedded = LoadProperties(annotation, context, ((DocumentLiteral)value).GetEntries()); if (embedded != null) { prop.SetValidator(new TypeValidator(new PropertiesType(embedded))); break; } } throw new SyntaxError("Expected a Type value for 'type'."); case "types": if (value is SetLiteral) { SetValue values = (SetValue)((SetLiteral)value).interpret(context); if (values.ItemType is TypeType) { HashSet <IType> types = new HashSet <IType>(); foreach (IValue val in values.getItems()) { if (val == NullValue.Instance) { continue; } types.Add(resolveType(annotation, context, ((TypeValue)val).GetIType())); } if (types.Contains(null)) { return(null); // TODO something went wrong } prop.SetValidator(new TypeSetValidator(types)); prop.SetRequired(types.Count == values.Length()); // no null filtered out break; } } throw new SyntaxError("Expected a Set of types for 'types'."); case "values": if (value is SetLiteral) { SetValue values = (SetValue)((SetLiteral)value).interpret(context); HashSet <String> texts = new HashSet <String>(); foreach (IValue val in values.getItems()) { if (val == NullValue.Instance) { continue; } texts.Add(val.GetStorableData().ToString()); } prop.SetValidator(new ValueSetValidator(texts)); prop.SetRequired(texts.Count == values.Length()); // no null filtered out break; } throw new SyntaxError("Expected a Set value for 'values'."); default: throw new SyntaxError("Unknown property attribute: " + name); } } return(prop); }