从实体元数据中提取属性的显示名称

Pulling the Display name of an attribute from entity Metadata

我在尝试使用 C# 从 CRM 获取数据方面相当陌生,我正在尝试获取 CRM 上所有属性的显示名称,当我尝试时,我得到的结果是 Microsoft.Xrm.Sdk.Label而且获得该标签的价值似乎并不直接,有人可以指出我正确的方向吗?

using System;    
using Microsoft.Xrm.Tooling.Connector;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;


namespace CRM_MetaData_Download
{
    class Program
    {
        static void Main(string[] args)
        {
            try {
                var connectionString = @"AuthType = Office365; Url = https://CRMINFORMATION";
                CrmServiceClient conn = new CrmServiceClient(connectionString);

                IOrganizationService service;
                service = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
                RetrieveEntityRequest retrieveEntityRequest = new RetrieveEntityRequest
                {
                    EntityFilters = EntityFilters.All,
                    LogicalName = "account"
                };
                RetrieveEntityResponse retrieveAccountEntityResponse = (RetrieveEntityResponse)service.Execute(retrieveEntityRequest);
                EntityMetadata AccountEntity = retrieveAccountEntityResponse.EntityMetadata;

                Console.WriteLine("Account entity attributes:");
                foreach (object attribute in AccountEntity.Attributes)
                {
                    AttributeMetadata a = (AttributeMetadata)attribute;
                    Console.WriteLine(a.LogicalName + "    " +
                        a.Description + "    " +
                        a.DisplayName + "    " +
                        a.EntityLogicalName + "    " +
                        a.SchemaName + "    " +
                        a.AttributeType + "    "
                        );
                }
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }

    }
}

由于 Dynamics CRM 支持多语言功能,因此将为每种语言存储显示名称标签。你可以像下面这样得到它:

a.DisplayName.UserLocalizedLabel.Label