Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.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# net表达式计算器spel-列表迭代_C#_List_Spring.net - Fatal编程技术网

C# net表达式计算器spel-列表迭代

C# net表达式计算器spel-列表迭代,c#,list,spring.net,C#,List,Spring.net,我试图在SpEL中执行以下行,但它不起作用: FileAttachments.?{DownloadedPath.Contains('CMA')}.count()>0 其中FileAttachments是类FileAttachment的对象列表,其属性为DownloadedPath 基本上,我正在尝试检查任何文件附件的下载路径属性是否包含“CMA” 但它返回一个错误: 选择只能用于实现的类型的实例 我数不清 我创建了一个简单的原型,因为我认为您的表达式应该有效,而且确实有效: using

我试图在SpEL中执行以下行,但它不起作用:

FileAttachments.?{DownloadedPath.Contains('CMA')}.count()>0
其中
FileAttachments
是类
FileAttachment
的对象列表,其属性为
DownloadedPath

基本上,我正在尝试检查任何
文件附件
下载路径
属性是否包含“CMA”

但它返回一个错误:

选择只能用于实现的类型的实例 我数不清


我创建了一个简单的原型,因为我认为您的表达式应该有效,而且确实有效:

using System.Collections.Generic;
using System.Diagnostics;
using Spring.Expressions;

namespace StackOverflow10159903
{
  internal class Program
  {
    private static void Main(string[] args)
    {
      var attachmentContainer = new FileAttachmentsContainer();
      attachmentContainer.AddAttachment(new FileAttachment {DownloadedPath = "CMA"});

      var attachments = new List<FileAttachment>();
      attachments.Add(new FileAttachment {DownloadedPath = "CMA"});

      var valueFromList =
        ExpressionEvaluator.GetValue(attachments, "?{DownloadedPath.Contains('CMA')}.count()>0") 
        as bool?;

      var valueFromContainer =
        ExpressionEvaluator.GetValue(attachmentContainer, "FileAttachments?{DownloadedPath.Contains('CMA')}.count()>0")
        as bool?;

      Debug.Assert(valueFromList == true);
      Debug.Assert(valueFromContainer == true);
    }
  }

  public class FileAttachmentsContainer
  {
    private readonly List<FileAttachment> _fileAttachments;

    public FileAttachmentsContainer()
    {
      _fileAttachments = new List<FileAttachment>();
    }

    public IEnumerable<FileAttachment> FileAttachments
    {
      get { return _fileAttachments; }
    }

    public void AddAttachment(FileAttachment fileAttachment)
    {
      _fileAttachments.Add(fileAttachment);
    }
  }

  public class FileAttachment
  {
    public string DownloadedPath { get; set; }
  }
}
使用System.Collections.Generic;
使用系统诊断;
使用Spring.Expressions;
命名空间StackOverflow10159903
{
内部课程计划
{
私有静态void Main(字符串[]args)
{
var attachmentContainer=新文件AttachmentsContainer();
addAttachmentContainer.AddAttachment(新文件附件{DownloadedPath=“CMA”});
var attachments=新列表();
Add(新文件附件{DownloadedPath=“CMA”});
var VALUEMFROMLIST=
ExpressionEvaluator.GetValue(附件“?{DownloadedPath.Contains('CMA')}.count()>0”)
作为布尔?;
var valueFromContainer=
ExpressionEvaluator.GetValue(attachmentContainer,“文件附件?{DownloadedPath.Contains('CMA')}.count()>0”)
作为布尔?;
Assert(valueFromList==true);
Assert(valueFromContainer==true);
}
}
公共类文件附件容器
{
私有只读列表_文件附件;
公共文件附件容器()
{
_fileAttachments=新列表();
}
公共IEnumerable文件附件
{
获取{return\u fileAttachments;}
}
public void AddAttachment(FileAttachment FileAttachment)
{
_文件附件。添加(文件附件);
}
}
公共类文件附件
{
公共字符串下载路径{get;set;}
}
}
根据您的错误消息,我想您的
文件附件
类与您描述的不同。最终,您将列表传递给表达式,而不是保存列表的容器对象