2016-08-18 12 views
-1

が、私はこのカスタムソーターを持って動作しません。ソート対象は

'System.Collections.Generic.IComparer<ViewDomainClass.Report.TestPackage.ViewTestPackageHistorySheet>' 

しかし、これは動作します:私は、私はこのエラーを得たjointnumber

List<ViewTestPackageHistorySheet> testList = _reportTestPackageHistorySheetRepository.ShowReport(Id).ToList(); 

     testList.Sort(new AlphaNumericSorter()); 

に基づいてリストのこのタイプをソートする必要が

List<string> testList = _reportTestPackageHistorySheetRepository.ShowReport(Id).Select(i=>i.JointNumber).ToList(); 
     testList.Sort(new AlphaNumericSorter()); 
+0

' 'System.Collections.Generic.IComparer ' 'エラーではない、それは単なる名前空間ですか?実際のエラーは何ですか? ''しかし、これは動作します:etc ... "'もしあなたの次のコード行がうまくいくなら、あなたの質問は何ですか? – DGibbs

+0

なぜ文字列用のコスチュームソーターを実装するのですか? –

+0

コメントを書き留めてください!!!!!!! –

答えて

1

あなたが実装したいかもしれませんがのようなものです: IComparer<ViewTestPackageHistorySheet>

あなたはを比較したいです代わりのstring

のような何か:

public class AlphaNumericSorter : IComparer<ViewTestPackageHistorySheet> 
{ 
    public int Compare(ViewTestPackageHistorySheet x, ViewTestPackageHistorySheet y) 
    { 
     return SafeNativeMethods.StrCmpLogicalW(x.JointNumber, y.JointNumber); 
    } 
} 

[SuppressUnmanagedCodeSecurity] 
internal static class SafeNativeMethods 
{ 
    [DllImport("shlwapi.dll", CharSet = CharSet.Unicode)] 
    public static extern int StrCmpLogicalW(string psz1, string psz2); 
} 

のようにそれを使用します。

var result = _reportTestPackageHistorySheetRepository.ShowReport(Id).ToList(); 

result.Sort(new AlphaNumericSorter()); 
関連する問題