Home All Groups Group Topic Archive Search About
Author
21 Jul 2005 2:38 PM
Sam
Hi,

i'm a bit stuck at the following problem and hope any of you can provide
me wit a nice solution:

I have a company with multiple employees.
When creating a company control i can define a property "employee" of
type Employee (my own created class), but that's only one employee, i
need multiple.
I've found an example where an Employees property is called by using the
  ParseChildren(true,"Employees"), but that means that all children are
considered employees, but i also have other properties like "address".
And the example defines the property as type ArrayList. How is the
designer to know what type of tag it is (nowhere is it defined as Employee)?
So i'm looking for a way to identify the <employee> tag when the
employee.get() property is called.

below a sample code of what i've tried or trying to accomplish.

Thanks for any replies.
Sam.


company.aspx:
<company>
     <address>Street 1</address>
     <employee name="john" />
     <employee name="sam"  />
</company>


Company.vb:
<ParseChildren(True)> _
Public Class Company
     Inherits WebControl

     Public Property Address() As String
     ...
     End Property

     Private _elements As New ArrayList
    <PersistenceMode(PersistenceMode.InnerProperty)> _
     Public ReadOnly Property Employee() As ArrayList
         Get
             Return _employees
         End Get
     End Property

     Private _elements As Employee[]
    <PersistenceMode(PersistenceMode.InnerProperty)> _
     Public Property Employee() As Employee
         Get
             Return _employees[?]
         End Get
         Set(ByVal value As Employee)
             _employees[Employee.nr] = value
         End Set
     End Property
End Class

Author
22 Jul 2005 11:49 AM
Teemu Keiski
"> I've found an example where an Employees property is called by using the
>  ParseChildren(true,"Employees"), but that means that all children are
> considered employees, but i also have other properties like "address".
> And the example defines the property as type ArrayList. How is the
> designer to know what type of tag it is (nowhere is it defined as
> Employee)?
> So i'm looking for a way to identify the <employee> tag when the
> employee.get() property is called.
>

Yes, instead of using ArrayList, you should have strong-typed collection in
use. E.g collection typed for Employee object (in case for multiple possible
employee types, typed for the common parent type if the collection stores
them)

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke