Solved

GetConstructor() returning null

Posted on 2009-04-06
5
1,435 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

627 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