See if this sample does what you want:
Namespace MyCompany.Core
Public MustInherit Class Item
Protected mblnWasInited As Boolean
Protected Sub New()
Dim CallID As Integer = MyCompany.Commo n.AppHelper.Get NextMethodCall
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format("-----{0}:Begin MyCompany.Core. Item:{1}", CallID, "New()"))
mblnWasInited = False
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format("-----{0}:End MyCompany.Core. Item:{1}", CallID, "New()"))
End Sub
Protected Friend Overridable Sub Init()
Dim CallID As Integer = MyCompany.Commo n.AppHelper.Get NextMethodCall
Trace.Indent()
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:Begin MyCompany.Core. Item:{1}", CallID, "Init()"))
Init(False)
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:End MyCompany.Core. Item:{1}", CallID, "Init()"))
Trace.Unindent( )
End Sub
Protected Friend Overridable Sub Init(ByVal SetFlag As Boolean)
Dim CallID As Integer = MyCompany.Commo n.AppHelper.Get NextMethodCall
Trace.Indent()
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:Begin MyCompany.Core. Item:{1}", CallID, "Init(bool) "))
If SetFlag Then mblnWasInited = SetFlag
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:End MyCompany.Core. Item:{1}", CallID, "Init(bool) "))
Trace.Unindent( )
End Sub
End Class
End Namespace
Namespace MyCompany.Plugi ns
Public Class User
Inherits MyCompany.Core. Item
Public Sub New()
MyBase.new() 'Mybase.new has to be called before any other line of
code in the constructor
Dim CallID As Integer = MyCompany.Commo n.AppHelper.Get NextMethodCall
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:Begin MyCompany.Plugi ns.User:{1}", CallID, "New()"))
'
'
'
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:End MyCompany.Plugi ns.User:{1}", CallID, "New()"))
End Sub
Friend Shadows Sub Init()
Dim CallID As Integer = MyCompany.Commo n.AppHelper.Get NextMethodCall
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:Begin MyCompany.Plugi ns.User:{1}", CallID, "Init()"))
Trace.Indent()
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:Begin mybase:{1}", CallID, "Init()"))
MyBase.Init()
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:End mybase:{1}", CallID, "Init()"))
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:Begin local init logic", CallID))
'
' Custom implementation
'
'
Trace.Indent()
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:Begin setting init flag", CallID))
mblnWasInited = True
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:End setting init flag", CallID))
Trace.Unindent( )
'
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:End local init logic", CallID))
Trace.Unindent( )
Trace.WriteLine If(MyCompany.Co mmon.AppHelper. TracingOn,
String.Format(" {0}:End MyCompany.Plugi ns.User:{1}", CallID, "Init()"))
End Sub
End Class
End Namespace
Namespace MyCompany.Commo n
Friend Class AppHelper
Private Shared mTracingOn As Boolean
Private Shared mCallID As Integer
Shared Sub New()
mTracingOn = True
mCallID = Integer.MinValu e
End Sub
Public Shared ReadOnly Property TracingOn() As Boolean
Get
Return mTracingOn
End Get
End Property
Public Shared Function GetNextMethodCa ll() As Integer
mCallID += 1
Return mCallID
End Function
End Class
End Namespace
"Craig Buchanan" <na**@company.c om> wrote in message
news:Ox******** *****@TK2MSFTNG P02.phx.gbl...
I have three classes:
Core Assembly
Application - creates instances of User using Activator.Creat eInstance
Item - marked MustInherit; has an Init method
UserPlugin Assembly
User - Inherits Item, has an Init method
I would like to be able to call the Init method from the Application where
the Item.Init would fire before the User.Init method. Moreover, I don't
want the Init method on either class to be visible outside of the Core
assembly.
I don't want to use the New sub, as i don't always want the logic in the
Init to be run when an instance is created. I would like to hide the New
method from public use, but the CreateInstance method seems to require
one.
I would appreciate some advice on this. Thanks.
Craig Buchanan