Skip to content

Commit

Permalink
Merge pull request #26 from atheck/master
Browse files Browse the repository at this point in the history
Order for Any Attribute, optional DebuggerStepThroughAttribute
  • Loading branch information
mganss authored May 12, 2017
2 parents d94aead + 0a43907 commit 6ccc105
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
8 changes: 6 additions & 2 deletions XmlSchemaClassGenerator.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static void Main(string[] args)
Type collectionImplementationType = null;
var codeTypeReferenceOptions = default(CodeTypeReferenceOptions);
string textValuePropertyName = "Value";
var generateDebuggerStepThroughAttribute = true;

var options = new OptionSet {
{ "h|help", "show this message and exit", v => showHelp = v != null },
Expand Down Expand Up @@ -72,7 +73,8 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l
{ "ct|collectionType=", "collection type to use (default is " + typeof(Collection<>).FullName + ")", v => collectionType = v == null ? typeof(Collection<>) : Type.GetType(v, true) },
{ "cit|collectionImplementationType=", "the default collection type implementation to use (default is null)", v => collectionImplementationType = v == null ? null : Type.GetType(v, true) },
{ "ctro|codeTypeReferenceOptions=", "the default CodeTypeReferenceOptions Flags to use (default is unset; can be: {GlobalReference, GenericTypeParameter})", v => codeTypeReferenceOptions = v == null ? default(CodeTypeReferenceOptions) : (CodeTypeReferenceOptions)Enum.Parse(typeof(CodeTypeReferenceOptions), v, false) },
{ "tvpn|textValuePropertyName=", "the name of the property that holds the text value of an element (default is Value)", v => textValuePropertyName = v }
{ "tvpn|textValuePropertyName=", "the name of the property that holds the text value of an element (default is Value)", v => textValuePropertyName = v },
{ "dst|debuggerStepThrough", "generate DebuggerStepThroughAttribute (default is enabled)", v => generateDebuggerStepThroughAttribute = v != null }
};

var files = options.Parse(args);
Expand Down Expand Up @@ -113,14 +115,16 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l
CollectionType = collectionType,
CollectionImplementationType = collectionImplementationType,
CodeTypeReferenceOptions = codeTypeReferenceOptions,
TextValuePropertyName = textValuePropertyName
TextValuePropertyName = textValuePropertyName,
GenerateDebuggerStepThroughAttribute = generateDebuggerStepThroughAttribute
};

if (pclCompatible)
{
generator.UseXElementForAny = true;
generator.GenerateDesignerCategoryAttribute = false;
generator.GenerateSerializableAttribute = false;
generator.GenerateDebuggerStepThroughAttribute = false;
generator.DataAnnotationMode = DataAnnotationMode.None;
}

Expand Down
6 changes: 6 additions & 0 deletions XmlSchemaClassGenerator/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ public bool GenerateSerializableAttribute
set { _configuration.GenerateSerializableAttribute = value; }
}

public bool GenerateDebuggerStepThroughAttribute
{
get { return _configuration.GenerateDebuggerStepThroughAttribute; }
set { _configuration.GenerateDebuggerStepThroughAttribute = value; }
}

public bool GenerateDesignerCategoryAttribute
{
get { return _configuration.GenerateDesignerCategoryAttribute; }
Expand Down
4 changes: 4 additions & 0 deletions XmlSchemaClassGenerator/GeneratorConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public GeneratorConfiguration()
/// </summary>
public bool GenerateSerializableAttribute { get; set; }
/// <summary>
/// Generate the DebuggerStepThroughAttribute?
/// </summary>
public bool GenerateDebuggerStepThroughAttribute { get; set; }
/// <summary>
/// Generate the DesignerCategoryAttribute?
/// </summary>
public bool GenerateDesignerCategoryAttribute { get; set; }
Expand Down
16 changes: 12 additions & 4 deletions XmlSchemaClassGenerator/TypeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,10 @@ public override CodeTypeDeclaration Generate()
classDeclaration.Members.Add(text);
}

classDeclaration.CustomAttributes.Add(
new CodeAttributeDeclaration(new CodeTypeReference(typeof(DebuggerStepThroughAttribute), Configuration.CodeTypeReferenceOptions)));
if (Configuration.GenerateDebuggerStepThroughAttribute)
classDeclaration.CustomAttributes.Add(
new CodeAttributeDeclaration(new CodeTypeReference(typeof(DebuggerStepThroughAttribute), Configuration.CodeTypeReferenceOptions)));

if (Configuration.GenerateDesignerCategoryAttribute)
{
classDeclaration.CustomAttributes.Add(
Expand Down Expand Up @@ -864,7 +866,10 @@ private IEnumerable<CodeAttributeDeclaration> GetAttributes(bool isArray)
{
if (IsAny)
{
attributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(XmlAnyAttributeAttribute), Configuration.CodeTypeReferenceOptions)));
var anyAttribute = new CodeAttributeDeclaration(new CodeTypeReference(typeof(XmlAnyAttributeAttribute), Configuration.CodeTypeReferenceOptions));
if (Order != null)
anyAttribute.Arguments.Add(new CodeAttributeArgument("Order", new CodePrimitiveExpression(Order.Value)));
attributes.Add(anyAttribute);
}
else
{
Expand All @@ -876,7 +881,10 @@ private IEnumerable<CodeAttributeDeclaration> GetAttributes(bool isArray)
{
if (IsAny)
{
attributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(XmlAnyElementAttribute), Configuration.CodeTypeReferenceOptions)));
var anyAttribute = new CodeAttributeDeclaration(new CodeTypeReference(typeof(XmlAnyElementAttribute), Configuration.CodeTypeReferenceOptions));
if (Order != null)
anyAttribute.Arguments.Add(new CodeAttributeArgument("Order", new CodePrimitiveExpression(Order.Value)));
attributes.Add(anyAttribute);
}
else
{
Expand Down

0 comments on commit 6ccc105

Please sign in to comment.