Hello,
i want to know if i could optimize the reflection part of my app.
Background information:
the vb.net windows application checks if database records apply on different rules. So i created an Interface iRule
and (so far) 54 rules-classes that are implementing it. They all belong to the same project(Rule.dll). Because people should configure them to be active on specific conditions, there's also a table tabRule in Database where all these rules are listed(with RuleKey/RuleName etc.). This seems to be redundant but i haven't seen an alternative.
To come to the point:
I create instances of every Rule that is activated for the current record. Because the record count is avaraged 50000 and the rule-count is 54, the creation of the instances are time consuming. Do you have an idea(shared/static objects?) on how to optimze following part or suggestions for different approaches?
Dim asmRule As System.Reflection.Assembly = System.Reflection.Assembly.LoadFrom(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Rule.dll"))
...and later for about 2700000 times ...
' Find the rule in the rules assembly'
Dim ruleObj As Rule.IRule = Nothing, found As Boolean = False
For Each typeAsm As System.Type In asmRule.GetTypes
If typeAsm.GetInterface(GetType(Rule.IRule).FullName) IsNot Nothing Then
ruleObj = CType(asmRule.CreateInstance(typeAsm.FullName, True), Rule.IRule)
If ruleObj.GetKey = ruleRow.RuleKey Then 'ruleRow is the db-counterpart of the rule class'
found = True
Exit For
End If
End If
Next
'..... execute rule if found....'
Thanks