Parse() static private method

static private Parse ( string s, IXmlNamespaceResolver nsmgr, string &prefix ) : XmlQualifiedName
s string
nsmgr IXmlNamespaceResolver
prefix string
return XmlQualifiedName
示例#1
0
        private object ValueAs(string text, Type type, IXmlNamespaceResolver resolver)
        {
            try {
                if (type == typeof(object))
                {
                    return(text);
                }
                if (type == typeof(XmlQualifiedName))
                {
                    if (resolver != null)
                    {
                        return(XmlQualifiedName.Parse(text, resolver));
                    }
                    else
                    {
                        return(XmlQualifiedName.Parse(text, this));
                    }
                }
                if (type == typeof(DateTimeOffset))
                {
                    return(XmlConvert.ToDateTimeOffset(text));
                }

                switch (Type.GetTypeCode(type))
                {
                case TypeCode.Boolean:
                    return(XQueryConvert.StringToBoolean(text));

                case TypeCode.DateTime:
                    return(XQueryConvert.StringToDateTime(text));

                case TypeCode.Decimal:
                    return(XQueryConvert.StringToDecimal(text));

                case TypeCode.Double:
                    return(XQueryConvert.StringToDouble(text));

                case TypeCode.Int32:
                    return(XQueryConvert.StringToInt(text));

                case TypeCode.Int64:
                    return(XQueryConvert.StringToInteger(text));

                case TypeCode.Single:
                    return(XQueryConvert.StringToFloat(text));

                case TypeCode.String:
                    return(text);
                }
            } catch (Exception ex) {
                throw XmlError(String.Format("Current text value '{0}' is not acceptable for specified type '{1}'. {2}", text, type, ex != null ? ex.Message : String.Empty), ex);
            }
            throw new ArgumentException(String.Format("Specified type '{0}' is not supported.", type));
        }
 internal static XmlQualifiedName Parse(string name, IXmlNamespaceResolver resolver)
 {
     return(XmlQualifiedName.Parse(name, resolver, false));
 }
示例#3
0
        private object ValueAs(string text, Type type, IXmlNamespaceResolver resolver, bool isArrayItem)
        {
            try {
                if (type == typeof(object))
                {
                    return(text);
                }
                if (type.IsArray && !isArrayItem)
                {
                    var elemType = type.GetElementType();
                    var sarr     = text.Split((string [])null, StringSplitOptions.RemoveEmptyEntries);
                    var ret      = Array.CreateInstance(elemType, sarr.Length);
                    for (int i = 0; i < ret.Length; i++)
                    {
                        ret.SetValue(ValueAs(sarr [i], elemType, resolver, true), i);
                    }
                    return(ret);
                }

                if (type == typeof(XmlQualifiedName))
                {
                    if (resolver != null)
                    {
                        return(XmlQualifiedName.Parse(text, resolver, true));
                    }
                    else
                    {
                        return(XmlQualifiedName.Parse(text, this, true));
                    }
                }
                if (type == typeof(Uri))
                {
                    return(XmlConvert.ToUri(text));
                }
                if (type == typeof(TimeSpan))
                {
                    return(XmlConvert.ToTimeSpan(text));
                }
                if (type == typeof(DateTimeOffset))
                {
                    return(XmlConvert.ToDateTimeOffset(text));
                }

                switch (Type.GetTypeCode(type))
                {
                case TypeCode.Boolean:
                    return(XQueryConvert.StringToBoolean(text));

                case TypeCode.DateTime:
                    return(XQueryConvert.StringToDateTime(text));

                case TypeCode.Decimal:
                    return(XQueryConvert.StringToDecimal(text));

                case TypeCode.Double:
                    return(XQueryConvert.StringToDouble(text));

                case TypeCode.Int32:
                    return(XQueryConvert.StringToInt(text));

                case TypeCode.Int64:
                    return(XQueryConvert.StringToInteger(text));

                case TypeCode.Single:
                    return(XQueryConvert.StringToFloat(text));

                case TypeCode.String:
                    return(text);
                }
            } catch (Exception ex) {
                throw XmlError(String.Format("Current text value '{0}' is not acceptable for specified type '{1}'. {2}", text, type, ex != null ? ex.Message : String.Empty), ex);
            }
            throw new ArgumentException(String.Format("Specified type '{0}' is not supported.", type));
        }