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


C# Type.GetType方法代码示例

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


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

示例1: ResetFieldInfoCache

        /// <summary>
        /// Very importat to avoid out of order reflection
        /// The CLR caches previous fields access to speed up reflection but can return the fields in wrong order
        /// Clearing the m_fieldInfoCache of the Cache property resolves the issue
        /// </summary>
        /// <param name="type">Type of Object</param>
        public static void ResetFieldInfoCache(Type type)
        {
            if (mCacheProperty == null) {
                mCacheProperty = type.GetType().GetProperty("Cache",
                    BindingFlags.DeclaredOnly |
                    BindingFlags.Instance |
                    BindingFlags.NonPublic);
            }
            Debug.Assert(mCacheProperty != null, "There is no Cache property in the RuntimeType: " + type.GetType().Name);

            if (mCacheProperty != null) {
                var cacheObject = mCacheProperty.GetValue(type, null);

                Debug.Assert(cacheObject != null,
                    "There is no value for the Cache property in the RuntimeType: " + type.Name);
                var cacheField = cacheObject.GetType().GetField("m_fieldInfoCache",
                    BindingFlags.FlattenHierarchy | BindingFlags.Instance |
                    BindingFlags.NonPublic);

                Debug.Assert(cacheField != null,
                    "There is no m_fieldInfoCache field for the RuntimeTypeCache: " + type.Name);
                if (cacheField != null)
                    cacheField.SetValue(cacheObject, null);
            }
        }
开发者ID:calebillman,项目名称:FileHelpers,代码行数:31,代码来源:FieldInfoCacheManipulator.cs

示例2: GetService

		public object GetService( Type serviceType )
		{
			if( this.container.IsRegistered( serviceType.GetType() ) )
			{
				return this.container.Resolve( serviceType.GetType() );
			}

			return null;
		}
开发者ID:nazarenomanco,项目名称:Radical,代码行数:9,代码来源:PuzzleContainerServiceProviderFacade.cs

