Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. abstracting a class or property

abstracting a class or property

Scheduled Pinned Locked Moved Visual Basic
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sled Dog
    wrote on last edited by
    #1

    I have a lot of objects to create and I am wondering if I can build them with a parameter. I set 2 examples below with my Account and a Contact object's Data property. Can I have a parameter passed in during object instantiation that is the object type use this boiler plate for all of my classes? I don't know if there is such a thing as a class Template or Class Macro or Parameritized Class animal that I can use. Thanks for taking the time to look at the code. William '' Get the object with this ID. If it does not exist yet, try to load it Default Public ReadOnly Property Data(ByVal id As Integer) As Account Get Dim obj As Account = Nothing SyncLock Me If (m_odict.Contains(id)) Then obj = CType(m_odict(id), Account) m_olastaccessed(id) = DateTime.Now Else obj = New Account obj.ID = id If (obj.Load()) Then m_odict.Add(obj.ID, obj) m_olastaccessed.Add(obj.ID, DateTime.Now) Else obj = Nothing m_odict.Add(id, Nothing) m_olastaccessed.Add(id, DateTime.Now) End If End If End SyncLock Data = obj End Get End Property '' Get the object with this ID. If it does not exist yet, try to load it Default Public ReadOnly Property Data(ByVal id As Integer) As Contact Get Dim obj As Contact = Nothing SyncLock Me If (m_odict.Contains(id)) Then obj = CType(m_odict(id), Contact) m_olastaccessed(id) = DateTime.Now Else obj = New Contact obj.ID = id If (obj.Load()) Then m_odict.Add(obj.ID, obj) m_olastaccessed.Add(obj.ID, DateTime.Now) Else obj = Nothing m_odict.Add(id, Nothing) m_olastaccessed.Add(id, DateTime.Now) End If End If End SyncLock Data = obj End Get End Property

    C 1 Reply Last reply
    0
    • S Sled Dog

      I have a lot of objects to create and I am wondering if I can build them with a parameter. I set 2 examples below with my Account and a Contact object's Data property. Can I have a parameter passed in during object instantiation that is the object type use this boiler plate for all of my classes? I don't know if there is such a thing as a class Template or Class Macro or Parameritized Class animal that I can use. Thanks for taking the time to look at the code. William '' Get the object with this ID. If it does not exist yet, try to load it Default Public ReadOnly Property Data(ByVal id As Integer) As Account Get Dim obj As Account = Nothing SyncLock Me If (m_odict.Contains(id)) Then obj = CType(m_odict(id), Account) m_olastaccessed(id) = DateTime.Now Else obj = New Account obj.ID = id If (obj.Load()) Then m_odict.Add(obj.ID, obj) m_olastaccessed.Add(obj.ID, DateTime.Now) Else obj = Nothing m_odict.Add(id, Nothing) m_olastaccessed.Add(id, DateTime.Now) End If End If End SyncLock Data = obj End Get End Property '' Get the object with this ID. If it does not exist yet, try to load it Default Public ReadOnly Property Data(ByVal id As Integer) As Contact Get Dim obj As Contact = Nothing SyncLock Me If (m_odict.Contains(id)) Then obj = CType(m_odict(id), Contact) m_olastaccessed(id) = DateTime.Now Else obj = New Contact obj.ID = id If (obj.Load()) Then m_odict.Add(obj.ID, obj) m_olastaccessed.Add(obj.ID, DateTime.Now) Else obj = Nothing m_odict.Add(id, Nothing) m_olastaccessed.Add(id, DateTime.Now) End If End If End SyncLock Data = obj End Get End Property

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Templates are a new C# feature in VS.Net 2005. I honestly don't know if they will be in VB.NET Christian Graus - Microsoft MVP - C++

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups