简体   繁体   English

在.NET-core中从ODataV4元数据XML提取类

[英]Extracting classes from ODataV4 Metadata XML in .NET-core

I downloaded the file ODataV4Metadata.xml from Microsoft Dynamics 365. This file contains many EntityType tags in which classes are described. 我从Microsoft Dynamics 365下载了文件ODataV4Metadata.xml 。此文件包含许多EntityType标记,其中描述了类。 For reference, this is how it (partly) looks: 作为参考,这是它的(部分)外观:

<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="Microsoft.Dynamics.CRM" Alias="mscrm">
            <EntityType Name="crmbaseentity" Abstract="true" />
            <EntityType Name="accountleads" BaseType="mscrm.crmbaseentity">
                <Key>
                    <PropertyRef Name="accountleadid" />
                </Key>
                <Property Name="accountleadid" Type="Edm.Guid" />
                <Property Name="overriddencreatedon" Type="Edm.DateTimeOffset" />
                <Property Name="timezoneruleversionnumber" Type="Edm.Int32" />
                <Property Name="importsequencenumber" Type="Edm.Int32" />
...etc

This should, for example, generate a class called Accountleads , with properties like 例如,这应生成一个名为Accountleads的类,其属性如

[DataMember(Name = "overriddencreatedon")]
        public System.DateTimeOffset? Overriddencreatedon
        {
            get
            {
                return this._Overriddencreatedon;
            }
            set
            {
                this._Overriddencreatedon = value;
            }
         }

As I'm working in .NET-core it seems rather impossible. 当我在.NET核心中工作时,这似乎是不可能的。 I was able to generate a HUGE (100k lines of code) file consisting out of all the EntityTypes with lots of comments. 我能够生成一个巨大的(100k行代码)文件,其中包含所有带有大量注释的EntityTypes However, it seems I am not able to do this in .NET-core, although I am able to use the generated classes. 但是,尽管我能够使用生成的类,但似乎无法在.NET-core中执行此操作。 The second problem is, it generates just one file, with all classes in it (and it doesn't include all the namespaces beforehand using the using keyword) 第二个问题是,它只生成一个文件,其中包含所有类(并且使用using关键字事先不包括所有名称空间)

Is there any tool which has some more flexibility, works in .NET-core and generates classes in separate files? 是否有任何工具具有更大的灵活性,可以在.NET核心中运行并且可以在单独的文件中生成类? Googling it gives many solutions in ASP.NET and .NET v4. 谷歌搜索它为ASP.NET和.NET v4提供了许多解决方案。

If necessary I will make an Open Source tool to do this, but maybe I haven't looked at enough places. 如有必要,我将制作一个开放源代码工具来执行此操作,但也许我没有研究足够的地方。


Sources I checked: 我检查的来源:

The out-of-box tool for creating early-bound proxy classes is CrmSvcUtil . 用于创建早期绑定代理类的现成工具是CrmSvcUtil

Daryl LaBar has written the Early Bound Generator for XrmToolbox , which I believe leverages CrmSvcUtil. Daryl LaBar已经为XrmToolbox编写了Early Bound Generator ,我相信它利用CrmSvcUtil。

There's a commercial VS add-on for D365 called XrmToolkit that includes the ability to create proxy classes (using a proprietary algorithm, so they are different from the classes that CrmSvcUtil generates). D365有一个名为XrmToolkit的商业VS附加组件 ,它具有创建代理类的功能(使用专有算法,因此它们不同于CrmSvcUtil生成的类)。 This is the tool I use, and it does create each class as a separate file. 这是我使用的工具,它确实将每个类创建为单独的文件。

As a side note, Jason Lattimer's D365 Developer Extensions has a lot of helpful features, but I don't believe it has built-in proxy class generation. 附带说明一下,Jason Lattimer的D365开发人员扩展具有许多有用的功能,但是我不相信它具有内置的代理类生成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM