public static Schema BuildMultiChoice(Type enumType, params int[] defaultValues) { var choiceSet = ChoiceSet.FromEnum(enumType); choiceSet.Defaults = defaultValues.ToList(); return(new SchemaBuilder(enumType.FullName, DataType.MultiChoice, choiceSet.ToEditable(new EditableFactory(null))).ToSchema()); }
public static Schema BuildChoice(Type enumType, int?defaultValue) { var choiceSet = ChoiceSet.FromEnum(enumType); if (defaultValue.HasValue) { choiceSet.Defaults = new List <int> { defaultValue.Value } } ; return(new SchemaBuilder(enumType.FullName, DataType.Choice, choiceSet.ToEditable(new EditableFactory(null))).ToSchema()); }
public static ChoiceSet FromCursor(ICursor cursor) { var dataField = cursor.GoTo((int)ItemLayout.Data, true); var result = new ChoiceSet(); if (!cursor.GoTo((int)ItemLayout.Id).IsNull) { result.Id = cursor.GoTo((int)ItemLayout.Id).Get <ItemId>(); } result.Name = cursor.GoTo((int)ItemLayout.Name).Get <string>(); result.Revision = cursor.GoTo((int)ItemLayout.Revision).Get <int>(); result.Description = dataField.GoTo("Description").Get <string>(); result.Caption = dataField.GoTo("Caption").Get <string>(); result.Defaults = dataField.GoTo("Defaults").Children.Select(x => x.Get <int>()).ToList(); result.Options = dataField.GoTo("Options").Children.Select(ChoiceOption.FromCursor).ToList(); return(result); }
Schema BuildSchemaForEnum(Type type, string schemaName, List <Tuple <Type, Schema> > schemaList) { var dataType = DataType.Choice; var choiceSetAttribute = type.GetTypeInfo().GetCustomAttribute <ChoiceSetAttribute>(); if (choiceSetAttribute != null && choiceSetAttribute.MultiChoice) { dataType = DataType.MultiChoice; } var sb = new SchemaBuilder(schemaName, dataType, ChoiceSet.FromEnum(type).ToEditable(editableFactory)); var result = sb.ToSchema(); if (choiceSetAttribute != null) { result.Id = choiceSetAttribute.SchemaId; } schemaList.Add(Tuple.Create(type, result)); return(result); }