2012-04-15 19 views
0

私はSPELに次の行を実行しようとしていますが、それは動作しません:FileAttachmentsプロパティDownloadedPathあるクラスFileAttachmentのオブジェクトのリストがあるspring.netの式の評価-spel-リスト反復

FileAttachments.?{DownloadedPath.Contains('CMA')}.count()>0 

基本的に私は、任意のFileAttachmentDownloadedPathプロパティは『CMA』が含まれているかどうかを確認しようとしています。

しかし、それはエラーで返されます:

Selection can only be used on an instance of the type that implements IEnumerable.

答えて

1

私はあなたの表現が動作するはずoppinionを持っていたし、実際にそれが仕事をするように私は簡単なプロトタイプを作成しました:

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; } 
    } 
} 

あなたのエラーによるとメッセージ私はあなたのFileAttachmentクラスがあなたの記述と異なっていると思います。最終的には、リストを保持しているコンテナオブジェクトではなく、式にリストを渡しています。