Errors with 3.0

Oct 28, 2009 at 8:08 PM

Hello,

I'm getting an error (and some warnings) using Xsd2Code 3.0.

The error is with string properties, the generated code is as follows:

public string Phone
{
	get
	{
		if ((this.phoneField == null))
		{
			this.phoneField = new string();
		}
		return this.phoneField;
	}

...

}

Which generates the error:

'string' does not contain a constructor that takes '0' arguments


I believe the null check could be eliminated for all value types which would also solve one of the warnings listed below.


The two basic types of warnings I'm getting are:
  1. On value type parameters I'm getting:
    The result of the expression is always 'true' since a value of type 'decimal' is never equal to 'null' of type 'decimal?'
    I believe this is the same issue that was fixed in 3.0 for Enum types (ie Fix warnning when setter test if field is null on enum type.) and could be fixed by not checking for null on value types.
  2. For inherited classes with IncludeSerializationMethod=True and UseGenericBaseClass=False I'm getting:
    'AirLegType.Serialize()' hides inherited member 'SegmentType.Serialize()'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.
    I think in this instance the override keyword would be the correct solution.
Thanks for this great tool!
-Ryan

 

 

Coordinator
Nov 1, 2009 at 4:17 PM
Hi,
Thank you for your feedback.
Can you give me your generation option because i can't reproduce this case.
Pascal.

2009/10/28 iolaus <notifications@codeplex.com>

From: iolaus

Hello,

I'm getting an error (and some warnings) using Xsd2Code 3.0.

The error is with string properties, the generated code is as follows:

public string Phone
{
	get
	{
		if ((this.phoneField == null))
		{
			this.phoneField = new string();
		}
		return this.phoneField;
	}

...

}

Which generates the error:

'string' does not contain a constructor that takes '0' arguments


I believe the null check could be eliminated for all value types which would also solve one of the warnings listed below.


The two basic types of warnings I'm getting are:
  1. On value type parameters I'm getting:
    The result of the expression is always 'true' since a value of type 'decimal' is never equal to 'null' of type 'decimal?'
    I believe this is the same issue that was fixed in 3.0 for Enum types (ie Fix warnning when setter test if field is null on enum type.) and could be fixed by not checking for null on value types.
  2. For inherited classes with IncludeSerializationMethod=True and UseGenericBaseClass=False I'm getting:
    'AirLegType.Serialize()' hides inherited member 'SegmentType.Serialize()'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.
    I think in this instance the override keyword would be the correct solution.
Thanks for this great tool!
-Ryan

 

 

Read the full discussion online.

To add a post to this discussion, reply to this email (Xsd2Code@discussions.codeplex.com)

To start a new discussion for this project, email Xsd2Code@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Nov 9, 2009 at 2:25 PM

I submitted a patch to bug http://xsd2code.codeplex.com/WorkItem/View.aspx?WorkItemId=9029 which addresses this issue as well. it uses cross - language String.Empty in case of a String.