Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate classes without DataAnnotations #314

Open
IceTrooper opened this issue Mar 25, 2022 · 5 comments
Open

Generate classes without DataAnnotations #314

IceTrooper opened this issue Mar 25, 2022 · 5 comments

Comments

@IceTrooper
Copy link

IceTrooper commented Mar 25, 2022

Is it possible to generate C# classes without the DataAnnotations?
I'm using the generated classes inside Unity and I got an error:
Assets\Scripts\Integrations\OpenDrive\XsdSchemas\out\Integrations.OpenDRIVE.cs(4987,48): error CS1069: The type name 'RequiredAttributeAttribute' could not be found in the namespace 'System.ComponentModel.DataAnnotations'. This type has been forwarded to assembly 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' Consider adding a reference to that assembly.
and I can't add that reference to the project (I won't be even using those features).

Thank you :)

@mganss
Copy link
Owner

mganss commented Mar 25, 2022

This is currently not possible. What does the generated code look like? RequiredAttributeAttribute sounds strange, it should be RequiredAttribute.

@IceTrooper
Copy link
Author

IceTrooper commented Mar 28, 2022

Sorry for the delayed reply.

The code looks like this:

/// <summary>
/// <para>s-coordinate of start position</para>
/// <para xml:lang="en">Minimum inclusive value: 0.0.</para>
/// </summary>
[System.ComponentModel.DescriptionAttribute("s-coordinate of start position")]
//[System.ComponentModel.DataAnnotations.RequiredAttribute()]
[System.Xml.Serialization.XmlAttributeAttribute("s")]
public double S { get; set; }

/// <summary>
/// <para>Start position (x inertial)</para>
/// </summary>
[System.ComponentModel.DescriptionAttribute("Start position (x inertial)")]
//[System.ComponentModel.DataAnnotations.RequiredAttribute()]
[System.Xml.Serialization.XmlAttributeAttribute("x")]
public double X { get; set; }

/// <summary>
/// <para>Start position (y inertial)</para>
/// </summary>
[System.ComponentModel.DescriptionAttribute("Start position (y inertial)")]
//[System.ComponentModel.DataAnnotations.RequiredAttribute()]
[System.Xml.Serialization.XmlAttributeAttribute("y")]
public double Y { get; set; }

Because of that, I had to manually comment out all of the occurrences of DataAnnotations, which is doable with Find and Replace, but tedious and I think it's not the right way of doing this. :/

This is the screenshot of the problem inside Visual Studio.
obraz

I know that in an ordinary .NET application, you just need to add a reference to the appropriate assembly. However, in Unity it is not so trivial nor currently desired.

@mganss
Copy link
Owner

mganss commented Mar 31, 2022

OK I'll try and make this configurable. I won't be getting to it until next week, though.

@IceTrooper
Copy link
Author

That's awesome to hear! The project where I'm using this tool will still be a while away, so it's no problem to wait for a little. Plus I think anyone using this tool on Unity projects would appreciate that configuration option.

As I've read on many forums these DataAnnotations due to being in a different .dll than the rest are a pain in the ass (even outside of Unity projects).

@mganss
Copy link
Owner

mganss commented Apr 4, 2022

There already is support for this feature through the -c option (PCL compatible output). This does a few other things as well but hopefully those won't impact your use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants