Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

GetConstructor() returning null

Posted on 2009-04-06
5
Medium Priority
?
1,494 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 1500 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

783 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