當前位置: 首頁>>代碼示例>>C#>>正文


C# Type.ToString方法代碼示例

本文整理匯總了C#中System.Type.ToString方法的典型用法代碼示例。如果您正苦於以下問題:C# Type.ToString方法的具體用法?C# Type.ToString怎麽用?C# Type.ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Type的用法示例。


在下文中一共展示了Type.ToString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetAttribute

        public static void GetAttribute(Type t)
        {
            VersionAttribute att;

            att = (VersionAttribute)Attribute.GetCustomAttribute(t, typeof(VersionAttribute));

            if (att == null)
            {
                Console.WriteLine("No attribute in class {0}.\n", t.ToString());
            }
            else
            {
                Console.WriteLine("The version of the class {0} is {1}.{2}", t.ToString(), att.Major, att.Minor);
            }

            MemberInfo[] MyMemberInfo = t.GetMethods();

            for (int i = 0; i < MyMemberInfo.Length; i++)
            {
                att = (VersionAttribute)Attribute.GetCustomAttribute(MyMemberInfo[i], typeof(VersionAttribute));
                if (att == null)
                {
                    Console.WriteLine("No attribute in member function {0}.\n", MyMemberInfo[i].ToString());
                }
                else
                {
                    Console.WriteLine("The version of the method {0} is {1}.{2}",
                        MyMemberInfo[i].ToString(), att.Major, att.Minor);
                }
            }
        }
開發者ID:danielkaradaliev,項目名稱:TelerikAcademyAssignments,代碼行數:31,代碼來源:MainMethod.cs

示例2: VerifyInvalidReadValue

        private bool VerifyInvalidReadValue(int iBufferSize, int iIndex, int iCount, Type exceptionType)
        {
            bool bPassed = false;
            Char[] buffer = new Char[iBufferSize];

            ReloadSource();
            DataReader.PositionOnElement(ST_TEST_NAME);
            DataReader.Read();
            if (!DataReader.CanReadValueChunk)
            {
                try
                {
                    DataReader.ReadValueChunk(buffer, 0, 5);
                    return bPassed;
                }
                catch (NotSupportedException)
                {
                    return true;
                }
            }
            try
            {
                DataReader.ReadValueChunk(buffer, iIndex, iCount);
            }
            catch (Exception e)
            {
                CError.WriteLine("Actual   exception:{0}", e.GetType().ToString());
                CError.WriteLine("Expected exception:{0}", exceptionType.ToString());
                bPassed = (e.GetType().ToString() == exceptionType.ToString());
            }

            return bPassed;
        }
開發者ID:johnhhm,項目名稱:corefx,代碼行數:33,代碼來源:ReadValue.cs

示例3: ConvertBack

 public object ConvertBack(object value, Type sourceType, object parameter, CultureInfo culture)
 {
     if (value == null)
     {
         if (!DefaultValueConverter.AcceptsNull(sourceType))
         {
             CultureInfo invariantCulture = CultureInfo.InvariantCulture;
             string str = "ValueConverter can't convert Type {0}  to Type {1}";
             object[] objArray = new object[] { "'null'", sourceType.ToString() };
             throw new InvalidOperationException(string.Format(invariantCulture, str, objArray));
         }
         value = null;
     }
     else
     {
         Type type = value.GetType();
         this.EnsureConverter(sourceType, type);
         if (this.converter == null)
         {
             CultureInfo cultureInfo = CultureInfo.InvariantCulture;
             string str1 = "ValueConverter can't convert Type {0}  to Type {1}";
             object[] objArray1 = new object[] { type.ToString(), sourceType.ToString() };
             throw new InvalidOperationException(string.Format(cultureInfo, str1, objArray1));
         }
         value = this.converter.ConvertBack(value, sourceType, parameter, culture);
     }
     return value;
 }
開發者ID:evnik,項目名稱:UIFramework,代碼行數:28,代碼來源:DynamicValueConverter.cs

示例4: ChangeType

        /// <summary>
        /// convert from string to the appropriate type
        /// </summary>
        /// <param name="propertyValue">incoming string value</param>
        /// <param name="propertyType">type to convert to</param>
        /// <returns>converted value</returns>
        internal static object ChangeType(string propertyValue, Type propertyType)
        {
            Debug.Assert(null != propertyValue, "should never be passed null");

            PrimitiveType primitiveType;
            if (PrimitiveType.TryGetPrimitiveType(propertyType, out primitiveType) && primitiveType.TypeConverter != null)
            {
                try
                {
                    // functionality provided by type converter
                    return primitiveType.TypeConverter.Parse(propertyValue);
                }
                catch (FormatException ex)
                {
                    propertyValue = (0 == propertyValue.Length ? "String.Empty" : "String");
                    throw Error.InvalidOperation(Strings.Deserialize_Current(propertyType.ToString(), propertyValue), ex);
                }
                catch (OverflowException ex)
                {
                    propertyValue = (0 == propertyValue.Length ? "String.Empty" : "String");
                    throw Error.InvalidOperation(Strings.Deserialize_Current(propertyType.ToString(), propertyValue), ex);
                }
            }
            else
            {
                Debug.Assert(false, "new StorageType without update to knownTypes");
                return propertyValue;
            }
        }
