當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。