Solved

GetConstructor() returning null

Posted on 2009-04-06
5
1,353 Views
Last Modified: 2012-08-13
Hi,

I am trying to retrieve a constructors info so i can invoke the constructor but all i am getting is null.

Can anyone see where i am going wrong?

Cheers


string _recordCode = recordObj.GetType().Name.ToString();
 
Type[] types = new Type[3];
types[0] = recordObj.GetType().BaseType;
types[1] = ChildRecords.SINGLE_GENERATION.GetType().BaseType;
types[2] = _user.ShowInactiveRecords.GetType().BaseType;
 
ConstructorInfo cons = recordObj.GetType().GetConstructor(types);

Open in new window

0
Comment
Question by:dwhitfield_CPWN
  • 3
  • 2
5 Comments
 
LVL 12

Expert Comment

by:andrewjb
ID: 24076421
You're going to have to show us the constructors of recordObj's type etc. Can you post a complete code sample that demostrates the problem? There's not enough info here to find the error - you've probably got a type wrong somewhere.
0
 

Author Comment

by:dwhitfield_CPWN
ID: 24076941
Hi,

I have included the constustor and enum.

I have changed the types array as this was wrong:-

                Type[] types = new Type[3];
                types[0] = typeof(string);
                types[1] = ChildRecords.SINGLE_GENERATION.GetType().BaseType;
                types[2] = typeof(bool);

although it is still returning null.
 public WorkFlow(string code, ChildRecords children, bool includeInactiveChildren)
{
}       
 
    public enum ChildRecords
    {
        ALL,
        NONE,
        SINGLE_GENERATION,
    }

Open in new window

0
 

Author Comment

by:dwhitfield_CPWN
ID: 24078052
Ive now worked out that it is the Enum type that is causing null to be returned.

Does anyone have any idea why the type of Enum causes this?
0
 
LVL 12

Accepted Solution

by:
andrewjb earned 500 total points
ID: 24078145
Why .BaseType()? Why not just .GetType() or typeof(enum)
0
 

Author Comment

by:dwhitfield_CPWN
ID: 24078184
ive took the BaseType() off and it works fine now.

Cheers
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now