Solved

GetConstructor() returning null

Posted on 2009-04-06
5
1,396 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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