hmmm... Is this possible?

M

Matt

I have a base class that is derived from an existing class and i need to
have ANOTHER class that is linked to the objects created in their
class. OK icant explain it properly. Here is part of the code.

Ok i assume you have read the code by now. So, without creating a new
dictionary and running the same keys with different objects as the
values. How else can i make it so when i .Add in DictinaryDraw, that i
can access the properties and methods individually for each object in
the dictionary? In other words i need a new instance of the reference
(for properties and methods) to be accessable via the object within the
dictionary. so something like this
dictionarydraw(index).referenceproperty. I understand i probably need to
inherit drawreference into the object im adding into the dictionary,
except i cant because its a system class.


Imports System.Collections
Public Class DictionaryDraw
Inherits DictionaryBase

Private indexLast As Integer = -1

Public Function Add() As Integer
Do While MyBase.Dictionary.Contains(indexLast)
indexLast = indexLast + 1
Loop
MyBase.Dictionary.Add(indexLast + 1, New Drawing2D.GraphicsPath())
End Function

End Class


Public Class DrawReference

#Region "Declarations"
'All my declarations in here
#End Region

#Region "Properties"
'All my properties in here
#End Region

End Class
 
P

Phill. W

Matt said:
So, without creating a new dictionary and running the same keys
with different objects as the values. How else can i make it so when
i .Add in DictionaryDraw, that i can access the properties and
methods individually for each object in the dictionary?

Each item in the Dictionary is a DictionaryEntry, each of which has
a Key and a Value property, the latter being the object that you
added. You'd have to know (or be prepared to find out) what
Type it is, and then you can "down-cast" it to the correct Type so
you can use it, as in

Dim x as New DictionaryDraw
Dim y as Drawing2D.GraphicsPath()

y = DirectCast( _
x.Item( "abc" ).Value _
, Drawing2D.GraphicsPath() _
)
MsgBox( y.SomeProperty )

Also,

Do While MyBase.Dictionary.Contains(indexLast)
indexLast = indexLast + 1
Loop
MyBase.Dictionary.Add(indexLast + 1, ...

Could be replaced by

' I /think/ it's .Count; /might/ be .Length ...
MyBase.Dictionary.Add( MyBase.Dictionary.Count + 1 )

HTH,
Phill W.
 
M

Matt

Thanks Phil. But i was meaning the "extra" properties i want to assign
to the object in the dictionary value. For instance, all the properties
in the class DrawReference to be accessable by each new object instance
in the directionary. The class is already stronly typed so i dont have
to directcast all the time. Since its going to be a pretty cpu intensive
program for those few seconds every time a graphic is loaded.

I cant replace indexlast+1 with .count+1 because my index's are going to
be individually deleted and added frequently. So the highest index most
probably always will not be the same number as .count

Thanks for the reply though. Its good to see someone read my post :)
 
M

Matt

NEVERMIND! i ask stupid questions. I figured out a way to do it that
satisfy's my need. besides, i dont think what i was asking is possible
anyway coz its kinda obscure.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top