Ejemplo n.º 1
0
        private static UserInterfaceType GetUserInterfaceType(CrocoTypeDescription desc)
        {
            var type = desc.ExtractType();

            if (type == typeof(bool) || type == typeof(bool?))
            {
                return(UserInterfaceType.DropDownList);
            }

            if (type == typeof(DateTime) || type == typeof(DateTime?))
            {
                return(UserInterfaceType.DatePicker);
            }

            if (desc.IsEnumeration)
            {
                return(UserInterfaceType.DropDownList);
            }

            if (desc.IsNumber)
            {
                return(UserInterfaceType.NumberBox);
            }

            return(UserInterfaceType.TextBox);
        }
Ejemplo n.º 2
0
        private static UserInterfaceNumberBoxData GetNumberBoxDataForProperty(CrocoTypeDescription prop, UserInterfaceType interfaceType)
        {
            if (interfaceType != UserInterfaceType.NumberBox)
            {
                return(null);
            }

            var type = prop.ExtractType();

            if (CrocoClassDescriptionBuilder.IsNullable(type, out var extractedType))
            {
                type = extractedType;
            }

            if (IntegerTypes.TryGetValue(type, out var minMax))
            {
                return(new UserInterfaceNumberBoxData
                {
                    IsInteger = true,
                    MinValue = minMax.MinValue,
                    MaxValue = minMax.MaxValue
                });
            }
            ;
            minMax = NonIntegerTypes[type];

            return(new UserInterfaceNumberBoxData
            {
                IsInteger = false,
                MinValue = minMax.MinValue,
                MaxValue = minMax.MaxValue
            });
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public void TestTypes(Type type, bool isRecursiveExpected)
        {
            var doc = CrocoTypeDescription.GetDescription(type);

            var main = doc.GetMainTypeDescription();

            Assert.IsNotNull(doc);
            Assert.AreEqual(type, main.ExtractType());

            var isRecursive = new CrocoClassDescriptionChecker().IsRecursiveType(doc);

            Assert.AreEqual(isRecursiveExpected, isRecursive);
        }
Ejemplo n.º 5
0
        public void CheckDropDownDataType()
        {
            var descr = CrocoTypeDescription
                        .GetDescription(typeof(DropDownListData))
                        .GetMainTypeDescription();

            Assert.IsTrue(descr.IsClass);

            var props = descr.Properties;

            Assert.AreEqual(2, props.Count);
            Assert.IsNull(props.FirstOrDefault(x => x.PropertyDescription.PropertyName == nameof(DropDownListData.DataProviderTypeFullName)));
        }
        public JsOpenApiWorkerMethodDocumentation(JsWorkerMethodDocs methodDocs)
        {
            MethodName  = methodDocs.MethodName;
            Description = methodDocs.Description;

            if (methodDocs.Response != null)
            {
                Response = CrocoTypeDescription.GetDescription(methodDocs.Response);
            }

            if (methodDocs.Parameters != null)
            {
                Parameters = methodDocs.Parameters.Select(x => CrocoTypeDescription.GetDescription(x)).ToList();
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Получить документацию по типу данных
        /// </summary>
        /// <param name="typeName"></param>
        /// <returns></returns>
        public static CrocoTypeDescriptionResult GetTypeDocumentation(string typeName)
        {
            if (typeName == null)
            {
                return(null);
            }

            var type = CrocoTypeSearcher.FindFirstTypeByName(typeName, x => !x.IsGenericTypeDefinition);

            if (type == null)
            {
                return(null);
            }

            return(CrocoTypeDescription.GetDescription(type));
        }
Ejemplo n.º 8
0
        public CrocoTypeDescription GetTypeDocumentation(string typeName)
        {
            if (typeName == null)
            {
                return(null);
            }

            var type = CrocoTypeSearcher.FindFirstTypeByName(typeName);

            if (type == null)
            {
                return(null);
            }

            return(CrocoTypeDescription.GetDescription(type));
        }
Ejemplo n.º 9
0
        public static DropDownListData GetDropDownListData(CrocoTypeDescription propTypeDesc, GenericInterfaceOptions opts)
        {
            if (!propTypeDesc.IsEnumeration)
            {
                throw new InvalidOperationException($"{propTypeDesc.FullTypeName} is not  enum");
            }

            var enumsList = new List <SelectListItem>();

            if (propTypeDesc.IsNullable)
            {
                enumsList.Add(new SelectListItem
                {
                    Value    = null,
                    Selected = true,
                    Text     = opts.NotSelectedText
                });
            }

            enumsList.AddRange(propTypeDesc.EnumDescription.EnumValues.Select(x => new SelectListItem
            {
                Value = x.StringRepresentation,
                Text  = x.DisplayName
            }));

            if (!enumsList.Any(x => x.Selected))
            {
                var first = enumsList.FirstOrDefault();

                if (first != null)
                {
                    first.Selected = true;
                }
            }

            return(new DropDownListData
            {
                CanAddNewItem = false,
                SelectList = enumsList
            });
        }
Ejemplo n.º 10
0
 public void Test()
 {
     var result = CrocoTypeDescription.GetDescription(typeof(Exception));
 }