Skip to content

Commit 00219b0

Browse files
committed
Генерация элементов для SystemEnum
1 parent 5dcfa16 commit 00219b0

File tree

2 files changed

+85
-2
lines changed

2 files changed

+85
-2
lines changed

src/OneScriptDocumenter/Cli/MarkdownGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ private void WriteMethods(MarkdownWriter writer, IList<MethodModel> methModels)
186186
itemBuilder.Append($"**{parameterModel.Name}**: {parameterModel.Description}");
187187
if (parameterModel.IsOptional)
188188
{
189-
itemBuilder.Append(" *Необязательный.* ");
189+
itemBuilder.Append(" *Необязательный*. ");
190190

191191
if (!string.IsNullOrEmpty(parameterModel.DefaultValue))
192192
itemBuilder.Append($"Значение по умолчанию: {parameterModel.DefaultValue}");
@@ -233,7 +233,7 @@ private void WriteConstructors(MarkdownWriter writer, IList<MethodModel> methMod
233233
itemBuilder.Append($"**{parameterModel.Name}**: {parameterModel.Description}");
234234
if (parameterModel.IsOptional)
235235
{
236-
itemBuilder.Append(" *Необязательный.* ");
236+
itemBuilder.Append(" *Необязательный*. ");
237237
if (!string.IsNullOrEmpty(parameterModel.DefaultValue))
238238
itemBuilder.Append($"Значение по умолчанию: {parameterModel.DefaultValue}");
239239
}

src/OneScriptDocumenter/Secondary/DocumentationModelBuilder.cs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This Source Code Form is subject to the terms of the
66
----------------------------------------------------------*/
77

88
using System;
9+
using System.Collections;
910
using System.Collections.Generic;
1011
using System.IO;
1112
using System.Linq;
@@ -14,6 +15,8 @@ This Source Code Form is subject to the terms of the
1415
using System.Xml.Linq;
1516
using OneScript.Contexts;
1617
using OneScript.Localization;
18+
using OneScript.Types;
19+
using OneScript.Values;
1720
using OneScriptDocumenter.Model;
1821
using OneScriptDocumenter.Primary;
1922
using ArgumentException = System.ArgumentException;
@@ -136,10 +139,37 @@ private IDocument MakeSystemEnumNode(PrimaryBslDocument primaryDoc)
136139
Owner = primaryDoc.Owner,
137140
Name = new BilingualString(typeMarkup.Name, typeMarkup.Alias),
138141
Description = XmlSummary(primaryDoc.SelfDoc),
142+
Items = LoadSystemEnumItems(primaryDoc.Owner),
139143
Example = XmlTextBlock(primaryDoc.SelfDoc, "example")
140144
};
141145
}
142146

147+
private List<EnumItemModel> LoadSystemEnumItems(Type enumType)
148+
{
149+
var items = new List<EnumItemModel>();
150+
var instantiator = enumType.GetMethod("CreateInstance", BindingFlags.Static | BindingFlags.Public);
151+
if (instantiator == null)
152+
return items;
153+
154+
var enumInstance = (IEnumerable)instantiator.Invoke(null, new[] { new FakeTypeManager() });
155+
if (enumInstance == null)
156+
return items;
157+
158+
159+
foreach (var unknownTypeItem in enumInstance)
160+
{
161+
if (unknownTypeItem is EnumerationValue enumValue)
162+
{
163+
items.Add(new EnumItemModel
164+
{
165+
Name = new BilingualString(enumValue.Name, enumValue.Alias)
166+
});
167+
}
168+
}
169+
170+
return items;
171+
}
172+
143173
private IDocument MakeSimpleEnumNode(PrimaryBslDocument primaryDoc)
144174
{
145175
var typeMarkup = MarkupProvider.GetEnumMarkup(primaryDoc.Owner);
@@ -372,5 +402,58 @@ private string XmlTextBlock(XElement docs, string nodeName, bool isCode = false)
372402
return stringValue == "" ? null : // Чтобы свойство не писал сериализатор JSON
373403
stringValue;
374404
}
405+
406+
private class FakeTypeManager : ITypeManager
407+
{
408+
public TypeDescriptor GetTypeByName(string name)
409+
{
410+
throw new NotImplementedException();
411+
}
412+
413+
public TypeDescriptor GetTypeByFrameworkType(Type type)
414+
{
415+
throw new NotImplementedException();
416+
}
417+
418+
public bool TryGetType(string name, out TypeDescriptor type)
419+
{
420+
throw new NotImplementedException();
421+
}
422+
423+
public bool TryGetType(Type frameworkType, out TypeDescriptor type)
424+
{
425+
throw new NotImplementedException();
426+
}
427+
428+
public TypeDescriptor RegisterType(string name, string alias, Type implementingClass)
429+
{
430+
return default;
431+
}
432+
433+
public void RegisterType(TypeDescriptor typeDescriptor)
434+
{
435+
436+
}
437+
438+
public ITypeFactory GetFactoryFor(TypeDescriptor type)
439+
{
440+
throw new NotImplementedException();
441+
}
442+
443+
public bool IsKnownType(Type type)
444+
{
445+
throw new NotImplementedException();
446+
}
447+
448+
public bool IsKnownType(string typeName)
449+
{
450+
throw new NotImplementedException();
451+
}
452+
453+
public IReadOnlyList<TypeDescriptor> RegisteredTypes()
454+
{
455+
throw new NotImplementedException();
456+
}
457+
}
375458
}
376459
}

0 commit comments

Comments
 (0)