Push updated /Api/Type definition

This commit is contained in:
JustArchi
2018-02-12 11:04:27 +01:00
parent ea2cf23087
commit bb06b9a887
2 changed files with 16 additions and 5 deletions

View File

@@ -1064,7 +1064,7 @@ namespace ArchiSteamFarm {
return obj is Game game && Equals(game); return obj is Game game && Equals(game);
} }
public override int GetHashCode() => (int) (AppID - int.MaxValue); public override int GetHashCode() => (int) (AppID - 1 - int.MaxValue);
} }
} }
} }

View File

@@ -549,24 +549,35 @@ namespace ArchiSteamFarm {
return true; return true;
} }
Dictionary<string, string> result = new Dictionary<string, string>(); Dictionary<string, object> properties = new Dictionary<string, object> {
{ nameof(targetType.BaseType), targetType.BaseType?.GetUnifiedName() },
{ nameof(targetType.CustomAttributes), targetType.CustomAttributes.Select(attribute => attribute.AttributeType.GetUnifiedName()) }
};
Dictionary<string, object> body = new Dictionary<string, object>();
if (targetType.IsClass) { if (targetType.IsClass) {
foreach (FieldInfo field in targetType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).Where(field => !field.IsPrivate)) { foreach (FieldInfo field in targetType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).Where(field => !field.IsPrivate)) {
result[field.Name] = field.FieldType.GetUnifiedName(); body[field.Name] = field.FieldType.GetUnifiedName();
} }
foreach (PropertyInfo property in targetType.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).Where(property => property.CanRead && !property.GetMethod.IsPrivate)) { foreach (PropertyInfo property in targetType.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).Where(property => property.CanRead && !property.GetMethod.IsPrivate)) {
result[property.Name] = property.PropertyType.GetUnifiedName(); body[property.Name] = property.PropertyType.GetUnifiedName();
} }
} else if (targetType.IsEnum) { } else if (targetType.IsEnum) {
Type enumType = Enum.GetUnderlyingType(targetType); Type enumType = Enum.GetUnderlyingType(targetType);
properties["UnderlyingType"] = enumType.GetUnifiedName();
foreach (object value in Enum.GetValues(targetType)) { foreach (object value in Enum.GetValues(targetType)) {
result[value.ToString()] = Convert.ChangeType(value, enumType).ToString(); body[value.ToString()] = Convert.ChangeType(value, enumType).ToString();
} }
} }
Dictionary<string, object> result = new Dictionary<string, object>(2) {
{ "Properties", properties },
{ "Body", body }
};
await ResponseJsonObject(request, response, new GenericResponse(true, "OK", result)).ConfigureAwait(false); await ResponseJsonObject(request, response, new GenericResponse(true, "OK", result)).ConfigureAwait(false);
return true; return true;
} }