473,772 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(in t orgNo)
{
.....
}
public int show()
{
.....
}
}
}

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

IOrganization m_organization =
(IOrganization) orgAssembly.Cre ateInstance("My Space.Organizat ion");

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 2689
R.Balaji <rb********@hot mail.com> wrote:
How do I call the overloaded construction when I create the instance using
the Reflection?


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

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

--
Jon Skeet - <sk***@pobox.co m>
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
2382
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 (???). This is what it seems to me. I have this declarations: class wxFoldWindowItem { private: wxWindow *_wnd;
6
2109
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 (presuming the base constructor took an int): Derived::Derived(int a) : Base(a)
1
229
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 (System.Reflection.FieldInfo info in p.GetType().GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic))
1
257
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
1500
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, it is going to get the info from the database and populate itself. If a datarow is provided, then it will use the row to populate itself. So, I wanted to have the "by ID" function get a datarow from the
5
4580
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 constructors (because we do not allow developers to instantiate them directly). Because our business objects are instantiated very frequently, the idea of using reflection sounds like a performance killer (I haven't done any tests on this, but the...
8
1959
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 to understand it. i have a class like this withe some overloaded constructors class Abcd{ public: //sorry for forgetting this earlier Abcd();
13
1520
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 constructors when you are able to use object initialization? I see a point, to provide the overloads, if you are developing framework code that might support the need to run ontop of 2.x but if you are writing a sealed application / know you are...
2
1101
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 the result of the functions I just called. (Pretend the line below is a textbox) So therefore, TextBox1.Text would look like this = "Multiply(4,GrabNumFromAray(RandomNumGen(4)))"
0
9454
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
tracyyun
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4009
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2851
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.