Added enum export to documentation generation
This commit is contained in:
committed by
Matthias Mailänder
parent
a985452907
commit
eda3dfa50f
@@ -48,8 +48,11 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
|
||||
static string GenerateJson(string version, IEnumerable<Type> sequenceTypes)
|
||||
{
|
||||
var sequenceTypesInfo = sequenceTypes.Where(x => !x.ContainsGenericParameters && !x.IsAbstract)
|
||||
.Where(x => x.Name != nameof(FileNotFoundSequence)) // NOTE: This is the simplest way to exclude FileNotFoundSequence, which shouldn't be added.
|
||||
var relatedEnumTypes = new HashSet<Type>();
|
||||
|
||||
var sequenceTypesInfo = sequenceTypes
|
||||
.Where(x => !x.ContainsGenericParameters && !x.IsAbstract
|
||||
&& x.Name != nameof(FileNotFoundSequence)) // NOTE: This is the simplest way to exclude FileNotFoundSequence, which shouldn't be added.
|
||||
.Select(type => new
|
||||
{
|
||||
type.Namespace,
|
||||
@@ -71,9 +74,11 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
.GetField(nameof(SpriteSequenceField<bool>.Key))?
|
||||
.GetValue(fi.GetValue(null));
|
||||
|
||||
var defaultValue = fi.FieldType
|
||||
.GetField(nameof(SpriteSequenceField<bool>.DefaultValue))?
|
||||
.GetValue(fi.GetValue(null));
|
||||
var defaultValueField = fi.FieldType.GetField(nameof(SpriteSequenceField<bool>.DefaultValue));
|
||||
var defaultValue = defaultValueField?.GetValue(fi.GetValue(null));
|
||||
|
||||
if (defaultValueField != null && defaultValueField.FieldType.IsEnum)
|
||||
relatedEnumTypes.Add(defaultValueField.FieldType);
|
||||
|
||||
return new
|
||||
{
|
||||
@@ -86,10 +91,22 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
})
|
||||
});
|
||||
|
||||
var relatedEnums = relatedEnumTypes.Select(type => new
|
||||
{
|
||||
type.Namespace,
|
||||
type.Name,
|
||||
Values = Enum.GetNames(type).Select(x => new
|
||||
{
|
||||
Key = Convert.ToInt32(Enum.Parse(type, x)),
|
||||
Value = x
|
||||
})
|
||||
});
|
||||
|
||||
var result = new
|
||||
{
|
||||
Version = version,
|
||||
SpriteSequenceTypes = sequenceTypesInfo
|
||||
SpriteSequenceTypes = sequenceTypesInfo,
|
||||
RelatedEnums = relatedEnums
|
||||
};
|
||||
|
||||
return JsonConvert.SerializeObject(result);
|
||||
|
||||
Reference in New Issue
Block a user