当前位置: 首页>>代码示例>>C#>>正文


C# Type.GetConstructor方法代码示例

本文整理汇总了C#中System.Type.GetConstructor方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetConstructor方法的具体用法?C# Type.GetConstructor怎么用?C# Type.GetConstructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Type的用法示例。


在下文中一共展示了Type.GetConstructor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Filter

 /// <summary>
 /// Создает на основе типа фильтр
 /// </summary>
 /// <param name="lib"></param>
 /// <param name="type"></param>
 public Filter(string lib, Type type)
 {
     libname = lib;
     if (type.BaseType == typeof(AbstractFilter))
     {
         Exception fullex = new Exception("");
         ConstructorInfo ci = type.GetConstructor(System.Type.EmptyTypes);
         filter = ci.Invoke(null);
         PropertyInfo everyprop;
         everyprop = type.GetProperty("Name");
         name = (string)everyprop.GetValue(filter, null);
         everyprop = type.GetProperty("Author");
         author = (string)everyprop.GetValue(filter, null);
         everyprop = type.GetProperty("Ver");
         version = (Version)everyprop.GetValue(filter, null);
         help = type.GetMethod("Help");
         MethodInfo[] methods = type.GetMethods();
         filtrations = new List<Filtration>();
         foreach (MethodInfo mi in methods)
             if (mi.Name == "Filter")
             {
                 try
                 {
                     filtrations.Add(new Filtration(mi));
                 }
                 catch (TypeLoadException)
                 {
                     //Не добавляем фильтрацию.
                 }
             }
         if (filtrations == null) throw new TypeIncorrectException("Класс " + name + " не содержит ни одной фильтрации");
     }
     else
         throw new TypeLoadException("Класс " + type.Name + " не наследует AbstractFilter");
 }
开发者ID:verygrey,项目名称:ELPTWPF,代码行数:40,代码来源:Filter.cs

示例2: NullableMembers

 public NullableMembers(Type elementType)
 {
     NullableType = NullableTypeDefinition.MakeGenericType(elementType);
     Constructor = NullableType.GetConstructor(new[] { elementType });
     GetHasValue = NullableType.GetProperty("HasValue").GetGetMethod();
     GetValue = NullableType.GetProperty("Value").GetGetMethod();
 }
开发者ID:jaygumji,项目名称:EnigmaDb,代码行数:7,代码来源:NullableMembers.cs

示例3: ConstructOverrideInstance

        private object ConstructOverrideInstance(Type overrideType, string overrideTypeName)
        {
            object overideStepsInstance = null;

            // Invoke the override 
            var containerConstructor = overrideType.GetConstructor(new[] {typeof(IObjectContainer)});

            if (containerConstructor == null)
            {
                var defaultConstructor = overrideType.GetConstructor(Type.EmptyTypes);

                if (defaultConstructor == null)
                {
                    throw new NotSupportedException(string.Format(
                        "No suitable constructor found on steps override type '{0}'. Type must either provide a default constructor, or a constructor that takes an IObjectContainer parameter.",
                        overrideTypeName));
                }

                // Create target type using default constructor
                overideStepsInstance = defaultConstructor.Invoke(null);
            }
            else
            {
                var container = ScenarioContext.Current.GetBindingInstance(typeof(IObjectContainer)) as IObjectContainer;
                overideStepsInstance = containerConstructor.Invoke(new object[] {container});
            }
            return overideStepsInstance;
        }
开发者ID:sybrix,项目名称:EdFi-App,代码行数:28,代码来源:StepsOverrideAspect.cs

