private void GenerateModelEnum(Type type) { if (ModelsCodeGenerated.Contains(type) || CannotGenerateAssemblyTypes(type)) { return; } ModelsCodeGenerated.Add(type); EnumReferenceInfo enumReferenceInfo = new EnumReferenceInfo { Name = type.Name, NameSpace = type.Namespace }; Type baseEumType = Enum.GetUnderlyingType(type); enumReferenceInfo.TypeName = GetFullNameOfType(baseEumType, true); foreach (object name in Enum.GetValues(type)) { object res = Convert.ChangeType(name, baseEumType); string value = ""; if (res != null) { value = res.ToString(); } if (!enumReferenceInfo.KeyValues.Any(x => x.Key == name.ToString())) { enumReferenceInfo.KeyValues.Add(new KeyValue <string, string>(name.ToString(), value)); } } NamespaceReferenceInfo.Enums.Add(enumReferenceInfo); }
private void GenerateModelInterface(Type type) { if (type == null) { return; } if (type == typeof(Task)) { return; } else if (type.GetBaseType() == typeof(Task)) { type = type.GetGenericArguments()[0]; } if (type.IsArray) { type = type.GetElementType(); } if (ModelsCodeGenerated.Contains(type) || CannotGenerateAssemblyTypes(type)) { return; } if (type == typeof(object) || type.GetAssembly() == typeof(string).GetAssembly()) { return; } bool isGeneric = type.GetIsGenericType(); if (isGeneric && type.GetGenericTypeDefinition() != type) { GenerateModelClass(type.GetGenericTypeDefinition()); return; } ClassReferenceInfo classReferenceInfo = new ClassReferenceInfo { Type = ClassReferenceType.InterfaceLevel, NameSpace = type.Namespace }; Type baseType = type.GetBaseType(); if (baseType != typeof(object) && baseType != null) { classReferenceInfo.BaseClassName = GetFullNameOfType(baseType, true); } else { classReferenceInfo.BaseClassName = GetFullNameOfType(typeof(NotifyPropertyChangedBase), true); } classReferenceInfo.Name = GetFullNameOfType(type, false); ModelsCodeGenerated.Add(type); foreach (PropertyInfo propertyInfo in type.GetListOfDeclaredProperties()) { GenerateProperty(propertyInfo, classReferenceInfo); } GenerateModelInterface(type.GetBaseType()); NamespaceReferenceInfo.Classes.Add(classReferenceInfo); }