Closed zijianhuang closed 5 years ago
Implemented. However, found not needed. enum could be number at run time, and become index of array.
static void WriteEnumMembersAndCloseBracing(CodeTypeDeclaration typeDeclaration, TextWriter w, CodeGeneratorOptions o)
{
var currentIndent = o.IndentString;
o.IndentString += BasicIndent;
var enumMembers = typeDeclaration.Members.OfType<CodeTypeMember>().ToList();
bool anyMemberDocComment = enumMembers.Any(d => d.Comments.Count > 0);
bool anyInit = enumMembers.Any(ctm =>
{
var codeMemberField = ctm as CodeMemberField;
var initExpression = codeMemberField.InitExpression as CodePrimitiveExpression;
return initExpression != null;
});
if (!anyInit)
{
var i = 0;
enumMembers.ForEach(ctm =>
{
var codeMemberField = ctm as CodeMemberField;
codeMemberField.InitExpression = new CodePrimitiveExpression(i);
i++;
});
}
if (anyMemberDocComment)
{
var i = 0;
w.WriteLine();
enumMembers.ForEach(ctm =>
{
if (i > 0)
{
w.WriteLine(",");
}
var codeMemberField = ctm as CodeMemberField;
System.Diagnostics.Trace.Assert(codeMemberField != null);
//Handle the comment of the member
WriteCodeCommentStatementCollection(ctm.Comments, w, o);//This will create a new line first
w.Write(o.IndentString);
var enumMemberText = GetEnumMember(codeMemberField);
w.Write(enumMemberText);
i++;
});
w.WriteLine();
w.WriteLine(currentIndent + "}");
}
else
{
var i = 0;
w.Write(" ");
enumMembers.ForEach(ctm =>
{
if (i > 0)
{
w.Write(", ");
}
var codeMemberField = ctm as CodeMemberField;
System.Diagnostics.Trace.Assert(codeMemberField != null);
var enumMemberText = GetEnumMember(codeMemberField);
w.Write(enumMemberText);
i++;
});
w.WriteLine(" }");
}
o.IndentString = currentIndent;
}
currently if enum is a sequence starting from zero, int is not exported.
member might have a defaultExpression