Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VB.net - Macro Substitution
Message
From
08/01/2011 14:25:19
 
 
To
08/01/2011 13:47:53
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:
01495254
Views:
77
>Hello Viv
>
>Thank you for your continued help. I am starting to get seriously lost here - but I am trying to keep up :-)
>
>after adjusting your code to match my field names and other namings like this:
>Module SecurityTest
>    <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
>End Module
>
>...
>
>        Dim param As e_SecurityCodes = e_SecurityCodes.DMS_Accounting_AP Or e_SecurityCodes.DMS_Client
>        Dim result_Match = (From x In result_0 Where x.SecurityCode.IncludesAnyOf(param) Select x).ToList()
>I am now getting the following error on the last dim command:
>'IncludesAnyOf' is not a member of 'Integer?'
>Ofcourse the field x.SecurityCode is integer - so how do you attach a method to that field?
>I'll keep trying to get this straight - I miss working with VFP :-)

Hi,
The extension method (because the first parameter is of type e_SecurityCodes) extends the e_SecurityCodes type. If you wanted it to work with an Integer then the first parameter of the extension method must be an Integer (and the body of the method adapted accordingly). But although an e_SecurityCodes value must be stored in the database as an Integer I'd convert it to the enum as soon as it is retrieved. In your code that would mean defining ListCol.SecurityCode as type e_SecurityCodes and then when selecting into ListCol use:
SecurityCode = DirectCast(z.SecurityCode,e_SecurityCodes)
and reverse cast it back to an integer when writing to storage if neccessary. That way you'll be dealing with instances of e_SecurityCodes throughout the app rather than relying on 'magic number' integers.
Hope that makes sense. If not shout and I'll try to clarify a bit more....
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform