ok, thanks
got it working, now having to determine the constructor to use (if no
paramterless one available), and pass corrent values, etc.
however....
how do i compare to types
(Runtime Type) System.Char* and System.String?
Maybe if you can answer why if can't do this it would help....
object myobj =
System.Activator.CreateInstance(Type.GetType("Syst em.String"),new object[]
{"string value"});
It's throwing a missing method exception, I'm guessing because there is no
contructor that takes a string - only takes a System.Char*.
There is no default (parameterless contructor) .
To use System.Char* I'd have to unsafe it, but surely there's a way of doing
it passing a string?
TIA
Sam Martin
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
boxim <sa*********@yahoo.co.uk> wrote: Real easy one I think, just can't find example,
I need to create an instance of a type, but i don't have a type var, i
have a string
e.g.
string t = "MyNamespace.Class1";
I wan't to do something like
System.Activator.CreateInstance(t); // i know the relevant assemblies
will be loaded.
Obviously i know this createinstance method takes a System.Type
parameter, not a string representation.
No it doesn't - or rather, not all overloads of it do. There's a perfectly
usable Activator.CreateInstance(string, string) where you give the
assembly name and the type name.
Alternatively, use Type.GetType to get the type if it's in either
mscorlib or your own assembly. Otherwise, load the relevant assembly
and then use Assembly.GetType.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too