Return strong type (like typed dataset)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fsx
    New Member
    • Nov 2007
    • 9

    Return strong type (like typed dataset)

    I have a class that accepts objects via an add method and then stores them in a list of objects:

    Code:
    public class tagBuilder
    private _store as Dictionary(Of String, Object)
    
    public sub Add(tagName as string, tagValue as object)
    _store.add(tagName, tagValue)
    end sub
    
    end class
    I would like to add some methods that allow me to return a strong type (string, int, date) based on the specified tag. Is this possible? Doesn't a typed dataset do something similar based on the column datatype?

    Code:
    public function GetTag(tagName as string)
    ' pseudocode: 
    ' - search _store for tagName
    ' - get value into object
    ' - cast object to actual type and return
    end function
  • fsx
    New Member
    • Nov 2007
    • 9

    #2
    Sorry, I think i've done a bad job of describing this.

    I'm wondering if I need code generation to create me methods that will return expected tags. for example, a string "username" tag would be returned with .GetUserName() [ as string] and a date "dob" tag would be returned with .GetDob() [ as date].

    The original idea was to get a strong typed back instead of an object and then cast it to a type.

    Comment

    Working...