Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 基于泛型方法中的类填充列表时出错_C#_.net_List_Class - Fatal编程技术网

C# 基于泛型方法中的类填充列表时出错

C# 基于泛型方法中的类填充列表时出错,c#,.net,list,class,C#,.net,List,Class,在11个不同的类(处理web服务)中,我有一个如下定义的列表 但我遇到一个错误无法将类型“System.Collections.Generic.List”隐式转换为“System.Collections.Generic.List” 因此,首先,我应该如何从我的泛型方法返回列表,以及如何调用它以返回填充了配置数据的列表?听起来您的类edbService定义在两个名称空间中 EvryCardManagement.Common和 EvryCardManagement.CustomerUpdate 我建

在11个不同的类(处理web服务)中,我有一个如下定义的列表

但我遇到一个错误
无法将类型“System.Collections.Generic.List”隐式转换为“System.Collections.Generic.List”


因此,首先,我应该如何从我的泛型方法返回列表,以及如何调用它以返回填充了配置数据的列表?

听起来您的类edbService定义在两个名称空间中

EvryCardManagement.Common和 EvryCardManagement.CustomerUpdate


我建议只在EvryCardManagement.Common中定义它,然后让所有的东西都从那里引用它。

听起来像是在两个名称空间中定义了类edbService

EvryCardManagement.Common和 EvryCardManagement.CustomerUpdate


我建议只在EvryCardManagement.Common中定义它,然后让所有的东西都从那里引用它。

听起来像是在两个名称空间中定义了类edbService

EvryCardManagement.Common和 EvryCardManagement.CustomerUpdate


我建议只在EvryCardManagement.Common中定义它,然后让所有的东西都从那里引用它。

听起来像是在两个名称空间中定义了类edbService

EvryCardManagement.Common和 EvryCardManagement.CustomerUpdate


我建议只在EvryCardManagement.Common中定义它,并让所有的东西都从那里引用它。

谢谢(这很有效!),但是我应该如何编写它以便该方法返回一个填充列表?您只需要添加一个list类型的局部变量的声明。然后将edbService对象添加到循环中的列表中,然后在函数末尾返回列表调用该过程,但我收到一个错误PopulateSoapody是什么?错误是什么?值得关闭此线程并启动一个新线程吗?谢谢(这很有效!),但是我应该如何编写它以使该方法返回一个填充的列表?您只需要添加一个list类型的局部变量声明。然后将edbService对象添加到循环中的列表中,然后在函数末尾返回列表调用该过程,但我收到一个错误PopulateSoapody是什么?错误是什么?值得关闭此线程并启动一个新线程吗?谢谢(这很有效!),但是我应该如何编写它以使该方法返回一个填充的列表?您只需要添加一个list类型的局部变量声明。然后将edbService对象添加到循环中的列表中,然后在函数末尾返回列表调用该过程,但我收到一个错误PopulateSoapody是什么?错误是什么?值得关闭此线程并启动一个新线程吗?谢谢(这很有效!),但是我应该如何编写它以使该方法返回一个填充的列表?您只需要添加一个list类型的局部变量声明。然后将edbService对象添加到循环中的列表中,然后在函数末尾返回列表调用该过程,但我收到一个错误PopulateSoapody是什么?错误是什么?是否值得关闭此线程并启动一个新线程?
private List<edbService> genEdbService;

internal class edbService
{
    public string ServiceID { get; set; }
    public string ServiceName { get; set; }
    public string ServiceDescr { get; set; }
    public string ServiceInterval { get; set; }
    public string ServiceStatus { get; set; }
    public string ServiceUrl { get; set; }
    public string SourceApplication { get; set; }
    public string DestinationApplication { get; set; }
    public string Function { get; set; }
    public string Version { get; set; }
    public string userid { get; set; }
    public string credentials { get; set; }
    public string orgid { get; set; }
    public string orgunit { get; set; }
    public string customerid { get; set; }
    public string channel { get; set; }
    public string ip { get; set; }
}
public DCSSCustomerCreate_V3_0()
{
try
{
    XElement x = XElement.Load(global::EvryCardManagement.Properties.Settings.Default.DataPath + "CustomerCreate.xml");
    // Get global settings        
    IEnumerable<XElement> services = from el in x.Descendants("Service")
         select el;
    if (services != null)
    {
        edb_service = new List<edbService>();

        // edb_service= Common.populateEDBService("CustomerCreate.xml");

        foreach (XElement srv in services)
        {
        edbService edbSrv = new edbService();

        edbSrv.ServiceID = srv.Element("ServiceID").Value;
        edbSrv.ServiceName = srv.Element("ServiceName").Value;
        edbSrv.ServiceDescr = srv.Element("ServiceDescr").Value;
        edbSrv.ServiceInterval = srv.Element("ServiceInterval").Value;
        edbSrv.ServiceStatus = srv.Element("ServiceStatus").Value;
        edbSrv.ServiceUrl = srv.Element("ServiceUrl").Value;
        foreach (XElement ServiceHeader in srv.Elements("ServiceHeader"))
        {
        ... 
public static List<edbService> populateEDBService(string xmlDataFile)
{
    try
    {
    XElement x = XElement.Load(global::EvryCardManagement.Properties.Settings.Default.DataPath + xmlDataFile);

    // Get global settings
    IEnumerable<XElement> services = from el in x.Descendants("Service")
         select el;
    if (services != null)
    {
      //edb_Service = new List<edbService>();
      foreach (XElement srv in services)
      {
      edbService edbSrv = new edbService();

      edbSrv.ServiceID = srv.Element("ServiceID").Value;
      edbSrv.ServiceName = srv.Element("ServiceName").Value;
      edbSrv.ServiceDescr = srv.Element("ServiceDescr").Value;
      edbSrv.ServiceInterval = srv.Element("ServiceInterval").Value;
      edbSrv.ServiceStatus = srv.Element("ServiceStatus").Value;
      edbSrv.ServiceUrl = srv.Element("ServiceUrl").Value;

      foreach (XElement ServiceHeader in srv.Elements("ServiceHeader"))
        {
        edbSrv.SourceApplication = ServiceHeader.Element("SourceApplication").Value;
        edbSrv.DestinationApplication = ServiceHeader.Element("DestinationApplication").Value;
        edbSrv.Function = ServiceHeader.Element("Function").Value;
        edbSrv.Version = ServiceHeader.Element("Version").Value;

        foreach (XElement ClientContext in ServiceHeader.Elements("ClientContext"))
          {
          edbSrv.userid = ClientContext.Element("userid").Value;
          edbSrv.credentials = ClientContext.Element("credentials").Value;
          edbSrv.orgid = ClientContext.Element("orgid").Value;
          edbSrv.orgunit = ClientContext.Element("orgunit").Value;
          edbSrv.customerid = ClientContext.Element("customerid").Value;
          edbSrv.channel = ClientContext.Element("channel").Value;
          edbSrv.ip = ClientContext.Element("ip").Value;
          }
        }

     // populateEDBService.Add(edbSrv);
     }
}
}
catch (Exception ex)
{
    /* Write to log */
    Common.logBuilder("CustomerCreate : Form --> CustomerCreate <--", "Exception", Common.ActiveMQ,
       ex.Message, "Exception");
    /* Send email to support */
    emailer.exceptionEmail(ex);
    }
return;
}
edb_service = Common.populateEDBService("CustomerUpdate.xml");