Solved

GetConstructor() returning null

Posted on 2009-04-06
5
1,337 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Why .BaseType()? Why not just .GetType() or typeof(enum)
0
 

Author Comment

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

Cheers
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

17 Experts available now in Live!

Get 1:1 Help Now