Get Constructor Info - CSharp System.Reflection

CSharp examples for System.Reflection:ConstructorInfo

Description

Get Constructor Info

Demo Code


using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Reflection;
using System.ComponentModel;
using System.Collections.Generic;
using System;/*from  www  .  j a  va 2  s. co  m*/

public class Main{
        private static ConstructorInfo GetConstructorInfo(object instance, Type[] parameterTypes) {
            if (instance == null) {
                throw new ArgumentNullException("instance");
            }
            ConstructorInfo constructorInfo = instance.GetType().GetConstructor(parameterTypes);
            if (constructorInfo == null) {
                throw new ArgumentException(String.Format(
                    "A matching constructor on type '{0}' could not be found.",
                    instance.GetType().FullName));
            }
            return constructorInfo;
        }
}

Related Tutorials