multi-base class defintions occuring in CSharp.

Aug 21, 2010 at 6:46 AM

Hello,  I was working with this XSD: http://schemas.dmtf.org/ovf/envelope/1/dsp8023_1.1.xsd

I'm a bit new using this library, I didn't see or missed if this came up before, so I'm not sure if I'm missing a flag or something, but I'm pretty sure C# does not do multi-inheritance in this manner. This is what I started for params (borrowed from the library unit test).

var xsdGen = new GeneratorFacade(new GeneratorParams() { TargetFramework = TargetFramework.Net35, 
GenerateCloneMethod = true,
IncludeSerializeMethod = true,
AutomaticProperties = true,
InputFilePath = inputFilePath,
NameSpace = "Ovf.Definition",
CollectionObjectType = CollectionType.ObservableCollection,
EnableDataBinding = true,
Language = GenerationLanguage.CSharp });
var result = xsdGen.GenerateBytes();


When the code got generated there are many segments like: 

    [System.Xml.Serialization.XmlIncludeAttribute(typeof(qualifierSArray))]
    public partial class qualifierString : cimString, EntityBase<qualifierString> {        
        private bool qualifierField;        
        public bool qualifier {
            get {
                return this.qualifierField;
            }
            set {
                if ((qualifierField.Equals(value) != true)) {
                    this.qualifierField = value;
                    this.OnPropertyChanged("qualifier");
                }
            }
        }
    }
   
    public partial class qualifierSArray : qualifierString, EntityBase<qualifierSArray> {
    }
   
    public partial class cimChar16 : cimString, EntityBase<cimChar16> {
    }

Thank you for your time

-Thomas

Coordinator
Aug 21, 2010 at 8:34 AM

Hi, in your case use flag GenerateBaseClass=false.

Thank you for your feedback.

Aug 21, 2010 at 9:12 AM

Thank you for the quick reply.  I was also using the wrong 'branch' so I switched to trunk and used the following which generates the dll

            var xsdGen = new GeneratorFacade(new GeneratorParams() { DisableDebug = false,
                                                                     EnableDataBinding = false, 
                                                                     EnableSummaryComment = false,
                                                                     GenerateCloneMethod = false,
                                                                     GenerateDataContracts = false,                                                                     
                                                                     HidePrivateFieldInIde = false,
                                                                     EnableInitializeFields = false,                                                                     
                                                                     TargetFramework = TargetFramework.Net35,
                                                                     AutomaticProperties = false,
                                                                     InputFilePath = inputFilePath, 
                                                                     NameSpace = "Ovf.Definition", 
                                                                     CollectionObjectType = CollectionType.List,                                                                      
                                                                     Language = GenerationLanguage.CSharp });

It would have been nice to auto-gen the Generic base class, do you plan for an update to that?  I couldn't the file, in Code Template: ObjectChangeTracker.cs.txt  so I used the pattern of the other files and took it from the Extras.

Thank you

-Thomas

Coordinator
Aug 22, 2010 at 9:44 AM
Hi, you can update source from CodePlex. I added the missing files and i also checking my last changes (Minor update on ObjectChangeTracking)..
Yes I plan an update that fixes the problem you've encountered. I can not give you a date because I'm working on this project on my personal time
Pascal.

2010/8/21 albadraco <notifications@codeplex.com>

From: albadraco

Thank you for the quick reply.  I was also using the wrong 'branch' so I switched to trunk and used the following which generates the dll

            var xsdGen = new GeneratorFacade(new GeneratorParams() { DisableDebug = false,
                                                                     EnableDataBinding = false, 
                                                                     EnableSummaryComment = false,
                                                                     GenerateCloneMethod = false,
                                                                     GenerateDataContracts = false,                                                                     
                                                                     HidePrivateFieldInIde = false,
                                                                     EnableInitializeFields = false,                                                                     
                                                                     TargetFramework = TargetFramework.Net35,
                                                                     AutomaticProperties = false,
                                                                     InputFilePath = inputFilePath, 
                                                                     NameSpace = "Ovf.Definition", 
                                                                     CollectionObjectType = CollectionType.List,                                                                      
                                                                     Language = GenerationLanguage.CSharp });

It would have been nice to auto-gen the Generic base class, do you plan for an update to that?  I couldn't the file, in Code Template: ObjectChangeTracker.cs.txt  so I used the pattern of the other files and took it from the Extras.

Thank you

-Thomas

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


Aug 27, 2010 at 11:22 PM

I was stepping through the code with this base class duplication issue,  I made a simple change that might work in most cases, an edge case would be the use of Interfaces, if the BaseTypes collection contained only Interfaces, it probably would fail.

Here is the change I did, hopefully this will help.

File: CodeExtension.cs
Line: 288

            if (GeneratorContext.GeneratorParams.GenericBaseClass.Enabled)
            {
                var ctr = new CodeTypeReference(GeneratorContext.GeneratorParams.GenericBaseClass.BaseClassName);
                ctr.TypeArguments.Add(new CodeTypeReference(type.Name));
                type.BaseTypes.Add(ctr);
            }

I changed it to:

            if (GeneratorContext.GeneratorParams.GenericBaseClass.Enabled && type.BaseTypes.Count <= 0)
            {
                var ctr = new CodeTypeReference(GeneratorContext.GeneratorParams.GenericBaseClass.BaseClassName);
                ctr.TypeArguments.Add(new CodeTypeReference(type.Name));
                type.BaseTypes.Add(ctr);
            }
In the XSD's I've been using this seems to work in all my cases, I hope this can help, but then I don't have any Interfaces defined.
Thank you
-Thomas

 

Coordinator
Aug 29, 2010 at 8:10 AM

Thank you Thomas.
I'am agree with your change.
Pascal.

Le 28 août 2010 00:22, "albadraco" <notifications@codeplex.com> a écrit :

From: albadraco

I was stepping through the code with this base class duplication issue,  I made a simple change that might work in most cases, an edge case would be the use of Interfaces, if the BaseTypes collection contained only Interfaces, it probably would fail.

Here is the change I did, hopefully this will help.

File: CodeExtension.cs
Line: 288

            if (GeneratorContext.GeneratorParams.GenericBaseClass.Enabled)
            {
                var ctr = new CodeTypeReference(GeneratorContext.GeneratorParams.GenericBaseClass.BaseClassName);
                ctr.TypeArguments.Add(new CodeTypeReference(type.Name));
                type.BaseTypes.Add(ctr);
            }

I changed it to:

            if (GeneratorContext.GeneratorParams.GenericBaseClass.Enabled && type.BaseTypes.Count <= 0)
            {
                var ctr = new CodeTypeReference(GeneratorContext.GeneratorParams.GenericBaseClass.BaseClassName);
                ctr.TypeArguments.Add(new CodeTypeReference(type.Name));
                type.BaseTypes.Add(ctr);
            }
In the XSD's I've been using this seems to work in all my cases, I hope this can help, but then I don't have any Interfaces defined.
Thank you
-Thomas

 



Read the full discussion online.

To add a post to this discussion, reply to this email (Xsd2Code@...