本文整理汇总了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);
}
}
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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,
});
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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());
}
}
示例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;
}
示例14:
public object this[Type type]
{
get
{
return this[type.ToString()];
}
set
{
string stuff = type.ToString();
this[stuff] = value;
}
}
示例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());
}
}