コード例 #1
0
        private ApiClassInfo GenerateDictionary(Type dictionaryType, int size, Dictionary <Type, object> createdObjectReferences)
        {
            var  classInfo = new ApiClassInfo(dictionaryType, ApiPropertyType.ArrayObject);
            Type typeK     = typeof(object);
            Type typeV     = typeof(object);

            if (dictionaryType.IsGenericType)
            {
                Type[] genericArgs = dictionaryType.GetGenericArguments();
                typeK = genericArgs[0];
                typeV = genericArgs[1];
            }

            ObjectGeneratorEx objectGenerator = new ObjectGeneratorEx();

            for (int i = 0; i < size; i++)
            {
                var ci       = new ApiClassInfo(dictionaryType, ApiPropertyType.ClassObject);
                var newKey   = objectGenerator.GenerateObject(typeK, createdObjectReferences);
                var newValue = objectGenerator.GenerateObject(typeV, createdObjectReferences);
                newKey.Name   = "Key";
                newValue.Name = "Value";
                ci.Properties.Add(newKey);
                ci.Properties.Add(newValue);
                classInfo.Properties.Add(ci);
            }

            return(classInfo);
        }
コード例 #2
0
        private ApiClassInfo GenerateNullable(Type nullableType, Dictionary <Type, object> createdObjectReferences)
        {
            Type type = nullableType.GetGenericArguments()[0];
            ObjectGeneratorEx objectGenerator = new ObjectGeneratorEx();
            var ci = objectGenerator.GenerateObject(type, createdObjectReferences);

            ci.CanNull = true;
            return(ci);
        }
コード例 #3
0
        private ApiClassInfo GenerateKeyValuePair(Type keyValuePairType, Dictionary <Type, object> createdObjectReferences)
        {
            var classInfo = new ApiClassInfo(keyValuePairType, ApiPropertyType.ClassObject);

            Type[]            genericArgs     = keyValuePairType.GetGenericArguments();
            Type              typeK           = genericArgs[0];
            Type              typeV           = genericArgs[1];
            ObjectGeneratorEx objectGenerator = new ObjectGeneratorEx();
            var keyObject   = objectGenerator.GenerateObject(typeK, createdObjectReferences);
            var valueObject = objectGenerator.GenerateObject(typeV, createdObjectReferences);

            keyObject.Name   = "Key";
            valueObject.Name = "Value";
            classInfo.Properties.Add(keyObject);
            classInfo.Properties.Add(valueObject);

            return(classInfo);
        }
コード例 #4
0
        private ApiClassInfo GenerateArray(Type arrayType, int size, Dictionary <Type, object> createdObjectReferences)
        {
            var classInfo = new ApiClassInfo(arrayType, ApiPropertyType.ArrayObject);

            Type type = arrayType.GetElementType();
            ObjectGeneratorEx objectGenerator = new ObjectGeneratorEx();

            for (int i = 0; i < size; i++)
            {
                var ci = objectGenerator.GenerateObject(type, createdObjectReferences);
                classInfo.Properties.Add(ci);
            }

            return(classInfo);
        }
コード例 #5
0
        private List <ApiClassInfo> SetPublicFields(Type type, Dictionary <Type, object> createdObjectReferences)
        {
            List <ApiClassInfo> infos = new List <ApiClassInfo>();

            FieldInfo[]       fields          = type.GetFields(BindingFlags.Public | BindingFlags.Instance);
            ObjectGeneratorEx objectGenerator = new ObjectGeneratorEx();

            foreach (FieldInfo field in fields)
            {
                var ci = objectGenerator.GenerateObject(field.FieldType, createdObjectReferences);
                ci.Name = field.Name;
                infos.Add(ci);
            }

            return(infos);
        }
コード例 #6
0
        private ApiClassInfo GenerateTuple(Type type, Dictionary <Type, object> createdObjectReferences)
        {
            var classInfo = new ApiClassInfo(type, ApiPropertyType.ClassObject);

            Type[]            genericArgs     = type.GetGenericArguments();
            ObjectGeneratorEx objectGenerator = new ObjectGeneratorEx();

            for (int i = 0; i < genericArgs.Length; i++)
            {
                var ci = objectGenerator.GenerateObject(genericArgs[i], createdObjectReferences);
                ci.Name = $"Item{i + 1}";
                classInfo.Properties.Add(ci);
            }

            return(classInfo);
        }
コード例 #7
0
        private ApiClassInfo GenerateCollection(Type collectionType, int size, Dictionary <Type, object> createdObjectReferences)
        {
            var  classInfo = new ApiClassInfo(collectionType, ApiPropertyType.ArrayObject);
            Type type      = collectionType.IsGenericType ?
                             collectionType.GetGenericArguments()[0] :
                             typeof(object);
            bool areAllElementsNull           = true;
            ObjectGeneratorEx objectGenerator = new ObjectGeneratorEx();

            for (int i = 0; i < size; i++)
            {
                var ci = objectGenerator.GenerateObject(type, createdObjectReferences);
                classInfo.Properties.Add(ci);
            }

            return(classInfo);
        }
コード例 #8
0
        private List <ApiClassInfo> SetPublicProperties(Type type, Dictionary <Type, object> createdObjectReferences)
        {
            List <ApiClassInfo> infos = new List <ApiClassInfo>();

            PropertyInfo[]    properties      = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            ObjectGeneratorEx objectGenerator = new ObjectGeneratorEx();

            foreach (PropertyInfo property in properties)
            {
                if (property.CanWrite || property.CanRead)
                {
                    var ci = objectGenerator.GenerateObject(property.PropertyType, createdObjectReferences);
                    ci.Name = property.Name;
                    infos.Add(ci);
                }
            }
            return(infos);
        }
コード例 #9
0
ファイル: ApiHelper.cs プロジェクト: 775083111/GMS
        /// <summary>
        /// 获取类信息
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public ApiClassInfo GetApiInfoByType(Type type)
        {
            ObjectGeneratorEx ex = new ObjectGeneratorEx();

            return(ex.GenerateObject(type));
        }