本文整理汇总了C#中Type.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Type.ToString方法的具体用法?C# Type.ToString怎么用?C# Type.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Type
的用法示例。
在下文中一共展示了Type.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: ReadContentAsAsync
// Concatenates values of textual nodes of the current content, ignoring comments and PIs, expanding entity references,
// and converts the content to the requested type. Stops at start tags and end tags.
public virtual async Task<object> ReadContentAsAsync(Type returnType, IXmlNamespaceResolver namespaceResolver)
{
if (!CanReadContentAs())
{
throw CreateReadContentAsException("ReadContentAs");
}
string strContentValue = await InternalReadContentAsStringAsync().ConfigureAwait(false);
if (returnType == typeof(string))
{
return strContentValue;
}
else
{
try
{
return XmlUntypedStringConverter.Instance.FromString(strContentValue, returnType, (namespaceResolver == null ? this as IXmlNamespaceResolver : namespaceResolver));
}
catch (FormatException e)
{
throw new XmlException(SR.Xml_ReadContentAsFormatException, returnType.ToString(), e, this as IXmlLineInfo);
}
catch (InvalidCastException e)
{
throw new XmlException(SR.Xml_ReadContentAsFormatException, returnType.ToString(), e, this as IXmlLineInfo);
}
}
}
示例3: IsTypeDefaulted
public bool IsTypeDefaulted(Type type)
{
string typeName = type.ToString();
bool isDefaulted = false;
if (cachedTypesDefaultYes.Contains(typeName))
{
isDefaulted = true;
}
else if (cachedTypesDefaultNo.Contains(typeName))
{
isDefaulted = false;
}
else
{
List<string> classNames = GetClassNames(type);
isDefaulted = classNames.Intersect(typesToDefault).Count() > 0;
if (isDefaulted)
{
cachedTypesDefaultYes.Add(typeName);
}
else
{
cachedTypesDefaultNo.Add(typeName);
}
}
return isDefaulted;
}
示例4: StringEnum
/// <summary>
/// Creates a new <see cref="StringEnum"/> instance.
/// </summary>
/// <param name="enumType">Enum type.</param>
public StringEnum(Type enumType)
{
if (!enumType.IsEnum)
throw new ArgumentException(String.Format("Supplied type must be an Enum. Type was {0}", enumType.ToString()));
_enumType = enumType;
}
示例5: Analyze
void Analyze( Type targettype )
{
Console.WriteLine( "analyzing " + targettype.ToString() + " ... " );
foreach( MemberInfo memberinfo in targettype.GetMembers() )
{
//Console.WriteLine( memberinfo.MemberType.ToString() + " " + memberinfo.Name );
if( memberinfo.MemberType == MemberTypes.Field )
{
//Console.WriteLine( memberinfo.Name );
FieldInfo fi = targettype.GetField( memberinfo.Name );
Console.WriteLine( "Field: " + memberinfo.Name + " " + fi.FieldType + " isliteral " + fi.IsLiteral.ToString() );
}
else if( memberinfo.MemberType == MemberTypes.Property )
{
//Console.WriteLine( memberinfo.Name );
PropertyInfo pi = targettype.GetProperty( memberinfo.Name );
Console.WriteLine( "Property: " + pi.PropertyType + " " + memberinfo.Name );
}
else if( memberinfo.MemberType == MemberTypes.Method )
{
Console.WriteLine( memberinfo.MemberType.ToString() + " " + memberinfo.Name );
MethodBase methodbase = memberinfo as MethodBase;
MethodInfo methodinfo = memberinfo as MethodInfo;
Console.WriteLine( " returntype " + methodinfo.ReturnType.ToString() );
ParameterInfo[] parameterinfos = methodbase.GetParameters();
for( int i = 0; i < parameterinfos.GetUpperBound(0) + 1; i ++ )
{
Console.WriteLine( " parameter " + parameterinfos[i].ParameterType + " " + parameterinfos[i].Name );
}
//Console.WriteLine( memberinfo.Name );
//MethodInfo mi = targettype.GetMethod( memberinfo.Name );
//Console.WriteLine( memberinfo.Name );
}
}
}
示例6: GooBinaryPointer
public GooBinaryPointer(GooBinaryRange range, Type dataType)
{
int typeSize = 1;
if (dataType == typeof(byte)) {
typeSize = 1;
_typeString = "uint8";
}
else if (dataType == typeof(ushort)) {
typeSize = 2;
_typeString = "uint16";
}
else if (dataType == typeof(uint)) {
typeSize = 4;
_typeString = "uint32";
}
else if (dataType == typeof(float)) {
typeSize = 4;
_typeString = "float32";
}
else {
throw new ArgumentException("Unrecognized range type " + dataType.ToString());
}
if (range.Length % typeSize != 0) {
throw new ArgumentException("Mesh data is not even multiple of element size");
}
_start = range.Start;
_length = range.Length / typeSize;
}
示例7: Array
public Array(Type type) {
base.SetType(new Type(type, true));
gszItemType = type.ToString();
gItems = new List<Object>();
//base.SetType("Array");
//gszItemType = szType;
}
示例8: LoadConfig
public static Dictionary<int, BaseConfig> LoadConfig(string path, Type type)
{
int jsonStartIndex = 4;
int columnStartIndex = 1;
var ta = Resources.Load(path) as TextAsset;
string RawJson = ta.text;
Dictionary<int, BaseConfig> dic = new Dictionary<int, BaseConfig>();
TabFileReader tabReader = new TabFileReader();
tabReader.Load(RawJson);
int JsonNodeCount = tabReader.RowCount;
for (int i = jsonStartIndex; i < JsonNodeCount; i++)
{
try
{
System.Reflection.ConstructorInfo conInfo = type.GetConstructor(Type.EmptyTypes);
BaseConfig t = conInfo.Invoke(null) as BaseConfig;
t.init(tabReader, i, columnStartIndex);
if (0 != t.id)
{
if (!dic.ContainsKey(t.id))
dic.Add(t.id, t);
else
Log.LogError("Config Data Ready Exist, TableName: " + t.GetType().Name + " ID:" + t.id);
}
}
catch (Exception)
{
Log.LogError(type.ToString() + " ERROR!!! line " + (i + 2).ToString());
}
}
return dic;
}
示例9: AddField
public static void AddField (StringBuilder sb, int n, Type val)
{
if (val != null) {
sb.Append (n.ToString(CultureInfo.InvariantCulture));
sb.Append (val.ToString());
}
}
示例10: SetPurchaseType
public void SetPurchaseType(Button button,Type type)
{
PurchaseImage = Array.Find(FindObjectsOfType<JuiceType>(), i => i.name == type.ToString()).GetComponent<Image>();
PurchaseType = type;
AllButtonDisable();
button.image.sprite = onPushButtonSprite;
SceneManager.Instance.StartChange(SceneNameManager.Scene.Purchase, new FadeTimeData(1, 1));
}
示例11: DeriveParametersNotSupported
internal static InvalidOperationException DeriveParametersNotSupported(Type type, CommandType commandType)
{
var args = new[] {type.ToString(), commandType.ToString()};
return
new InvalidOperationException(
GetExceptionMessage(
"{0} DeriveParameters only supports CommandType.StoredProcedure, not CommandType.{1}.", args));
}
示例12: EditableEntity
public EditableEntity(Type sqlClientEntityType)
{
this.m_sqlClientEntity = Activator.CreateInstance(sqlClientEntityType) as MyGeneration.dOOdads.SqlClientEntity;
if (this.m_sqlClientEntity == null)
{
throw new Exception("Can't create SqlClientEntity of type " + sqlClientEntityType.ToString());
}
}
示例13: GetPieceParent
public static GameObject GetPieceParent(Type piece)
{
if (!RoomManager.pieceParents.ContainsKey(piece) || RoomManager.pieceParents[piece] == null)
{
GameObject preexisting = GameObject.Find(piece.ToString().UppercaseFirst() + " Group");
if (preexisting != null && preexisting.transform.parent == RoomManager.masterParent.transform)
{
RoomManager.pieceParents[piece] = preexisting;
}
else
{
RoomManager.pieceParents[piece] = new GameObject();
RoomManager.pieceParents[piece].name = piece.ToString().UppercaseFirst() + " Group";
RoomManager.pieceParents[piece].transform.parent = RoomManager.masterParent.transform;
}
}
return RoomManager.pieceParents[piece];
}
示例14: EnableBehaviour
protected void EnableBehaviour( Type componentType ) {
Behaviour behaviour = GetComponentInChildren( componentType, true ) as Behaviour;
if (behaviour == null) {
Debug.Log( componentType.ToString( ) + " not present on player" );
} else {
behaviour.enabled = true;
}
}
示例15: GetTypeStr
public string libName = ""; //注册到lua的名字
string GetTypeStr(Type t) {
string str = t.ToString();
if (t.IsGenericType) {
str = GetGenericName(t);
} else if (str.Contains("+")) {
str = str.Replace('+', '.');
}
return str;
}