473,320 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Calling overloaded constructors using Reflection

Hi,

How do I call the overloaded construction when I create the instance using
the Reflection?

for eg)

namespace MySpace
{
Interface IOrganization
{
int show();
}
}
namespace MySpace
{
class Organization : IOrganization
{
public Organization()
{
.....
}
public Organization(int orgNo)
{
.....
}
public int show()
{
.....
}
}
}

I create the instance using the reflection like this.
Assembly orgAssembly = Assembly.LoadFrom(@"c:\org.dll");

IOrganization m_organization =
(IOrganization)orgAssembly.CreateInstance("MySpace .Organization");

When I want to create an instance of the class Organization using
refelection, always it calls the default constructor.
How do I call the overloaded constructor? How do I pass the parameters?
Thanks.

Regards,
R.Balaji


Nov 16 '05 #1
1 2660
R.Balaji <rb********@hotmail.com> wrote:
How do I call the overloaded construction when I create the instance using
the Reflection?


Use Type.GetConstructor(Type[]) to get the appropriate constructor, and
then invoke it with the appropriate parameters.

Alternatively, use the form of Activator.CreateInstance which takes an
array of parameters, and hope they won't match more than one
constructor...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: andrea_gavana | last post by:
Hello NG, I am trying to port a useful class from wxWidgets (C++) to a pure Python/wxPython implementation. In the C++ source code, a unique class is initialized with 2 different methods (???)....
6
by: Justin | last post by:
Hello, first time posting. If I have a base class and a derived class, is there only one way to call the base constructor? i.e. Is this the only way I can call the base constructor...
1
by: Adam W Root | last post by:
So I have a Product and an extending class ProductLine. I want to create a new ProductLine from a Product. I wrote this in a constructor: public Product(Product p) { foreach...
1
by: R.Balaji | last post by:
Hi, How do I call the overloaded construction when I create the instance using the Reflection? for eg) namespace MySpace { Interface IOrganization
7
by: cmay | last post by:
Can someone quick shed some light on this issue I am having? I wanted to create 2 constructors for my object, one that takes an ID value and one that takes a datarow. If ID value is provided,...
5
by: Anders Borum | last post by:
Hello! Whilst refactoring an application, I was looking at optimizing a ModelFactory with generics. Unfortunately, the business objects created by the ModelFactory doesn't provide public...
8
by: shanakard | last post by:
I m a beginner programmer and new to this site so i m not quite sure whether this is the correct place to ask this question. I saw the 2 articles published here about this question but can't seem...
13
by: =?Utf-8?B?QW5kcmVhcw==?= | last post by:
Hi, I would like to get some thoughts on Overloaded constructors vs. Object initializations. Assuming that the class supports a default constructor, is there any reason to include overloaded...
2
by: thisismykindabyte | last post by:
Hey-o! Can anyone tell me how to make this work? Long story short, I would like to use text from TextBox1.Text as the functions I would like to call. Then I would like TextBox1.Text to show...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.