示例4: Deserialize

 public override object Deserialize(Stream serializationStream, Type t)
 {
     var arrayField = t.BaseType.GetField("_data", BindingFlags.NonPublic | BindingFlags.Instance);
     var arrayType = arrayField.FieldType.GetElementType();
     var sizeType = (Type) t.GetField("SizeType").GetValue(null);
     var sizeFormatter = _typeFormatterFactory.GetFormatter(sizeType);
     var rawSize = sizeFormatter.Deserialize(serializationStream, sizeType);
     var arraySize = PrimitiveSupport.TypeToInt(rawSize);
     if (arrayType == typeof (Byte))
     {
         var arrayData = new byte[arraySize];
         serializationStream.Read(arrayData, 0, arraySize);
         var ret = t.GetConstructor(new Type[] {typeof (Byte[])}).Invoke(new object[] {arrayData});
         return ret;
     }
     else
     {
         var ret = t.GetConstructor(new Type[] {typeof (ulong)}).Invoke(new object[] {(ulong)arraySize});
         var array = (Array)arrayField.GetValue(ret);
         var subFormatter = _typeFormatterFactory.GetFormatter(arrayType);
         for (var i = 0; i < arraySize; i++)
         {
             array.SetValue(subFormatter.Deserialize(serializationStream, arrayType), i);
         }
         return ret;
     }
 }
开发者ID:sw17ch,项目名称:Z-ARCHIVED-legacy-cauterize,代码行数:27,代码来源:CauterizeVariableArrayFormatter.cs

示例5: Create

        /// <summary>创建</summary>
        /// <param name="type"></param>
        /// <param name="types"></param>
        /// <returns></returns>
        public static ConstructorInfoX Create(Type type, Type[] types)
        {
            ConstructorInfo constructor = type.GetConstructor(types);
            if (constructor == null) constructor = type.GetConstructor(DefaultBinding, null, types, null);
            if (constructor != null) return Create(constructor);

            //ListX<ConstructorInfo> list = TypeX.Create(type).Constructors;
            //if (list != null && list.Count > 0)
            //{
            //    if (types == null || types.Length <= 1) return list[0];

            //    ListX<ConstructorInfo> list2 = new ListX<ConstructorInfo>();
            //    foreach (ConstructorInfo item in list)
            //    {
            //        ParameterInfo[] ps = item.GetParameters();
            //        if (ps == null || ps.Length < 1 || ps.Length != types.Length) continue;

            //        for (int i = 0; i < ps.Length; i++)
            //        {

            //        }
            //    }
            //}

            //// 基本不可能的错误,因为每个类都会有构造函数
            //throw new Exception("无法找到构造函数!");

            return null;
        }
开发者ID:g992com,项目名称:esb,代码行数:33,代码来源:ConstructorInfoX.cs

示例6: Show

        /// <summary>
        /// Shows the specified tool window by provide it's type.  This function
        /// has no effect if the tool window is already visible.
        /// </summary>
        /// <param name="window">The type of tool window to be shown.</param>
        public void Show(Type window)
        {
            foreach (Tool d in this.m_Windows)
            {
                if (d.GetType() == window)
                    return;
            }

            System.Reflection.ConstructorInfo constructor = null;
            Tool c = null;

            // Construct the new tool window.
            constructor = window.GetConstructor(new Type[] { });
            if (constructor == null)
            {
                constructor = window.GetConstructor(new Type[] { typeof(Tools.Manager) });
                c = constructor.Invoke(new object[] { this }) as Tool;
            }
            else
                c = constructor.Invoke(null) as Tool;

            // Add the solution loaded/unloaded events.
            Central.Manager.SolutionLoaded += new EventHandler((sender, e) =>
                {
                    c.OnSolutionLoaded();
                });
            Central.Manager.SolutionUnloaded += new EventHandler((sender, e) =>
                {
                    c.OnSolutionUnloaded();
                });

            Central.Manager.IDE.ShowDock(c, c.DefaultState);
            this.m_Windows.Add(c);
        }
开发者ID:rudybear,项目名称:moai-ide,代码行数:39,代码来源:Manager.cs

示例7: Parse

 private static void Parse(Type Match, NetIncomingMessage Message)
 {
     if (Match.GetConstructor(new Type[0]) == null) {
         throw new Exception("Message '" + Match.Name + "' Does not have an empty constructor!");
     }
     Message msg = (Message)Match.GetConstructor(new Type[0]).Invoke(new object[0]);
     msg.Receive(Message);
 }
