mirror of https://github.com/abpframework/abp.git
15 changed files with 225 additions and 22 deletions
@ -0,0 +1,23 @@ |
|||||
|
using System; |
||||
|
using System.Reflection; |
||||
|
|
||||
|
namespace Volo.Abp.Http.Modeling |
||||
|
{ |
||||
|
[Serializable] |
||||
|
public class PropertyApiDescriptionModel |
||||
|
{ |
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
public string TypeAsString { get; set; } |
||||
|
|
||||
|
//TODO: Validation rules for this property
|
||||
|
public static PropertyApiDescriptionModel Create(PropertyInfo propertyInfo) |
||||
|
{ |
||||
|
return new PropertyApiDescriptionModel |
||||
|
{ |
||||
|
Name = propertyInfo.Name, |
||||
|
TypeAsString = propertyInfo.PropertyType.FullName |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,54 @@ |
|||||
|
using System; |
||||
|
using System.Linq; |
||||
|
|
||||
|
namespace Volo.Abp.Http.Modeling |
||||
|
{ |
||||
|
[Serializable] |
||||
|
public class TypeApiDescriptionModel |
||||
|
{ |
||||
|
public string BaseTypeAsString { get; set; } |
||||
|
|
||||
|
public bool IsEnum { get; set; } |
||||
|
|
||||
|
public string[] EnumNames { get; set; } |
||||
|
|
||||
|
public object[] EnumValues { get; set; } |
||||
|
|
||||
|
public PropertyApiDescriptionModel[] Properties { get; set; } |
||||
|
|
||||
|
private TypeApiDescriptionModel() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public static TypeApiDescriptionModel Create(Type type) |
||||
|
{ |
||||
|
var baseType = type.BaseType; |
||||
|
if (baseType == typeof(object)) |
||||
|
{ |
||||
|
baseType = null; |
||||
|
} |
||||
|
|
||||
|
var typeModel = new TypeApiDescriptionModel |
||||
|
{ |
||||
|
IsEnum = type.IsEnum, |
||||
|
BaseTypeAsString = baseType?.FullName |
||||
|
}; |
||||
|
|
||||
|
if (typeModel.IsEnum) |
||||
|
{ |
||||
|
typeModel.EnumNames = type.GetEnumNames(); |
||||
|
typeModel.EnumValues = type.GetEnumValues().Cast<object>().ToArray(); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
typeModel.Properties = type |
||||
|
.GetProperties() |
||||
|
.Select(PropertyApiDescriptionModel.Create) |
||||
|
.ToArray(); |
||||
|
} |
||||
|
|
||||
|
return typeModel; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue