Tom Knowlton
asked on
Please help on namespaces
I want to create a bunch of class libraries that are ALL under the same namespace. Each Class Library will be under it's own Solution / Project but will have the same namespace.
Is this possible?
Here is an example of what I mean...
~~~~~~~~~~~~~~~~~~~~~
DLL "A"
~~~~~~~~~~~~~~~~~~~~~
using System;
namespace GlobalNamespace{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class ClassTest
{
public ClassTest()
{
//
// TODO: Add constructor logic here
//
}
public string Speak()
{
return "Bark Bark Ruff Ruff";
}
}
}
~~~~~~~~~~~~~~~~~~~~~
DLL "B"
~~~~~~~~~~~~~~~~~~~~~
using System;
namespace GlobalNamespace{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class ClassTest
{
public ClassTest()
{
//
// TODO: Add constructor logic here
//
}
public string Speak()
{
return "Bark Bark Ruff Ruff";
}
}
}
How do I distinguish between DLL A Speak( ) and DLL B Speak( )
Is this possible?
Here is an example of what I mean...
~~~~~~~~~~~~~~~~~~~~~
DLL "A"
~~~~~~~~~~~~~~~~~~~~~
using System;
namespace GlobalNamespace{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class ClassTest
{
public ClassTest()
{
//
// TODO: Add constructor logic here
//
}
public string Speak()
{
return "Bark Bark Ruff Ruff";
}
}
}
~~~~~~~~~~~~~~~~~~~~~
DLL "B"
~~~~~~~~~~~~~~~~~~~~~
using System;
namespace GlobalNamespace{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class ClassTest
{
public ClassTest()
{
//
// TODO: Add constructor logic here
//
}
public string Speak()
{
return "Bark Bark Ruff Ruff";
}
}
}
How do I distinguish between DLL A Speak( ) and DLL B Speak( )
Check into the System.Reflection Namespace. I havent tested this there may be more too it.
System.Reflection.Assembly myAssemblyA = System.Reflection.Assembly .LoadFile( "A.DLL");
System.Type myTypeA = myAssemblyA.CreateInstance ("ClassTes t");
System.Reflection.MethodIn fo myMethodA = myTypeA.GetMethod("Insert" );
myMethod.Invoke(myTypeA,my ParamsA);
System.Reflection.Assembly myAssemblyB = System.Reflection.Assembly .LoadFile( "B.DLL");
System.Type myTypeB = myAssemblyB.CreateInstance ("ClassTes t");
System.Reflection.MethodIn fo myMethodB = myTypeA.GetMethod("Insert" );
myMethodB.Invoke(myTypeB,m yParamsB);
System.Reflection.Assembly
System.Type myTypeA = myAssemblyA.CreateInstance
System.Reflection.MethodIn
myMethod.Invoke(myTypeA,my
System.Reflection.Assembly
System.Type myTypeB = myAssemblyB.CreateInstance
System.Reflection.MethodIn
myMethodB.Invoke(myTypeB,m
ASKER
Any other option beside system.reflection??? Looks like a big mess.
The could create wrapper functions to the Reflection Code to clean it up:
private void InvokeMethodA
{
System.Reflection.Assembly myAssemblyA = System.Reflection.Assembly .LoadFile( "A.DLL");
System.Type myTypeA = myAssemblyA.CreateInstance ("ClassTes t");
System.Reflection.MethodIn fo myMethodA = myTypeA.GetMethod("Insert" );
myMethod.Invoke(myTypeA,my ParamsA);
}
private void InvokeMethodB
{
System.Reflection.Assembly myAssemblyB = System.Reflection.Assembly .LoadFile( "B.DLL");
System.Type myTypeB = myAssemblyB.CreateInstance ("ClassTes t");
System.Reflection.MethodIn fo myMethodB = myTypeA.GetMethod("Insert" );
myMethodB.Invoke(myTypeB,m yParamsB);
}
Youll have to look deeper into it to get the return values and such, Also, System.Reflection is AutoGeneration Friendly, you can Iterate Through Class Members and Auto Generate Wrapper Classes.
Somehow your going to have to specify wich Class you want to create an instance of, or wich class you want to Invoke a static method or property on. I cant think of a better way then the way the comiler does it behind the scenes.
If you dont mind, why do you need to have Classes With the exact same name and Namespace?
private void InvokeMethodA
{
System.Reflection.Assembly
System.Type myTypeA = myAssemblyA.CreateInstance
System.Reflection.MethodIn
myMethod.Invoke(myTypeA,my
}
private void InvokeMethodB
{
System.Reflection.Assembly
System.Type myTypeB = myAssemblyB.CreateInstance
System.Reflection.MethodIn
myMethodB.Invoke(myTypeB,m
}
Youll have to look deeper into it to get the return values and such, Also, System.Reflection is AutoGeneration Friendly, you can Iterate Through Class Members and Auto Generate Wrapper Classes.
Somehow your going to have to specify wich Class you want to create an instance of, or wich class you want to Invoke a static method or property on. I cant think of a better way then the way the comiler does it behind the scenes.
If you dont mind, why do you need to have Classes With the exact same name and Namespace?
ASKER
netnerd:
You asked:
>>>If you dont mind, why do you need to have Classes With the exact same name and Namespace?<<<
Answer: I dunno. :)
~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~
I think in the meantime I have found an answer I can live with:
~~~~~~~~~~~~~~~~~~~~~
DLL "A"
~~~~~~~~~~~~~~~~~~~~~
namespace BuyersFund
{
namespace SimpleTest
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class ClassTest
{
public ClassTest()
{
//
// TODO: Add constructor logic here
//
}
public string Speak()
{
return "Buyers Fund Simple Test";
}
}
}
}
~~~~~~~~~~~~~~~~~~~~~
DLL "B"
~~~~~~~~~~~~~~~~~~~~~
namespace BuyersFund
{
namespace AnotherSimpleTest
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class ClassTest
{
public ClassTest()
{
//
// TODO: Add constructor logic here
//
}
public string Speak()
{
return "Buyers Fund Simple Test";
}
}
}
}
Now I can do things like
<%
Set DBObj = Server.CreateObject("Buyer sFund.Simp leTest.Cla ssTest")
Set DBObjOther = Server.CreateObject("Buyer sFund.Simp leTest.Cla ssTest")
Response.Write("From CSharp COM Object: " & DBObj.Speak()) & "\n"
Response.Write("From CSharp COM Object: " & DBObjOther.Speak()) & "\n"
Set DBObj = Nothing
%>
You asked:
>>>If you dont mind, why do you need to have Classes With the exact same name and Namespace?<<<
Answer: I dunno. :)
~~~~~~~~~~~~~~~~~~~~~~~~~~
I think in the meantime I have found an answer I can live with:
~~~~~~~~~~~~~~~~~~~~~
DLL "A"
~~~~~~~~~~~~~~~~~~~~~
namespace BuyersFund
{
namespace SimpleTest
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class ClassTest
{
public ClassTest()
{
//
// TODO: Add constructor logic here
//
}
public string Speak()
{
return "Buyers Fund Simple Test";
}
}
}
}
~~~~~~~~~~~~~~~~~~~~~
DLL "B"
~~~~~~~~~~~~~~~~~~~~~
namespace BuyersFund
{
namespace AnotherSimpleTest
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class ClassTest
{
public ClassTest()
{
//
// TODO: Add constructor logic here
//
}
public string Speak()
{
return "Buyers Fund Simple Test";
}
}
}
}
Now I can do things like
<%
Set DBObj = Server.CreateObject("Buyer
Set DBObjOther = Server.CreateObject("Buyer
Response.Write("From CSharp COM Object: " & DBObj.Speak()) & "\n"
Response.Write("From CSharp COM Object: " & DBObjOther.Speak()) & "\n"
Set DBObj = Nothing
%>
ASKER
Errr....maybe should have been:
<%
Set DBObj = Server.CreateObject("Buyer sFund.Simp leTest","C lassTest")
Set DBObjOther = Server.CreateObject("Buyer sFund.Anot herSimpleT est","Clas sTest")
Response.Write("From CSharp COM Object: " & DBObj.Speak() & "\n")
Response.Write("From CSharp COM Object: " & DBObjOther.Speak() & "\n")
Set DBObj = Nothing
%>
<%
Set DBObj = Server.CreateObject("Buyer
Set DBObjOther = Server.CreateObject("Buyer
Response.Write("From CSharp COM Object: " & DBObj.Speak() & "\n")
Response.Write("From CSharp COM Object: " & DBObjOther.Speak() & "\n")
Set DBObj = Nothing
%>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you, netnerd!
Tom
Tom
ASKER
Actually, it seems like THIS was actually correct:
<%
Set DBObj = Server.CreateObject("Buyer sFund.Simp leTest.Cla ssTest")
Set DBObjOther = Server.CreateObject("Buyer sFund.Anot herSimpleT est.ClassT est")
Response.Write("From CSharp COM Object: " & DBObj.Speak()) & "\n"
Response.Write("From CSharp COM Object: " & DBObjOther.Speak()) & "\n"
Set DBObj = Nothing
%>
<%
Set DBObj = Server.CreateObject("Buyer
Set DBObjOther = Server.CreateObject("Buyer
Response.Write("From CSharp COM Object: " & DBObj.Speak()) & "\n"
Response.Write("From CSharp COM Object: " & DBObjOther.Speak()) & "\n"
Set DBObj = Nothing
%>
ASKER