開發者ID:AlineGuan,項目名稱:odata.net,代碼行數:35,代碼來源:ClientConvert.cs

示例5: VerifyInvalidReadBinHex

                private bool VerifyInvalidReadBinHex(int iBufferSize, int iIndex, int iCount, Type exceptionType)
                {
                    bool bPassed = false;
                    byte[] buffer = new byte[iBufferSize];

                    XmlReader DataReader = GetReader(pBinHexXml);
                    PositionOnElement(DataReader, ST_ELEM_NAME1);
                    DataReader.Read();

                    if (!DataReader.CanReadBinaryContent) return true;
                    try
                    {
                        DataReader.ReadContentAsBinHex(buffer, iIndex, iCount);
                    }
                    catch (Exception e)
                    {
                        bPassed = (e.GetType().ToString() == exceptionType.ToString());
                        if (!bPassed)
                        {
                            TestLog.WriteLine("Actual   exception:{0}", e.GetType().ToString());
                            TestLog.WriteLine("Expected exception:{0}", exceptionType.ToString());
                        }
                    }

                    return bPassed;
                }
開發者ID:noahfalk,項目名稱:corefx,代碼行數:26,代碼來源:ReadBinHex.cs

示例6: MyTrace

 public static void MyTrace(TraceLevel type, Type theClass, string controllerName, string actionName, string message, Exception e)
 {
     string messageToShow;
     log4net.ILog log;
     log = log4net.LogManager.GetLogger(theClass);
     if (e != null)
     {
         messageToShow = string.Format("\tClass={0} \r\n\tController= {1} \r\n\tAction= {2} \r\n\tMessage= {3} \r\n\tGetBaseException= {4}",
                     theClass.ToString(), controllerName, actionName, message, e.GetBaseException().ToString());
     }
     else
     {
         messageToShow = string.Format("\tClass={0} \r\n\tController= {1} \r\n\tAction= {2} \r\n\tMessage= {3}",
                     theClass.ToString(), controllerName, actionName, message);
     }
     switch (type)
     {
         case TraceLevel.Info:
             Trace.TraceInformation(messageToShow);
             log.Info(messageToShow);
             break;
         case TraceLevel.Error:
             Trace.TraceError(messageToShow);
             log.Error(messageToShow);
             break;
         case TraceLevel.Warning:
             Trace.TraceWarning(messageToShow);
             log.Warn(messageToShow);
             break;
     }
 }
開發者ID:jalvarez54,項目名稱:NorthWind54,代碼行數:31,代碼來源:MyTracer.cs

示例7: AddNokiaLayer

        /// <summary>
        /// Add a nokia layer to the layers collection of the map.
        /// </summary>
        /// <param name="layers">The layers collection.</param>
        /// <param name="type">The basic map type.</param>
        /// <param name="scheme">The scheme of the map.</param>
        /// <param name="appId">The application id.</param>
        /// <param name="token">The token.</param>
        public static void AddNokiaLayer(this LayerCollection layers, Type type, Scheme scheme, string appId, string token)
        {
            // request schema is
            // http://SERVER-URL/maptile/2.1/TYPE/MAPID/SCHEME/ZOOM/COL/ROW/RESOLUTION/FORMAT?param=value&...

            string copyrightText = (scheme == Scheme.SatelliteDay) ? "© 2012 DigitalGlobe" : "© 2012 NAVTEQ";
            string schemeString = Regex.Replace(scheme.ToString(), "[a-z][A-Z]", m => m.Value[0] + "." + m.Value[1]).ToLower();
            string typeString = type.ToString().ToLower();
            string caption = (type == Type.StreetTile) ? "Streets" : (type == Type.LabelTile) ? "Labels" : "BaseMap";

            layers.Add(new TiledLayer("Nokia_" + type.ToString())
            {
                Caption = caption,
                IsLabelLayer = type == Type.LabelTile || type == Type.StreetTile,
                IsBaseMapLayer = type == Type.MapTile || type == Type.BaseTile,
                TiledProvider = new RemoteTiledProvider
                {
                    MinZoom = 0,
                    MaxZoom = 20,
                    RequestBuilderDelegate = (x, y, level) =>
                    string.Format("http://{0}.maps.nlp.nokia.com/maptile/2.1/{1}/newest/{2}/{3}/{4}/{5}/256/png8?app_id={6}&token={7}",
                    "1234"[(x ^ y) % 4], typeString, schemeString, level, x, y, appId, token)
                },
                Copyright = copyrightText,
            });
        }
