Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }