本文整理汇总了C#中System.IO.XmlReader.ReadElementString方法的典型用法代码示例。如果您正苦于以下问题:C# XmlReader.ReadElementString方法的具体用法?C# XmlReader.ReadElementString怎么用?C# XmlReader.ReadElementString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.XmlReader
的用法示例。
在下文中一共展示了XmlReader.ReadElementString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeserializeArray
private static object DeserializeArray(XmlReader xmlReader)
{
string startingElementName = xmlReader.Name;
xmlReader.Read();
string arrayType = xmlReader.Name;
ArrayList array = new ArrayList();
Type returnType = null;
while (xmlReader.Name != startingElementName)
{
string tempValue = xmlReader.ReadElementString();
switch (arrayType)
{
case "boolean":
returnType = returnType ?? typeof(bool);
array.Add(tempValue == "true");
break;
// TODO: this is not an array but a base64 encoded string
//case "byte":
// //returnType = returnType ?? typeof(bool);
// //return Convert.FromBase64String(tempValue);
// //throw new Exception("Should never reach this");
// break;
case "byte":
returnType = returnType ?? typeof(sbyte);
array.Add(Convert.ToSByte(tempValue));
break;
case "char":
returnType = returnType ?? typeof(char);
array.Add(Convert.ToChar(Convert.ToByte(tempValue)));
break;
case "dateTime":
returnType = returnType ?? typeof(DateTime);
array.Add(GetDateTimeFromString(tempValue));
break;
case "double":
returnType = returnType ?? typeof(double);
array.Add(Convert.ToDouble(tempValue));
break;
case "guid":
returnType = returnType ?? typeof(Guid);
array.Add(GetGuidFromString(tempValue));
break;
case "short":
returnType = returnType ?? typeof(short);
array.Add(Convert.ToInt16(tempValue));
break;
case "unsignedShort":
returnType = returnType ?? typeof(ushort);
array.Add(Convert.ToUInt16(tempValue));
break;
case "int":
returnType = returnType ?? typeof(int);
array.Add(Convert.ToInt32(tempValue));
break;
case "unsignedInt":
returnType = returnType ?? typeof(uint);
array.Add(Convert.ToUInt32(tempValue));
break;
case "long":
returnType = returnType ?? typeof(long);
array.Add(Convert.ToInt64(tempValue));
break;
case "unsignedLong":
returnType = returnType ?? typeof(ulong);
array.Add(Convert.ToUInt64(tempValue));
break;
case "float":
returnType = returnType ?? typeof(float);
array.Add((Single)Convert.ToDouble(tempValue));
break;
case "string":
returnType = returnType ?? typeof(string);
array.Add(tempValue);
break;
default:
returnType = returnType ?? typeof(object);
break;
}
}
return array.ToArray(returnType);
}