开发者ID:CloneDeath,项目名称:Xanatos,代码行数:8,代码来源:MessageHandler.cs

示例8: ContentType

 public ContentType(Type type)
 {
     Type = type.AssertNotNull();
     Type.HasAttr<ContentTypeAttribute>().AssertTrue();
     (Type.Attr<ContentTypeAttribute>().Token != "binary").AssertTrue();
     Type.HasAttr<ContentTypeLocAttribute>().AssertTrue();
     Type.GetConstructor(typeof(IBranch).MkArray());
     Type.GetConstructor(typeof(IValue).MkArray());
 }
开发者ID:xeno-by,项目名称:datavault,代码行数:9,代码来源:ContentType.cs

示例9: ProviderInfo

			public ProviderInfo( Assembly assembly, Type type )
			{
				this.assembly = assembly;
				providerType = type;
				// find normal constructor (connectionstring only)
				providerConstructor = type.GetConstructor( new[] { typeof(string) } );
				Check.VerifyNotNull( providerConstructor, Error.InvalidProviderLibrary, assembly.FullName );
				// also try to find a constructor for when schema is specified
				providerSchemaConstructor = type.GetConstructor( new[] { typeof(string), typeof(string) } );
			}
开发者ID:arangas,项目名称:MediaPortal-1,代码行数:10,代码来源:ProviderRegistry.cs

示例10: ExceptionMappingAttribute

        /// <summary>
        /// Initializes a new instance of the <see cref="ExceptionMappingAttribute"/> class.
        /// </summary>
        /// <param name="exceptionType">Type of the exception.</param>
        /// <param name="faultDetailType">Type of the fault detail.</param>
        public ExceptionMappingAttribute(Type exceptionType,
            Type faultDetailType)
        {
            ExceptionType = exceptionType;
            FaultType = faultDetailType;

            exceptionConstructor = FaultType.GetConstructor(new Type[] { exceptionType });

            if (exceptionConstructor == null)
                parameterlessConstructor = FaultType.GetConstructor(Type.EmptyTypes);
        }
开发者ID:ChristianWeyer,项目名称:Thinktecture.ServiceModel,代码行数:16,代码来源:ExceptionMappingAttribute.cs

示例11: setParser

 public void setParser(Type lexerclass, Type parserclass, String mainmethodname, Type tokentypesclass)
 {
     lexerStreamConstructorInfo = lexerclass.GetConstructor(new Type[] { typeof(Stream) });
     if (lexerStreamConstructorInfo == null) throw new ArgumentException("Lexer class invalid (no constructor for Stream)");
     lexerStringConstructorInfo = lexerclass.GetConstructor(new Type[] { typeof(TextReader) });
     if (lexerStringConstructorInfo == null) throw new ArgumentException("Lexer class invalid (no constructor for TextReader)");
     parserConstructorInfo = parserclass.GetConstructor(new Type[] { typeof(TokenStream) });
     if (parserConstructorInfo == null) throw new ArgumentException("Parser class invalid (no constructor for TokenStream)");
     mainParsingMethodInfo = parserclass.GetMethod(mainmethodname);
     typeMap = GetTypeMap(tokentypesclass);
 }
开发者ID:jblomer,项目名称:GrGen.NET,代码行数:11,代码来源:ParserPackage.cs

示例12: Load

 public override bool Load(Queue<Token> tokens, Type tokenizerType, TemplateGroup group)
 {
     Token t = tokens.Dequeue();
     Match m = _reg.Match(t.Content);
     Tokenizer tok = (Tokenizer)tokenizerType.GetConstructor(new Type[] { typeof(string) }).Invoke(new object[] { m.Groups[2].Value });
     _eval = tok.TokenizeStream(group)[0];
     tok = (Tokenizer)tokenizerType.GetConstructor(new Type[] { typeof(string) }).Invoke(new object[] { m.Groups[4].Value });
     _search = tok.TokenizeStream(group)[0];
     tok = (Tokenizer)tokenizerType.GetConstructor(new Type[] { typeof(string) }).Invoke(new object[] { m.Groups[6].Value });
     _replace = tok.TokenizeStream(group)[0];
     return true;
 }
