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


C# Class.getDeclaredConstructor方法代码示例

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


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

示例1: GetObject

 /// <summary>
 /// This method will instantiate an object of the provided type. If
 /// the object or constructor does not have public access then this
 /// will ensure the constructor is accessible and can be used.
 /// </summary>
 /// <param name="type">
 /// this is used to ensure the object is accessible
 /// </param>
 /// <returns>
 /// this returns an instance of the specific class type
 /// </returns>
 public Object GetObject(Class type) {
    Constructor method = cache.get(type);
    if(method == null) {
       method = type.getDeclaredConstructor();
       if(!method.isAccessible()) {
          method.setAccessible(true);
       }
       cache.put(type, method);
    }
    return method.newInstance();
 }
开发者ID:ngallagher,项目名称:simplexml,代码行数:22,代码来源:Instantiator.cs

示例2: GetConstructor

 /// <summary>
 /// This is used to acquire the default no argument constructor
 /// for the the provided type. If the constructor is not accessible
 /// then it will be made accessible so that it can be instantiated.
 /// </summary>
 /// <param name="type">
 /// this is the type to acquire the constructor for
 /// </param>
 /// <returns>
 /// this returns the constructor for the type provided
 /// </returns>
 public Constructor GetConstructor(Class type) {
    Constructor factory = type.getDeclaredConstructor();
    if(!factory.isAccessible()) {
       factory.setAccessible(true);
    }
    return factory;
 }
开发者ID:ngallagher,项目名称:simplexml,代码行数:18,代码来源:ConverterFactory.cs


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