Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using the simple declaration of a class and the business logic below that contains lists.

VB
 public class Client
   private ClientList as new list(of Person)
   public property Client as list(of person)
    Get
      Return ClientList
    End Get
    Set(ByVal value As List(Of Client))
      ClientList = value 
    End Set
   end property
 end class

'the person class 
public class Person
 'Variable and properties here
end class


Rather than doing something on the following for each list in the client class?

VB
if client.clientlist.findall(function(p) p.id > 100).count > 0 then
 'do some business logic
elseif client.propertylist.findall(function(p) p.id > 100).count > 0 then
 'do some business logic
end if


Does / Can anyone point me in the right direction where I can interrogate the main class (in this case client), pull out the lists and perform business logic on the contents on the lists in either a recursive or reflection based approach or even suggest a better approach.

I have looked at using propertydescriptorcollection which I can look at each of the properties in the class but I am unable to create a new list based on the property type and populate it with the values of the list.

Grateful for any help
Simon
Posted

1 solution

Found my solution, this check my container class and check the state of the object to see if a database operation is needed.

VB
Dim properties As PropertyDescriptorCollection = TypeDescriptor.GetProperties(MC.GetType)
       For Each prop As PropertyDescriptor In properties
           If GetType(IList).IsAssignableFrom(prop.PropertyType) AndAlso prop.PropertyType.IsGenericType Then

               Dim item As IList = DirectCast(prop.GetValue(MC), IList)

               For Each ClassObject As Object In item
                   If ClassObject.state <> ClassState.No_Change Then
                       _IsDirty = True
                       Exit For
                   End If
               Next

               If _IsDirty = True Then Exit For
           End If
       Next


I would be interested to see if there is any floor with my own solution
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900