Пример #1
0
        public void EnumToKeyValues_StateUnderTest_ExpectedBehavior(string typeName)
        {
            var list = KeyValueExtesions.EnumToKeyValues(typeName);

            Assert.NotNull(list);
            Assert.True(list.Any());
        }
Пример #2
0
        public ApiResult <IList <KeyValue> > GetKeyValuesByEnum([FromQuery] string type)
        {
            if (type.IsNullOrEmpty())
            {
                ApiResult.Failure("类型不能为空");
            }

            var keyValues = KeyValueExtesions.EnumToKeyValues(type);

            if (keyValues == null)
            {
                return(ApiResult.Failure <IList <KeyValue> >("枚举不存在"));
            }

            return(ApiResult.Success(keyValues));
        }
Пример #3
0
        public static List <KeyValue> GetTabs(PropertyDescription[] propertys)
        {
            var result = new List <KeyValue>();

            foreach (var item in propertys)
            {
                var type = item.Property.PropertyType;
                if (item.FieldAttribute != null && item.FieldAttribute.IsTabSearch && type.IsEnum)
                {
                    result = KeyValueExtesions.EnumToKeyValues(type).ToList();
                    if (result != null)
                    {
                        result.ForEach(r => r.Name = item.Name);
                    }

                    break;
                }
            }

            return(result);
        }
Пример #4
0
        public ApiResult <List <KeyValue> > GetKeyValue([FromQuery] string type)
        {
            if (type.IsNullOrEmpty() || type == "undefined")
            {
                return(ApiResult.Failure <List <KeyValue> >("类型不能为空"));
            }

            if (type == "IAutoTable")
            {
                return(ApiResult.Success(Resolve <IAutoUIService>().AutoTableKeyValues()));
            }

            if (type == "IAutoForm")
            {
                return(ApiResult.Success(Resolve <IAutoUIService>().AutoFormKeyValues()));
            }

            if (type == "IAutoList")
            {
                return(ApiResult.Success(Resolve <IAutoUIService>().AutoListKeyValues()));
            }

            if (type == "IAutoPreview")
            {
                return(ApiResult.Success(Resolve <IAutoUIService>().AutoPreviewKeyValues()));
            }

            if (type == "IAutoNews")
            {
                return(ApiResult.Success(Resolve <IAutoUIService>().AutoNewsKeyValues()));
            }

            if (type == "IAutoArticle")
            {
                return(ApiResult.Success(Resolve <IAutoUIService>().AutoArticleKeyValues()));
            }

            if (type == "IAutoReport")
            {
                return(ApiResult.Success(Resolve <IAutoUIService>().AutoReportKeyValues()));
            }

            if (type == "IAutoFaq")
            {
                return(ApiResult.Success(Resolve <IAutoUIService>().AutoFaqsKeyValues()));
            }

            if (type == "IAutoImage")
            {
                return(ApiResult.Success(Resolve <IAutoUIService>().AutoImagesKeyValues()));
            }

            if (type == "IAutoIndex")
            {
                return(ApiResult.Success(Resolve <IAutoUIService>().AutoIndexKeyValues()));
            }

            if (type == "IAutoIntro")
            {
                return(ApiResult.Success(Resolve <IAutoUIService>().AutoIntroKeyValues()));
            }

            if (type == "IAutoTask")
            {
                return(ApiResult.Success(Resolve <IAutoUIService>().AutoTaskKeyValues()));
            }

            if (type == "IAutoVideo")
            {
                return(ApiResult.Success(Resolve <IAutoUIService>().AutoVideoKeyValues()));
            }

            if (type == "CatalogEntity")
            {
                return(ApiResult.Success(Resolve <ITableService>().CatalogEntityKeyValues()));
            }

            if (type == "SqlServcieCatalogEntity")
            {
                return(ApiResult.Success(Resolve <ITableService>().SqlServcieCatalogEntityKeyValues()));
            }

            if (type == "MongodbCatalogEntity")
            {
                return(ApiResult.Success(Resolve <ITableService>().MongodbCatalogEntityKeyValues()));
            }

            var find = type.GetTypeByName();

            if (find == null)
            {
                return(ApiResult.Failure <List <KeyValue> >($"类型不存在,请确认{type}输入是否正确"));
            }

            var intances = type.GetInstanceByName();

            if (intances is IRelation)
            {
                var result = ServiceInterpreter.Eval <IEnumerable <KeyValue> >("IRelationService", "GetKeyValues2", type);
                return(ApiResult.Success(result.ToList()));
            }

            //enum
            if (find.IsEnum)
            {
                var keyValues = KeyValueExtesions.EnumToKeyValues(type);
                if (keyValues == null)
                {
                    return(ApiResult.Failure <List <KeyValue> >("枚举不存在"));
                }

                return(ApiResult.Success(keyValues.ToList()));
            }

            // auto config
            if (intances is IAutoConfig)
            {
                var configValue = Resolve <ITypeService>().GetAutoConfigDictionary(type);
                if (configValue == null)
                {
                    return(ApiResult.Failure <List <KeyValue> >($"{type}不存在"));
                }
                var keyValues = new List <KeyValue>();
                foreach (var item in configValue)
                {
                    keyValues.Add(new KeyValue {
                        Key = item.Key, Value = item.Value
                    });
                }
                return(ApiResult.Success(keyValues));
            }
            return(null);
        }
Пример #5
0
        public void EnumToKeyValues_Type_test(Type type)
        {
            var result = KeyValueExtesions.EnumToKeyValues(type);

            Assert.NotNull(result);
        }