I think I've seen this somewhere, but I cannot remember how to initialze a
class by a string.
That is, I have a class(Component ) that I want to initialize on the fly. It
is derived from a base component I created.
So basically I have.
Public class myDerivedCompon ent
inherits myBaseComponent
.... stuff ...
End Class
and in another code I want to have
dIm myString as String = "myDerivedCompo nent"
Dim myD as myBaseComponent
myD.InstanceOf (myString)
Hopefully this makes sense.
-CJ 4 1194
Nevermind found it.
For thsoe that want the answer, its in the Activator class. (System
namespace).
I'll let you know how it goes.
-CJ
"CJ Taylor" <ct*****@morton welding.com> wrote in message
news:u8******** ******@TK2MSFTN GP09.phx.gbl... I think I've seen this somewhere, but I cannot remember how to initialze a class by a string.
That is, I have a class(Component ) that I want to initialize on the fly.
It is derived from a base component I created.
So basically I have.
Public class myDerivedCompon ent inherits myBaseComponent
... stuff ...
End Class
and in another code I want to have
dIm myString as String = "myDerivedCompo nent"
Dim myD as myBaseComponent
myD.InstanceOf (myString)
Hopefully this makes sense.
-CJ
I was looking into that, but it seemed to much since the method I was
calling was within the Current Executing Assembly.
You would have to work here to understand the weirdness of the situation.
=-)
<bu********@yah oo.com> wrote in message
news:01******** *************** *****@phx.gbl.. . Well, I've done something like that in a differnt way.
I get all Assembly, Class and method on the fly and execute it. NOTE: to use "LoadWithPartia lName" you need u'r assembly in the GAC.
'Load the DLL objRef = System.Reflecti on.Assembly.Loa dWithPartialNam e(strDLLName) If objRef Is Nothing Then Throw New Exception("Asse mbly : '" & strDLLName & "' could not be loaded.") 'Instansiate the Class objInstance = objRef.CreateIn stance (strClassName) If objInstance Is Nothing Then Throw New Exception("Clas s : '" & strClassName & "' could not be instantiated.") 'Call the Function CallByName(objI nstance, strMethodName, CallType.Method , Object) -----Original Message----- Nevermind found it.
For thsoe that want the answer, its in the Activator class. (Systemnamespace).
I'll let you know how it goes.
-CJ "CJ Taylor" <ct*****@morton welding.com> wrote in message news:u8******* *******@TK2MSFT NGP09.phx.gbl.. . I think I've seen this somewhere, but I cannot remember how to initialze a class by a string.
That is, I have a class(Component ) that I want to initialize on the fly.It is derived from a base component I created.
So basically I have.
Public class myDerivedCompon ent inherits myBaseComponent
... stuff ...
End Class
and in another code I want to have
dIm myString as String = "myDerivedCompo nent"
Dim myD as myBaseComponent
myD.InstanceOf (myString)
Hopefully this makes sense.
-CJ
.
Ok, so Activator isn't working th eway I want to (I could be doing something
wrong)
Here is my current code
Public Function CreateEosBase(B yVal sType As String) As EOSBaseComponen t
Dim tType As System.Type
Dim _EOSBase As EOSBaseComponen t
Try
tType = System.Type.Get Type(sType)
_EOSBase = CType(System.Ac tivator.CreateI nstance(tType), EOSBaseComponen t)
Return _EOSBase
Catch ex As Exception
Console.WriteLi ne("Error:" & Me.GetType.ToSt ring() & " " & ex.Message)
End Try
End Function
And type keeps coming back NullReferenceEx ception
Ideas?
CJ
<bu********@yah oo.com> wrote in message
news:01******** *************** *****@phx.gbl.. . Well, I've done something like that in a differnt way.
I get all Assembly, Class and method on the fly and execute it. NOTE: to use "LoadWithPartia lName" you need u'r assembly in the GAC.
'Load the DLL objRef = System.Reflecti on.Assembly.Loa dWithPartialNam e(strDLLName) If objRef Is Nothing Then Throw New Exception("Asse mbly : '" & strDLLName & "' could not be loaded.") 'Instansiate the Class objInstance = objRef.CreateIn stance (strClassName) If objInstance Is Nothing Then Throw New Exception("Clas s : '" & strClassName & "' could not be instantiated.") 'Call the Function CallByName(objI nstance, strMethodName, CallType.Method , Object) -----Original Message----- Nevermind found it.
For thsoe that want the answer, its in the Activator class. (Systemnamespace).
I'll let you know how it goes.
-CJ "CJ Taylor" <ct*****@morton welding.com> wrote in message news:u8******* *******@TK2MSFT NGP09.phx.gbl.. . I think I've seen this somewhere, but I cannot remember how to initialze a class by a string.
That is, I have a class(Component ) that I want to initialize on the fly.It is derived from a base component I created.
So basically I have.
Public class myDerivedCompon ent inherits myBaseComponent
... stuff ...
End Class
and in another code I want to have
dIm myString as String = "myDerivedCompo nent"
Dim myD as myBaseComponent
myD.InstanceOf (myString)
Hopefully this makes sense.
-CJ
.
Hi CJ,
There's a post in the languages.cshar p newsgroup, "opening form by
name", which uses Reflection to invoke the constructor of the class from
which you want an instance. It allows you to pass parameters, if necessary.
Regards,
Fergus This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Oplec |
last post by:
Hi,
I'm learning C++ as a hobby using The C++ Programming Language : Special
Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that
deal with templates. Exercise 13.9 asks for me to turn a previously
made String class that deals with char's into a templated String class
that uses the template parameter C instead of char. I...
|
by: Rob F |
last post by:
I am trying to compile a string class which was working before but
subsequent attempts to make it more 'object orientated' (privatizing
the member variables and implenting query functions) it refuses to
compile in Visual C++.
Here is the code: http://www.rbf.org.uk/xstring.h
When compiling I get the following:
\xstring.h(87) : error...
|
by: Vincent Cantin |
last post by:
I have a class defined by a template which needs to "say" its type to the
user via string.
As an example, here is the class that I want to fix :
template<class T> class Container : public Serializable
{
public:
T value;
|
by: Carl Youngblood |
last post by:
I imagine this subject has probably been brought up numerous times.
Forgive me for bringing it up again. I was googling through old posts
on this newsgroup about it and found a good suggestion on how to add
functionality to the string class. Rather than trying to inherit from
the string class, the author was suggesting wrapping the string...
|
by: Erik Arner |
last post by:
Hi, I really need some help here. After upgrading to g++ 3.4 I have run
into all sorts of troubles that I'm sure depends on my lack of proper
understanding of C++. I would now like to get it right once and for all,
if possible.
Most severe is the problem illustrated by the code below. It's based on
the "pluggable factory pattern" described...
| |
by: djake |
last post by:
In the stroustrup C++ programming language (third edition) i can
find example like this:
string s1= "Hello";
So I imagine string is a standard class.
Furthermore the class in the example is initialized with a
constructor like this
|
by: Tappy Tibbons |
last post by:
I have a class I am serializing, and need the resultant XML to skip/omit
classes that are not initialized, or their member variables have not been
set. Is this possible?
Say for the following code, sometimes the Person may not have given us one,
both, or either of their addresses.
The serialize function will still put in a...
|
by: keith bannister via .NET 247 |
last post by:
(Type your message here)
--------------------------------
From: keith bannister
Hi,
I'm new to .net (as of last week) but here goes.
I want to serialize/deserialize a file the conforms to an XML schema (xsd).
|
by: Keith Bannister |
last post by:
I'm new to .net so here goes.
I'm tying to deserialize a class that is associated with an XML
schema.
I created the C# class with xsd.exe as below:
xsd.exe /c /n:somenamespace properties.xsd
this creates properties.cs
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |