当前位置: 首页>>代码示例>>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;未经允许,请勿转载。