開發者ID:MuffPotter,項目名稱:xservernet-bin,代碼行數:34,代碼來源:NokiaProvider.cs

示例8: GetObject

 /// <summary>
 /// 
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 static public object GetObject(Type type)
 {
     if (signalObjects.ContainsKey(type.ToString()))
     {
         return signalObjects[type.ToString()];
     }
     return null;
 }
開發者ID:rocketeerbkw,項目名稱:DNA,代碼行數:13,代碼來源:SignalHelper.cs

示例9: AddObject

        /// <summary>
        /// adds the current object to the static dictionary of signal items
        /// </summary>
        /// <param name="type"></param>
        static public void AddObject(Type type, ISignalBase obj)
        {
            if (signalObjects.ContainsKey(type.ToString()))
            {
                signalObjects.Remove(type.ToString());
            }

            signalObjects.Add(type.ToString(), obj);
        }
開發者ID:rocketeerbkw,項目名稱:DNA,代碼行數:13,代碼來源:SignalHelper.cs

示例10: IsType

        /// <summary>
        /// 類型匹配
        /// </summary>
        /// <param name="type"></param>
        /// <param name="typeName"></param>
        /// <returns></returns>
        public static bool IsType(Type type, string typeName)
        {
            if (type.ToString() == typeName)
                return true;
            if (type.ToString() == "System.Object")
                return false;

            return IsType(type.BaseType, typeName);
        }
開發者ID:aj-hc,項目名稱:SZY,代碼行數:15,代碼來源:ReflectHelper.cs

示例11: CrearClasePropiedad

        public Propiedad CrearClasePropiedad(Type Tipo)
        {
            if (Tipo.ToString() == "GI.BR.Propiedades.Venta")
                return new Venta();

            else if (Tipo.ToString() == "GI.BR.Propiedades.Alquiler")
                return new Alquiler();

            return null;
        }
開發者ID:enzoburga,項目名稱:pimesoft,代碼行數:10,代碼來源:PropiedadFactory.cs

示例12: ExceptionNotThrownException

 public ExceptionNotThrownException(Type expectedException, Exception actualException)
 {
     if (actualException == null)
     {
         message = string.Format("{0} was not thrown", expectedException.ToString());
     }
     else
     {
         message = string.Format("{0} was not thrown, but {1} was", expectedException.ToString(),expectedException.GetType().ToString());
     }
 }
開發者ID:thelgevold,項目名稱:ExpressUnit,代碼行數:11,代碼來源:ExceptionNotThrownException.cs

示例13: Build

        public async Task<Page> Build(Type pageType, object parameter)
        {
            ConstructorInfo constructor = null;
            object[] parameters = null;

            if (parameter == null)
            {
                constructor = pageType.GetTypeInfo()
                    .DeclaredConstructors
                    .FirstOrDefault(c => !c.GetParameters().Any());

                parameters = new object[] { };
            }
            else
            {
                constructor = pageType.GetTypeInfo()
                    .DeclaredConstructors
                    .FirstOrDefault(
                        c =>
                        {
                            var p = c.GetParameters();
                            return p.Count() == 1
                                   && p[0].ParameterType == parameter.GetType();
                        });

                parameters = new[]
                            {
                                        parameter
                                    };
            }

            if (constructor == null)
                throw new InvalidOperationException(
                    "No suitable constructor found for page " + pageType.ToString());

            var page = constructor.Invoke(parameters) as Page;

            // Assign Binding Context
            if (_pagesByType.ContainsKey(pageType))
            {
                page.BindingContext = GetBindingContext(pageType);

                // Pass parameter to view model
                var model = page.BindingContext as BaseViewModel;
                if (model != null)
                    await model.OnNavigated(parameter);
            }
            else
                throw new InvalidOperationException(
                    "No suitable view model found for page " + pageType.ToString());

            return page;
        }
開發者ID:powerdude,項目名稱:xarch-starter,代碼行數:53,代碼來源:PageService.cs

示例14:

 public object this[Type type]
 {
     get
     {
         return this[type.ToString()];
     }
     set
     {
         string stuff = type.ToString();
         this[stuff] = value;
     }
 }
開發者ID:SriniKadiam,項目名稱:SpecAid,代碼行數:12,代碼來源:RecallAid.cs

示例15: Stop

        public void Stop(Type service)
        {
            if (_services.ContainsKey(service.ToString()))
            {
                ServiceHost host = _services[service.ToString()];

                // Close the ServiceHost.
                host.Close();

                _services.Remove(service.ToString());
            }
        }
開發者ID:NunoRodrigues,項目名稱:ServicesFrameworkAndGUI,代碼行數:12,代碼來源:Service.cs


注:本文中的System.Type.ToString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。