Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VB.net - Macro Substitution
Message
From
08/01/2011 05:49:10
 
 
To
07/01/2011 11:53:37
General information
Forum:
ASP.NET
Category:
LINQ
Environment versions
Environment:
VB 9.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01488984
Message ID:
01495224
Views:
62
Hi,

Well, looked at what I scribbled last night and in the cold light of day it was rubbish :-}
However I'm not sure exactly how you want to filter the items.
Most selections can be made using the existing HasFlag() or .Equals() methods. Probably the only exception is where an Item has multiple enum values and you want to include it if it contains *any* of a given enum list. So:
'Simple case - select all items that have specific enum set:
Dim result_Match = _
(From x In results Where x.SecurityCodes.HasFlag(e_SecurityCodes.DMS_Accounting_AP) Select x).ToList()
'or if the items need more than one enum match:
result_Match = _
(From x In results Where x.SecurityCodes.HasFlag(e_SecurityCodes.DMS_Accounting_AP Or e_SecurityCodes.DMS_Client) Select x).ToList()
'But use an extension method if you want to select items which contain any one of a given list:
Dim param As e_SecurityCodes = e_SecurityCodes.DMS_Accounting_AP Or e_SecurityCodes.DMS_Client
Dim result_Match = (From x In results Where x.SecurityCodes.IncludesAnyOf(param) Select x).ToList()
where extension method is:
'Extension method
<System.Runtime.CompilerServices.Extension()> _
    Public Function IncludesAnyOf(ByVal sc As e_SecurityCodes, ByVal DocSecurityValue As e_SecurityCodes) As Boolean
        Dim code As e_SecurityCodes
        For Each code In [Enum].GetValues(GetType(e_SecurityCodes))
            If sc.HasFlag(code) And DocSecurityValue.HasFlag(code) Then
                Return True
            End If
        Next
        Return False
    End Function
Hope this makes more sense :-}
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform