Re: Creating object from type
From: R.Balaji (rbalaji007_at_hotmail.com)
Date: 04/07/04
- Next message: Frans Bouma [C# MVP]: "Re: I've Had Enough"
- Previous message: Jon Skeet [C# MVP]: "Re: Calling overloaded constructors using Reflection"
- In reply to: Irfan: "Creating object from type"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 7 Apr 2004 19:12:50 +0530
Hi,
Yes. You can.
If you want to manipulate the dynamically created objects, then you need to
have reference to them.
To do that either you can go for Interfaces and Classes.
eg)
using System;
using System.Reflection;
namespace sampleNamespace
{
public class Class1
{
public Class1()
{
Assembly sampleAssembly = Assembly.LoadFrom(@"c:\\sample.dll");
ISample sampleObj =
sampleAssembly.CreateInstance("sampleNameSpace.SampleClass");
sampleObj.sampleMethod(1);
}
}
}
Regards,
R.Balaji
"Irfan" <gowani009@yahoo.com> wrote in message
news:eeZy6OKHEHA.2224@TK2MSFTNGP12.phx.gbl...
> Hi all
> I am new to DotNet and C#
>
> Is there any way to get a type of object from a string. Lets suppose i
have
> a string variable containing a type "MyNameSpace.MyComponent" where
> MyComponent.dll is already been referenced in the client project.
>
> Now i want to create any object from that string. I think this require
> getting a type from that string and then creating object from that type.
If
> this or any alternative is possible, pls let me know with a little
example.
>
> Regards,
> Irfan
>
>
>
>
>
- Next message: Frans Bouma [C# MVP]: "Re: I've Had Enough"
- Previous message: Jon Skeet [C# MVP]: "Re: Calling overloaded constructors using Reflection"
- In reply to: Irfan: "Creating object from type"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|