开发者ID:marquismark,项目名称:stringtemplate,代码行数:12,代码来源:Replace.cs

示例13: IsCollection

        public override bool IsCollection(Type collectionType)
        {
            // Implements ICollection and has a constructor that takes a single element of type ICollection
            if ((typeof(ICollection).IsAssignableFrom(collectionType)
                && (collectionType.GetConstructor(new Type[] { typeof(ICollection) }) != null)))
                return true;

            Type ienumGeneric = collectionType.GetInterface(typeof(IEnumerable<>).Name);
            if (ienumGeneric != null && collectionType.GetConstructor(new Type[] { ienumGeneric }) != null)
                return true;
            else
                return false;
        }
开发者ID:vfioox,项目名称:ENULib,代码行数:13,代码来源:CollectionConstructorHandler.cs

示例14: CreateInstanceOf

        internal static object CreateInstanceOf(Type type, Random rndGen, CreatorSettings creatorSettings)
        {
            if (!creatorSettings.EnterRecursion())
            {
                return null;
            }

            if (rndGen.NextDouble() < creatorSettings.NullValueProbability && !type.IsValueType)
            {
                return null;
            }

            // Test convention #1: if the type has a .ctor(Random), call it and the
            // type will initialize itself.
            ConstructorInfo randomCtor = type.GetConstructor(new Type[] { typeof(Random) });
            if (randomCtor != null)
            {
                return randomCtor.Invoke(new object[] { rndGen });
            }

            // Test convention #2: if the type has a static method CreateInstance(Random, CreatorSettings), call it and
            // an new instance will be returned
            var createInstanceMtd = type.GetMethod("CreateInstance", BindingFlags.Static | BindingFlags.Public);
            if (createInstanceMtd != null)
            {
                return createInstanceMtd.Invoke(null, new object[] { rndGen, creatorSettings });
            }

            object result = null;
            if (type.IsValueType)
            {
                result = Activator.CreateInstance(type);
            }
            else
            {
                ConstructorInfo defaultCtor = type.GetConstructor(Type.EmptyTypes);
                if (defaultCtor == null)
                {
                    throw new ArgumentException("Type " + type.FullName + " does not have a default constructor.");
                }

                result = defaultCtor.Invoke(new object[0]);
            }

            SetPublicProperties(type, result, rndGen, creatorSettings);
            SetPublicFields(type, result, rndGen, creatorSettings);
            creatorSettings.LeaveRecursion();
            return result;
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:49,代码来源:ComplexTypeInstanceCreator.cs

示例15: BuildEntityClasses

 public void BuildEntityClasses(EntityModel model)
 {
     _model = model;
       //Initialize static fields
       if (_baseEntityClass == null) {
     _baseEntityClass = typeof(EntityBase);
     _baseDefaultConstructor = _baseEntityClass.GetConstructor(Type.EmptyTypes);
     _baseConstructor = _baseEntityClass.GetConstructor(new Type[] { typeof(EntityRecord) });
     _entityBase_Record = typeof(EntityBase).GetField("Record");
     _entityRecord_GetValue = typeof(EntityRecord).GetMethods().First(m => m.Name == "GetValue" && m.GetParameters()[0].ParameterType == typeof(int));
     _entityRecord_SetValue = typeof(EntityRecord).GetMethods().First(m => m.Name == "SetValue" && m.GetParameters()[0].ParameterType == typeof(int));
       }
       //Build classes
       BuildClasses();
 }
开发者ID:yuanfei05,项目名称:vita,代码行数:15,代码来源:EntityClassBuilder.cs


注:本文中的System.Type.GetConstructor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。