best strategy for accessing static information from a dyanmic meth

P

PJ6

I want to store and access static information for each of a set of dynamic
methods. Right now I have them all call a method which uses a dictionary of
Type, Info... but the fully scaled product would put many thousands of
entries into this dictionary, I'd rather that each method directly retrieve
its own object. I'm thinking about creating a dynamic type with a static
field containing the info object for each method. There must already be a
commonly accepted way to do this. What is it?

OK maybe I've reached the point where I should be asking, what book should I
buy? :/

Paul
 
C

Cor Ligthert[MVP]

Paul

You know this.

\\\
Private a as new arraylist
Private MySub
dim b = new x
b.a = "Paul"
b.b = "Pj"
a.Add(b)
end sub
Public class x
public a as string
public b as string
End class x
///

Paul will exist in b.a until there has be done
a = nothing
or
a = new arraylist

And then it is not static

This is done non generic.
As you do it generic (using a generic list), you even can use the properties
in the list
(This is called strongly typed then)

Cor
 
P

PJ6

Cor,

I don't understand how this code answers my question.

Here is my existing code -

Dim locDel As LocalBuilder = il.DeclareLocal(GetType(DelegateInfo))
il.Emit(OpCodes.Ldtoken, delegateType)
il.Emit(OpCodes.Call, Methods.GetTypeFromHandle)
il.Emit(OpCodes.Call, Methods.GetDelegateInfoMethod)

Where GetDelegateInfoMethod points to a static method on the builder class
which constructs and serves DelegateInfo objects from a dictionary. This is
mainly a performance thing, I want to cache the object so it's not
constructed every time the method is called.

I can implement lots of different approaches (though Call doesn't seem to
work with lambda functions). This isn't a particularly interesting problem,
I'm just looking for the most commonly accepted way to do it.

Paul
 
P

PJ6

Actually never mind, I got it. I think this is the best possible solution.

Paul

il.Emit(OpCodes.Call, GetType(DelegateInfoHolder(Of
TDelegate)).GetMethod("Info"))

Private Class DelegateInfoHolder(Of DelegateType)
Private Shared _Info As DelegateInfo = New
DelegateInfo(GetType(DelegateType))
Public Shared Function Info() As DelegateInfo
Return _Info
End Function
End Class
 

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