English 中文(简体)
Generating classes using XSD without base class in each one
原标题:

Not sure what the appropriate tags are here...

A while back I created a batch script which, when run will convert all .xsd files found in C:api into C# classes using the xsd.exe file found in the Microsoft Windows SDK (using v6.1 here).

@ECHO OFF
CLS
ECHO ***
ECHO Runs xsd.exe on all *.xsd files sorted by filename in the current folder.
ECHO ***

FOR /R "C:api" %%G IN (*.xsd) DO (
  @ECHO ON
  "C:Program FilesMicrosoft SDKsWindowsv6.1Binxsd.exe" "C:apiasease.xsd" "%%G" /c /n:Mynamespace /o:"C:api"
  @ECHO OFF
)

The problem is this... I have 50 or so generated .cs files, including the base class. And inside every single one, it generates a copy of the base class, so I end up with the base class in every class, when I only need it in one.

Is there a way of preventing the class being generated without the base class in each one? I still want the base class to be created (base.cs), but just not in the other 49 classes.

Edit:

I have tried the following:

@ECHO OFF
SET str1=
FOR /R "C:api" %%G IN (*.xsd) DO (
  SET str1="%%G" %str1%
)

ECHO %str1%

The response returned is always the last file in the list.

最佳回答

You can pass multiple XML schema files to xsd.exe at once instead of looping through the files and passing each file separately. The list of schema files being passed would not be dynamic though...

Also this creates only one .cs file, named after the first XML schema file in the list, containing all classes.

问题回答

For your second problem, you have to set delayed expansion.

And use !str! instead of %str%

give this a try

SETLOCAL enabledelayedexpansion
@ECHO OFF
SET str1=
FOR /R "C:api" %%G IN (*.xsd) DO (
  SET str1="%%G" !str1!
)
ECHO !str1!




相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签