本文整理匯總了C#中System.ComponentModel.TypeConverter.ConvertFromInvariantString方法的典型用法代碼示例。如果您正苦於以下問題:C# TypeConverter.ConvertFromInvariantString方法的具體用法?C# TypeConverter.ConvertFromInvariantString怎麽用?C# TypeConverter.ConvertFromInvariantString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.ComponentModel.TypeConverter
的用法示例。
在下文中一共展示了TypeConverter.ConvertFromInvariantString方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ReadValue
private bool ReadValue(XmlNode node, TypeConverter converter, ArrayList errors, out object value)
{
try
{
foreach (XmlNode child in node.ChildNodes)
{
if (child.NodeType == XmlNodeType.Text)
{
value = converter.ConvertFromInvariantString(node.InnerText);
return true;
}
if (child.Name.Equals("Binary"))
{
byte[] data = Convert.FromBase64String(child.InnerText);
if (this.GetConversionSupported(converter, typeof(byte[])))
{
value = converter.ConvertFrom(null, CultureInfo.InvariantCulture, data);
return true;
}
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream(data);
value = formatter.Deserialize(stream);
return true;
}
if (child.Name.Equals("InstanceDescriptor"))
{
value = this.ReadInstanceDescriptor(child, errors);
return (value != null);
}
errors.Add(string.Format("Unexpected element type {0}", child.Name));
value = null;
return false;
}
value = null;
return true;
}
catch (Exception ex)
{
errors.Add(ex.Message);
value = null;
return false;
}
}
示例2: ReadValue
/// Generic function to read an object value. Returns true if the read
/// succeeded.
private bool ReadValue(XmlNode node, TypeConverter converter, ArrayList errors, out object value)
{
try
{
foreach (XmlNode child in node.ChildNodes)
{
if (child.NodeType == XmlNodeType.Text)
{
value = converter.ConvertFromInvariantString(node.InnerText);
return true;
}
else if (child.Name.Equals("Binary"))
{
byte[] data = Convert.FromBase64String(child.InnerText);
// Binary blob. Now, check to see if the type converter
// can convert it. If not, use serialization.
//
if (GetConversionSupported(converter, typeof(byte[])))
{
value = converter.ConvertFrom(null, CultureInfo.InvariantCulture, data);
return true;
}
else
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream(data);
value = formatter.Deserialize(stream);
return true;
}
}
else if (child.Name.Equals("InstanceDescriptor"))
{
value = ReadInstanceDescriptor(child, errors);
return (value != null);
}
else
{
errors.Add(string.Format("Unexpected element type {0}", child.Name));
value = null;
return false;
}
}
// If we get here, it is because there were no nodes. No nodes and no inner
// text is how we signify null.
//
value = null;
return true;
}
catch (Exception ex)
{
errors.Add(ex.Message);
value = null;
return false;
}
}
示例3: ReadValue
/// <summary>
/// ��ȡ"Value"�ڵ�
/// �������ԣ��������ĵ��е�����ֵ�������͵�ת����ת��Ϊ��ǰ���Ե�ֵ����
/// </summary>
/// <param name="node">���ڵ�</param>
/// <param name="converter">���͵�ת����</param>
/// <param name="errors">�����ڼ������Ĵ�������еĻ����ļ���</param>
/// <param name="value">����</param>
/// <returns>��ֵ�Ƿ��ܹ���ת������Ҫ������</returns>
private bool ReadValue(XmlNode node, TypeConverter converter, ArrayList errors, ref object value)
{
try
{
foreach (XmlNode child in node.ChildNodes)
{
//XmlNodeTypeö��ָ���ڵ�����͡�.Text:�ڵ���ı����ݡ�Text �ڵ㲻�ܾ����κ��ӽڵ㡣
if (child.NodeType == XmlNodeType.Text)
{
value = converter.ConvertFromInvariantString(node.InnerText);
return true;
}
else if (child.Name.Equals("Binary"))
{
byte[] data = Convert.FromBase64String(child.InnerText);
if (GetConversionSupported(converter, typeof(byte[])))
{
value = converter.ConvertFrom(data);
return true;
}
else
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream(data);
value = formatter.Deserialize(stream);
return true;
}
}
else
{
errors.Add(string.Format("��������{0}", child.Name));
value = null;
return false;
}
}
return true;
}
catch (Exception ex)
{
errors.Add(ex.Message);
value = null;
return false;
}
}
示例4: ConvertData
object ConvertData (TypeConverter c)
{
if (mime_type == ResXResourceWriter.ByteArraySerializedObjectMimeType) {
if (c.CanConvertFrom (typeof (byte [])))
return c.ConvertFrom (Convert.FromBase64String (dataString));
} else if (String.IsNullOrEmpty (mime_type)) {
if (c.CanConvertFrom (typeof (string)))
return c.ConvertFromInvariantString (dataString);
}
else
throw new Exception ("shouldnt get here, invalid mime type");
throw new TypeLoadException ("No converter for this type found");
}
示例5: ReadValue
/// <summary>
/// ��ȡ"Value"�ڵ�
/// �������ԣ��������ĵ��е�����ֵ�������͵�ת����ת��Ϊ��ǰ���Ե�ֵ����
/// </summary>
/// <param name="node">���ڵ�</param>
/// <param name="converter">���͵�ת����</param>
/// <param name="value">����</param>
/// <returns>��ֵ�Ƿ��ܹ���ת������Ҫ������</returns>
private bool ReadValue(XmlNode node, TypeConverter converter, ref object value)
{
try
{
foreach (XmlNode child in node.ChildNodes)
{
//XmlNodeTypeö��ָ���ڵ�����͡�.Text:�ڵ���ı����ݡ�Text �ڵ㲻�ܾ����κ��ӽڵ㡣
if (child.NodeType == XmlNodeType.Text)
{
value = converter.ConvertFromInvariantString(node.InnerText);
return true;
}
else if (child.NodeType == XmlNodeType.Element)
{//������Ϣ�ڵ����ô˲��ֶ�ȡ����ӿ���Ϣ20090616
List<string> tempIO = new List<string>();
for (int i = 0; i < node.ChildNodes.Count; i++)
{
tempIO.Add(node.ChildNodes[i].Attributes["name"].Value);
}
value = String.Join(",", tempIO.ToArray());
return true;
}
else if (child.Name.Equals("Binary"))
{
byte[] data = Convert.FromBase64String(child.InnerText);
if (GetConversionSupported(converter, typeof(byte[])))
{
value = converter.ConvertFrom(data);
return true;
}
else
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream(data);
value = formatter.Deserialize(stream);
return true;
}
}
else
{
value = null;
return false;
}
}
return true;
}
catch (Exception ex)
{
value = null;
return false;
}
}