示例3: GetUnderlyingType

 public static Type GetUnderlyingType(Type type)
 {
     Type type2 = typeof(int);
     if (type.GetType().FullName.Equals("System.Workflow.ComponentModel.Compiler.DesignTimeType", StringComparison.Ordinal))
     {
         MethodInfo method = type.GetType().GetMethod("GetEnumType");
         if (method != null)
         {
             Type type3 = method.Invoke(type, new object[0]) as Type;
             type2 = (type3 != null) ? type3 : type2;
         }
         return type2;
     }
     return Enum.GetUnderlyingType(type);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:15,代码来源:EnumHelper.cs

示例4: GetDataContractType

        public override Type GetDataContractType(Type requestedType)
        {
            // Serialize proxies as the base type
            if(typeof(INHibernateProxy).IsAssignableFrom(requestedType))
            {
                requestedType = requestedType.GetType().BaseType;
            }

            // Serialize persistent collections as the collection interface type
            if(typeof(IPersistentCollection).IsAssignableFrom(requestedType))
            {
                foreach(var collInterface in requestedType.GetInterfaces())
                {
                    if(collInterface.IsGenericType)
                    {
                        requestedType = collInterface;
                        break;
                    }

                    if(!collInterface.Equals(typeof(IPersistentCollection)))
                    {
                        requestedType = collInterface;
                    }
                }
            }

            return requestedType;
        }
开发者ID:RichieYang,项目名称:Composable.Monolithic,代码行数:28,代码来源:NHibernateDataContractSurrogate.cs

示例5: CallStaticFunction

 public object CallStaticFunction(Type type, string funcName, object[] args)
 {
     return PerformInvocation(type, funcName, args,
                   innerArgs => type.CallMethod(funcName, StaticFlags, innerArgs),
                   innerArgs => type.TryCallMethodWithValues(TryConvert, funcName, StaticFlags, innerArgs),
                   innerArgs => type.GetType().GetMethod(funcName).Invoke(type, args));
 }
开发者ID:buunguyen,项目名称:bike,代码行数:7,代码来源:Interpreter.Interop.cs

示例6: DataWraper

 public DataWraper(Type tableName, BindingSource componentId, ErrorProvider errorProvider)
 {
     errorProvider1 = errorProvider;
     
     bindingSourceMain = componentId;
     bindingSourceMain.PositionChanged += bindingSourceMain_PositionChanged;
     InitializeComponent();
     WrapperBindingSource.PositionChanged += WrapperBindingSource_PositionChanged;
     WrapperBindingSource.DataSource = tableName.GetType();
     //Type yy = tableName.GetType();
     Text = tableName.Name + "s";
     dataTableAdaptor = new MySqlTableAdaptor(tableName);
     dataTable = dataTableAdaptor.GetTable();
     WrapperBindingSource.DataSource = dataTable;
     errorProvider1.DataSource = WrapperBindingSource;
     if (componentId.Current != null)
     {
         WrapperBindingSource.Position = (int)componentId.Current;
     }
     WrapperID.DataBindings.Add("Text", WrapperBindingSource, "ID");
     WrapperComboBox.DataSource = dataTable;
     WrapperComboBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
     WrapperComboBox.AutoCompleteSource = AutoCompleteSource.ListItems;
     WrapperComboBox.DisplayMember = dataTable.Columns[1].ColumnName;
     WrapperComboBox.ValueMember = dataTable.Columns[0].ColumnName;
     //WrapperComboBox.DataSource = WrapperBindingSource;
     WrapperComboBox.SelectedValueChanged += WrapperComboBox_SelectedValueChanged;
     WrapperComponentSelection.Click+=WrapperComponentSelection_Click;
     WrapperComboBox.Validated += WrapperComboBox_Validated;
     WrapperLabel.Text = tableName.Name;
     WrapperID.TextChanged += WrapperID_TextChanged;
     //WrapperComboBox.DataBin
     type = tableName;
 }
开发者ID:profimedica,项目名称:SYKYO,代码行数:34,代码来源:DataWraper.cs

示例7: GetSpecialCaseClass

 public IModelObject GetSpecialCaseClass(Type o)
 {
     if (o.FullName == typeof(Category).FullName)
     {
         return new MissingCategory();
     }
     else if (o.FullName == typeof(ProvidedAnswer).FullName)
     {
         return new MissingProvidedAnswer();
     }
     else if (o.FullName == typeof(Question).FullName)
     {
         return new MissingQuestion();
     }
     else if (o.FullName == typeof(Rating).FullName)
     {
         return new MissingRating();
     }
     else if (o.FullName == typeof(Solution).FullName)
     {
         return new MissingSolution();
     }
     else if (o.FullName == typeof(Tag).FullName)
     {
         return null; // new MissingTag();
     }
     else if (o.FullName == typeof(User).FullName)
     {
         return new MissingUser();
     }
     else
     {
         throw new Exception("Special case class not found for type: " + o.GetType());
     }
 }
开发者ID:gljivar,项目名称:Rozo.Net,代码行数:35,代码来源:SpecialCaseManager.cs

示例8: BeginCatchBlock

 public override void BeginCatchBlock(Type exceptionType)
 {
     if (base.CurrExcStackCount == 0)
     {
         throw new NotSupportedException(Environment.GetResourceString("Argument_NotInExceptionBlock"));
     }
     __ExceptionInfo info = base.CurrExcStack[base.CurrExcStackCount - 1];
     if (info.GetCurrentState() == 1)
     {
         if (exceptionType != null)
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_ShouldNotSpecifyExceptionType"));
         }
         this.Emit(OpCodes.Endfilter);
     }
     else
     {
         if (exceptionType == null)
         {
             throw new ArgumentNullException("exceptionType");
         }
         if (!exceptionType.GetType().IsRuntimeType)
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"));
         }
         Label endLabel = info.GetEndLabel();
         this.Emit(OpCodes.Leave, endLabel);
         base.UpdateStackSize(OpCodes.Nop, 1);
     }
     info.MarkCatchAddr(this.ILOffset, exceptionType);
     info.m_filterAddr[info.m_currentCatch - 1] = this.m_scope.GetTokenFor(exceptionType.TypeHandle);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:32,代码来源:DynamicILGenerator.cs

示例9: CommandExecutorNotFoundException

        /// <summary>
        /// Initializes a new instance of the <see cref="CommandExecutorNotFoundException"/> class.
        /// </summary>
        /// <param name="commandType">Type of the command.</param>
        /// <param name="message">The message.</param>
        /// <param name="inner">The inner exception.</param>
        /// <exception cref="ArgumentNullException">Occurs when <i>commandType</i> is a <c>null</c> dereference.</exception>
        public CommandExecutorNotFoundException(Type commandType, string message, Exception inner)
            : base((String.IsNullOrEmpty(message) ? String.Format("No handler was found for command {0}.", commandType.GetType().FullName) : message), inner)
        {
            Contract.Requires<ArgumentNullException>(commandType != null);

            CommandType = commandType;
        }
