Esempio n. 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="interfaceBuilder"></param>
 /// <param name="builder"></param>
 /// <param name="block"></param>
 internal GenericUserInterfaceBlockBuilder(IGenericInterfaceBuilder interfaceBuilder, CrocoTypeDescriptionBuilder builder, UserInterfaceBlock block)
 {
     InterfaceBuilder = interfaceBuilder;
     DocsBuilder      = builder;
     Block            = block;
     DescribedType    = DocsBuilder.GetTypeDescriptionResult(typeof(TProp));
 }
Esempio n. 2
0
        internal static List <UserInterfaceBlock> GetBlocks(string prefix, CrocoTypeDescription currentType, CrocoTypeDescriptionResult desc, GenericInterfaceOptions opts)
        {
            List <UserInterfaceBlock> result = new List <UserInterfaceBlock>();

            foreach (var prop in currentType.Properties)
            {
                result.Add(GetBlockFromProperty(prefix, prop, desc, opts));
            }

            return(result);
        }
Esempio n. 3
0
        private static UserInterfaceBlock GetBlockForEnumerable(string prefix, CrocoPropertyReferenceDescription prop, CrocoTypeDescriptionResult desc, GenericInterfaceOptions opts)
        {
            var type = desc.GetTypeDescription(prop.TypeDisplayFullName);

            if (!type.ArrayDescription.IsArray)
            {
                throw new InvalidOperationException("Type is not of type enumerable");
            }

            var enumeratedType = desc.GetTypeDescription(type.ArrayDescription.ElementDiplayFullTypeName);

            if (enumeratedType.IsPrimitive)
            {
                return(new UserInterfaceBlock(prop)
                {
                    InterfaceType = UserInterfaceType.MultipleDropDownList,
                    DropDownData = GetSelectListData(prop, desc, opts)
                });
            }

            var newPrefix = AddPropNameToPrefix(prefix, prop.PropertyDescription.PropertyName);

            return(new UserInterfaceBlock(prop)
            {
                InterfaceType = UserInterfaceType.GenericInterfaceForArray,
                InnerGenericInterface = new GenericInterfaceModel
                {
                    Prefix = newPrefix,
                    Blocks = GetBlocks(newPrefix, enumeratedType, desc, opts)
                }
            });
        }
Esempio n. 4
0
        private static DropDownListData GetSelectListData(CrocoPropertyReferenceDescription propDescr, CrocoTypeDescriptionResult main, GenericInterfaceOptions opts)
        {
            var emptySelectListPredicates = new List <Func <CrocoTypeDescription, bool> >
            {
                x => x.ArrayDescription.IsArray,
                x => x.ExtractType() == typeof(DateTime) || x.ExtractType() == typeof(DateTime?)
            };

            var propTypeDesc = main.GetTypeDescription(propDescr.TypeDisplayFullName);

            if (propTypeDesc.ArrayDescription.IsArray)
            {
                var enumeratedType = main.GetTypeDescription(propTypeDesc.ArrayDescription.ElementDiplayFullTypeName);

                if (enumeratedType.IsEnumeration)
                {
                    return(new DropDownListData
                    {
                        SelectList = enumeratedType.EnumDescription.EnumValues.Select(x => new SelectListItem
                        {
                            Text = x.DisplayName,
                            Value = x.StringRepresentation
                        }).ToList(),
                        CanAddNewItem = false
                    });
                }
            }

            if (propTypeDesc.ExtractType() == typeof(bool) || propTypeDesc.ExtractType() == typeof(bool?))
            {
                return(new DropDownListData
                {
                    SelectList = MySelectListItemExtensions.GetBooleanList(propTypeDesc.IsNullable, opts),
                    CanAddNewItem = false
                });
            }

            if (emptySelectListPredicates.Any(x => x(propTypeDesc)))
            {
                return(new DropDownListData
                {
                    SelectList = new List <SelectListItem>(),
                    CanAddNewItem = true
                });
            }

            if (propTypeDesc.IsEnumeration)
            {
                return(ForEnumDropDownDataBuilder.GetDropDownListData(propTypeDesc, opts));
            }

            return(null);
        }
Esempio n. 5
0
        private static UserInterfaceBlock GetBlockFromProperty(string prefix, CrocoPropertyReferenceDescription prop, CrocoTypeDescriptionResult main, GenericInterfaceOptions opts)
        {
            var propTypeDescription = main.GetTypeDescription(prop.TypeDisplayFullName);

            if (!propTypeDescription.IsClass && !propTypeDescription.ArrayDescription.IsArray)
            {
                var type = GetUserInterfaceType(propTypeDescription);

                var selectList = GetSelectListData(prop, main, opts);

                return(new UserInterfaceBlock(prop)
                {
                    InterfaceType = type,
                    DropDownData = selectList,
                    NumberBoxData = GetNumberBoxDataForProperty(propTypeDescription, type)
                });
            }

            if (propTypeDescription.ArrayDescription.IsArray)
            {
                return(GetBlockForEnumerable(prefix, prop, main, opts));
            }

            if (propTypeDescription.IsClass)
            {
                var propDesc = main.GetTypeDescription(propTypeDescription.TypeDisplayFullName);

                var newPrefix = AddPropNameToPrefix(prefix, prop.PropertyDescription.PropertyName);

                return(new UserInterfaceBlock(prop)
                {
                    InterfaceType = UserInterfaceType.GenericInterfaceForClass,
                    InnerGenericInterface = new GenericInterfaceModel
                    {
                        Prefix = newPrefix,
                        Blocks = GetBlocks(newPrefix, propDesc, main, opts)
                    }
                });
            }

            throw new Exception("Not supported");
        }