开发者ID:Andrea,项目名称:ncqrs,代码行数:14,代码来源:CommandExecutorNotFoundException.cs

示例10: CheckProperty

 private void  CheckProperty(Type t, string propName, Type[] propTypes)
 {
     var props = t.GetProperties();
     var prop = props.Where(p => p.Name == propName).FirstOrDefault();
     Assert.IsNotNull(prop, $" - {t.GetType().Name} has no public {propName} property");
     Assert.IsTrue(Array.Exists(propTypes,p => p.Name == prop.PropertyType.Name), 
                       $"- {typeof(object).Name}: property {propName} is a {prop.PropertyType.Name}");
 }
开发者ID:ikdoeict-notes,项目名称:programmeren-3,代码行数:8,代码来源:TypeDeclarationTests.cs

示例11: GetRouteAttribute

 public static Route GetRouteAttribute(Type callToGetUrlFor)
 {
     object[] routeable = callToGetUrlFor.GetCustomAttributes(typeof(Route), true);
     if(routeable.Length == 0)
     {
         throw new Exception("tried to get a url from a non-routable object:" + callToGetUrlFor.GetType());
     }
     return (routeable[0] as Route);
 }
开发者ID:greendogs,项目名称:Transfluent-Unity,代码行数:9,代码来源:RestUrl.cs

示例12: KontrolListe

        void KontrolListe(Type t)
        {
            var kontroller = from Control ctrl in this.Controls
                             where ctrl.GetType() == t.GetType()
                             select ctrl.Name;

            foreach(var v in kontroller)
                MessageBox.Show(v);
            //dataGridView1.DataSource = kontroller;
        }
开发者ID:dogatuncay,项目名称:LINQ_Projects,代码行数:10,代码来源:Form1.cs

示例13: CacheEntry

			public CacheEntry(Type t)
			{
				this.t = t;

				if (t.GetType() != typeof(object).GetType())
				{
					// not a runtime type, TypeInfoProvider missing - return nothing
					constructors = fields = properties = events = methods = empty;
					defaultMember = null;
				}
			}
开发者ID:amithasan,项目名称:Framework-Class-Library-Extension,代码行数:11,代码来源:TypeInfo.cs

示例14: foreach

        /**
   * Creates an instance by copying values from the given other CoreMap,
   * using the values it associates with the given set of hashkeys for
   * the immutable, hashable keys used by hashcode and equals.
   */
        /*public HashableCoreMap<T>(ArrayCoreMap other, Set<Key<T>> hashkey):base(other) {
        
    int keyHashcode = 0;
    int valueHashcode = 0;
    
    foreach (Key<T> key in hashkey) {
      // NB it is important to compose these hashcodes in an order-independent
      // way, so we just add them all here.
      keyHashcode += key.hashCode();
      valueHashcode += base.get((Class)key).hashCode();
    }
    
    this.immutableKeys = hashkey;
    this.hashcode = keyHashcode * 31 + valueHashcode;
  }*/

        /// <summary>
        /// Sets the value associated with the given key; if the the key is one
        /// of the hashable keys, throws an exception.
        /// </summary>
        /// <exception cref="HashableCoreMapException">Attempting to set the value for an immutable, hashable key.</exception>
        public override /*<VALUE> VALUE*/ Object Set(Type key, Object value)
        {

            if (immutableKeys.Contains(key))
            {
                throw new HashableCoreMapException("Attempt to change value " +
                                                   "of immutable field " + key.GetType().Name);
            }

            return base.Set(key, value);
        }
开发者ID:gblosser,项目名称:OpenNlp,代码行数:37,代码来源:HashableCoreMap.cs

示例15: InstantiateContext

        /// <summary>
        /// Handles web specific details of context instantiation.
        /// </summary>
        protected override IApplicationContext InstantiateContext(IApplicationContext parent, object configContext, string contextName, Type contextType, bool caseSensitive, string[] resources)
        {
            if (!contextType.GetType().IsSubclassOf(typeof (FluentWebApplicationContext)))
            {
                Log.Warn(string.Format("This context type {0} does not support fluent configuration for object definitions.", contextType));
            }

            // the get assembly resources method will parse my resource strings I definied in spring config and return me an extended set
            string[] overridenResources = GetAssemblyResources(resources);
            return base.InstantiateContext(parent, configContext, contextName, contextType, caseSensitive, overridenResources);
        }
开发者ID:thenapoleon,项目名称:Fluent-API-for-Spring.Net,代码行数:14,代码来源:FluentWebApplicationContextHandler.cs


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