public static void Main(string[] args) { //<snippet11> // Parse an XSD formatted string to create a SoapInteger object. string xsdIntegerString = "-13"; SoapInteger xsdInteger = SoapInteger.Parse(xsdIntegerString); //</snippet11> //<snippet12> // Print the value of the SoapInteger object in XSD format. Console.WriteLine("The SoapInteger object in XSD format is {0}.", xsdInteger.ToString()); //</snippet12> //<snippet13> // Print the XSD type string of the SoapInteger object. Console.WriteLine("The XSD type of the SoapInteger " + "object is {0}.", xsdInteger.GetXsdType()); //</snippet13> //<snippet14> // Print the value of the SoapInteger object. Console.WriteLine( "The value of the SoapInteger object is {0}.", xsdInteger.Value); //</snippet14> //<snippet16> // Print the XSD type string of the SoapInteger class. Console.WriteLine("The XSD type of the SoapInteger class " + "is {0}.", SoapInteger.XsdType); //</snippet16> }
internal static object SoapCoerceArg(object value, Type pt, Hashtable keyToNamespaceTable) { object obj = null; if (value != null) { try { if (pt.IsByRef) { pt = pt.GetElementType(); } if (pt.IsInstanceOfType(value)) { obj = value; } else { string text = value as string; if (text != null) { if (pt == typeof(double)) { if (text == "INF") { obj = double.PositiveInfinity; } else if (text == "-INF") { obj = double.NegativeInfinity; } else { obj = double.Parse(text, CultureInfo.InvariantCulture); } } else if (pt == typeof(float)) { if (text == "INF") { obj = float.PositiveInfinity; } else if (text == "-INF") { obj = float.NegativeInfinity; } else { obj = float.Parse(text, CultureInfo.InvariantCulture); } } else if (SoapType.typeofISoapXsd.IsAssignableFrom(pt)) { if (pt == SoapType.typeofSoapTime) { obj = SoapTime.Parse(text); } else if (pt == SoapType.typeofSoapDate) { obj = SoapDate.Parse(text); } else if (pt == SoapType.typeofSoapYearMonth) { obj = SoapYearMonth.Parse(text); } else if (pt == SoapType.typeofSoapYear) { obj = SoapYear.Parse(text); } else if (pt == SoapType.typeofSoapMonthDay) { obj = SoapMonthDay.Parse(text); } else if (pt == SoapType.typeofSoapDay) { obj = SoapDay.Parse(text); } else if (pt == SoapType.typeofSoapMonth) { obj = SoapMonth.Parse(text); } else if (pt == SoapType.typeofSoapHexBinary) { obj = SoapHexBinary.Parse(text); } else if (pt == SoapType.typeofSoapBase64Binary) { obj = SoapBase64Binary.Parse(text); } else if (pt == SoapType.typeofSoapInteger) { obj = SoapInteger.Parse(text); } else if (pt == SoapType.typeofSoapPositiveInteger) { obj = SoapPositiveInteger.Parse(text); } else if (pt == SoapType.typeofSoapNonPositiveInteger) { obj = SoapNonPositiveInteger.Parse(text); } else if (pt == SoapType.typeofSoapNonNegativeInteger) { obj = SoapNonNegativeInteger.Parse(text); } else if (pt == SoapType.typeofSoapNegativeInteger) { obj = SoapNegativeInteger.Parse(text); } else if (pt == SoapType.typeofSoapAnyUri) { obj = SoapAnyUri.Parse(text); } else if (pt == SoapType.typeofSoapQName) { obj = SoapQName.Parse(text); SoapQName soapQName = (SoapQName)obj; if (soapQName.Key.Length == 0) { soapQName.Namespace = (string)keyToNamespaceTable["xmlns"]; } else { soapQName.Namespace = (string)keyToNamespaceTable["xmlns:" + soapQName.Key]; } } else if (pt == SoapType.typeofSoapNotation) { obj = SoapNotation.Parse(text); } else if (pt == SoapType.typeofSoapNormalizedString) { obj = SoapNormalizedString.Parse(text); } else if (pt == SoapType.typeofSoapToken) { obj = SoapToken.Parse(text); } else if (pt == SoapType.typeofSoapLanguage) { obj = SoapLanguage.Parse(text); } else if (pt == SoapType.typeofSoapName) { obj = SoapName.Parse(text); } else if (pt == SoapType.typeofSoapIdrefs) { obj = SoapIdrefs.Parse(text); } else if (pt == SoapType.typeofSoapEntities) { obj = SoapEntities.Parse(text); } else if (pt == SoapType.typeofSoapNmtoken) { obj = SoapNmtoken.Parse(text); } else if (pt == SoapType.typeofSoapNmtokens) { obj = SoapNmtokens.Parse(text); } else if (pt == SoapType.typeofSoapNcName) { obj = SoapNcName.Parse(text); } else if (pt == SoapType.typeofSoapId) { obj = SoapId.Parse(text); } else if (pt == SoapType.typeofSoapIdref) { obj = SoapIdref.Parse(text); } else if (pt == SoapType.typeofSoapEntity) { obj = SoapEntity.Parse(text); } } else if (pt == typeof(bool)) { if (text == "1" || text == "true") { obj = true; } else { if (!(text == "0") && !(text == "false")) { throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Message_CoercionFailed"), text, pt)); } obj = false; } } else if (pt == typeof(DateTime)) { obj = SoapDateTime.Parse(text); } else if (pt.IsPrimitive) { obj = Convert.ChangeType(value, pt, CultureInfo.InvariantCulture); } else if (pt == typeof(TimeSpan)) { obj = SoapDuration.Parse(text); } else if (pt == typeof(char)) { obj = text[0]; } else { obj = Convert.ChangeType(value, pt, CultureInfo.InvariantCulture); } } else { obj = Convert.ChangeType(value, pt, CultureInfo.InvariantCulture); } } } catch (Exception) { } if (obj == null) { string arg; if (RemotingServices.IsTransparentProxy(value)) { arg = typeof(MarshalByRefObject).ToString(); } else { arg = value.ToString(); } throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Message_CoercionFailed"), arg, pt)); } } return(obj); }
internal static object SoapCoerceArg(object value, Type pt, Hashtable keyToNamespaceTable) { object obj = (object)null; if (value != null) { try { if (pt.IsByRef) { pt = pt.GetElementType(); } if (pt.IsInstanceOfType(value)) { obj = value; } else { string s = value as string; if (s != null) { if (pt == typeof(double)) { obj = !(s == "INF") ? (!(s == "-INF") ? (object)double.Parse(s, (IFormatProvider)CultureInfo.InvariantCulture) : (object)double.NegativeInfinity) : (object)double.PositiveInfinity; } else if (pt == typeof(float)) { obj = !(s == "INF") ? (!(s == "-INF") ? (object)float.Parse(s, (IFormatProvider)CultureInfo.InvariantCulture) : (object)float.NegativeInfinity) : (object)float.PositiveInfinity; } else if (SoapType.typeofISoapXsd.IsAssignableFrom(pt)) { if (pt == SoapType.typeofSoapTime) { obj = (object)SoapTime.Parse(s); } else if (pt == SoapType.typeofSoapDate) { obj = (object)SoapDate.Parse(s); } else if (pt == SoapType.typeofSoapYearMonth) { obj = (object)SoapYearMonth.Parse(s); } else if (pt == SoapType.typeofSoapYear) { obj = (object)SoapYear.Parse(s); } else if (pt == SoapType.typeofSoapMonthDay) { obj = (object)SoapMonthDay.Parse(s); } else if (pt == SoapType.typeofSoapDay) { obj = (object)SoapDay.Parse(s); } else if (pt == SoapType.typeofSoapMonth) { obj = (object)SoapMonth.Parse(s); } else if (pt == SoapType.typeofSoapHexBinary) { obj = (object)SoapHexBinary.Parse(s); } else if (pt == SoapType.typeofSoapBase64Binary) { obj = (object)SoapBase64Binary.Parse(s); } else if (pt == SoapType.typeofSoapInteger) { obj = (object)SoapInteger.Parse(s); } else if (pt == SoapType.typeofSoapPositiveInteger) { obj = (object)SoapPositiveInteger.Parse(s); } else if (pt == SoapType.typeofSoapNonPositiveInteger) { obj = (object)SoapNonPositiveInteger.Parse(s); } else if (pt == SoapType.typeofSoapNonNegativeInteger) { obj = (object)SoapNonNegativeInteger.Parse(s); } else if (pt == SoapType.typeofSoapNegativeInteger) { obj = (object)SoapNegativeInteger.Parse(s); } else if (pt == SoapType.typeofSoapAnyUri) { obj = (object)SoapAnyUri.Parse(s); } else if (pt == SoapType.typeofSoapQName) { obj = (object)SoapQName.Parse(s); SoapQName soapQname = (SoapQName)obj; soapQname.Namespace = soapQname.Key.Length != 0 ? (string)keyToNamespaceTable[(object)("xmlns:" + soapQname.Key)] : (string)keyToNamespaceTable[(object)"xmlns"]; } else if (pt == SoapType.typeofSoapNotation) { obj = (object)SoapNotation.Parse(s); } else if (pt == SoapType.typeofSoapNormalizedString) { obj = (object)SoapNormalizedString.Parse(s); } else if (pt == SoapType.typeofSoapToken) { obj = (object)SoapToken.Parse(s); } else if (pt == SoapType.typeofSoapLanguage) { obj = (object)SoapLanguage.Parse(s); } else if (pt == SoapType.typeofSoapName) { obj = (object)SoapName.Parse(s); } else if (pt == SoapType.typeofSoapIdrefs) { obj = (object)SoapIdrefs.Parse(s); } else if (pt == SoapType.typeofSoapEntities) { obj = (object)SoapEntities.Parse(s); } else if (pt == SoapType.typeofSoapNmtoken) { obj = (object)SoapNmtoken.Parse(s); } else if (pt == SoapType.typeofSoapNmtokens) { obj = (object)SoapNmtokens.Parse(s); } else if (pt == SoapType.typeofSoapNcName) { obj = (object)SoapNcName.Parse(s); } else if (pt == SoapType.typeofSoapId) { obj = (object)SoapId.Parse(s); } else if (pt == SoapType.typeofSoapIdref) { obj = (object)SoapIdref.Parse(s); } else if (pt == SoapType.typeofSoapEntity) { obj = (object)SoapEntity.Parse(s); } } else if (pt == typeof(bool)) { if (s == "1" || s == "true") { obj = (object)true; } else { if (!(s == "0") && !(s == "false")) { throw new RemotingException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Message_CoercionFailed"), (object)s, (object)pt)); } obj = (object)false; } } else { obj = !(pt == typeof(DateTime)) ? (!pt.IsPrimitive ? (!(pt == typeof(TimeSpan)) ? (!(pt == typeof(char)) ? Convert.ChangeType(value, pt, (IFormatProvider)CultureInfo.InvariantCulture) : (object)s[0]) : (object)SoapDuration.Parse(s)) : Convert.ChangeType(value, pt, (IFormatProvider)CultureInfo.InvariantCulture)) : (object)SoapDateTime.Parse(s); } } else { obj = Convert.ChangeType(value, pt, (IFormatProvider)CultureInfo.InvariantCulture); } } } catch (Exception ex) { } if (obj == null) { throw new RemotingException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Message_CoercionFailed"), !RemotingServices.IsTransparentProxy(value) ? (object)value.ToString() : (object)typeof(MarshalByRefObject).ToString(), (object)pt)); } } return(obj); }
internal static object SoapCoerceArg(object value, Type pt, Hashtable keyToNamespaceTable) { object obj2 = null; if (value == null) { return(obj2); } try { if (pt.IsByRef) { pt = pt.GetElementType(); } if (pt.IsInstanceOfType(value)) { obj2 = value; } else { string s = value as string; if (s != null) { if (pt == typeof(double)) { if (s == "INF") { obj2 = (double)1.0 / (double)0.0; } else if (s == "-INF") { obj2 = (double)-1.0 / (double)0.0; } else { obj2 = double.Parse(s, CultureInfo.InvariantCulture); } } else if (pt == typeof(float)) { if (s == "INF") { obj2 = (float)1.0 / (float)0.0; } else if (s == "-INF") { obj2 = (float)-1.0 / (float)0.0; } else { obj2 = float.Parse(s, CultureInfo.InvariantCulture); } } else if (SoapType.typeofISoapXsd.IsAssignableFrom(pt)) { if (pt == SoapType.typeofSoapTime) { obj2 = SoapTime.Parse(s); } else if (pt == SoapType.typeofSoapDate) { obj2 = SoapDate.Parse(s); } else if (pt == SoapType.typeofSoapYearMonth) { obj2 = SoapYearMonth.Parse(s); } else if (pt == SoapType.typeofSoapYear) { obj2 = SoapYear.Parse(s); } else if (pt == SoapType.typeofSoapMonthDay) { obj2 = SoapMonthDay.Parse(s); } else if (pt == SoapType.typeofSoapDay) { obj2 = SoapDay.Parse(s); } else if (pt == SoapType.typeofSoapMonth) { obj2 = SoapMonth.Parse(s); } else if (pt == SoapType.typeofSoapHexBinary) { obj2 = SoapHexBinary.Parse(s); } else if (pt == SoapType.typeofSoapBase64Binary) { obj2 = SoapBase64Binary.Parse(s); } else if (pt == SoapType.typeofSoapInteger) { obj2 = SoapInteger.Parse(s); } else if (pt == SoapType.typeofSoapPositiveInteger) { obj2 = SoapPositiveInteger.Parse(s); } else if (pt == SoapType.typeofSoapNonPositiveInteger) { obj2 = SoapNonPositiveInteger.Parse(s); } else if (pt == SoapType.typeofSoapNonNegativeInteger) { obj2 = SoapNonNegativeInteger.Parse(s); } else if (pt == SoapType.typeofSoapNegativeInteger) { obj2 = SoapNegativeInteger.Parse(s); } else if (pt == SoapType.typeofSoapAnyUri) { obj2 = SoapAnyUri.Parse(s); } else if (pt == SoapType.typeofSoapQName) { obj2 = SoapQName.Parse(s); SoapQName name = (SoapQName)obj2; if (name.Key.Length == 0) { name.Namespace = (string)keyToNamespaceTable["xmlns"]; } else { name.Namespace = (string)keyToNamespaceTable["xmlns:" + name.Key]; } } else if (pt == SoapType.typeofSoapNotation) { obj2 = SoapNotation.Parse(s); } else if (pt == SoapType.typeofSoapNormalizedString) { obj2 = SoapNormalizedString.Parse(s); } else if (pt == SoapType.typeofSoapToken) { obj2 = SoapToken.Parse(s); } else if (pt == SoapType.typeofSoapLanguage) { obj2 = SoapLanguage.Parse(s); } else if (pt == SoapType.typeofSoapName) { obj2 = SoapName.Parse(s); } else if (pt == SoapType.typeofSoapIdrefs) { obj2 = SoapIdrefs.Parse(s); } else if (pt == SoapType.typeofSoapEntities) { obj2 = SoapEntities.Parse(s); } else if (pt == SoapType.typeofSoapNmtoken) { obj2 = SoapNmtoken.Parse(s); } else if (pt == SoapType.typeofSoapNmtokens) { obj2 = SoapNmtokens.Parse(s); } else if (pt == SoapType.typeofSoapNcName) { obj2 = SoapNcName.Parse(s); } else if (pt == SoapType.typeofSoapId) { obj2 = SoapId.Parse(s); } else if (pt == SoapType.typeofSoapIdref) { obj2 = SoapIdref.Parse(s); } else if (pt == SoapType.typeofSoapEntity) { obj2 = SoapEntity.Parse(s); } } else { if (pt == typeof(bool)) { switch (s) { case "1": case "true": obj2 = true; goto Label_055E; case "0": case "false": obj2 = false; goto Label_055E; } throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Message_CoercionFailed"), new object[] { s, pt })); } if (pt == typeof(DateTime)) { obj2 = SoapDateTime.Parse(s); } else if (pt.IsPrimitive) { obj2 = Convert.ChangeType(value, pt, CultureInfo.InvariantCulture); } else if (pt == typeof(TimeSpan)) { obj2 = SoapDuration.Parse(s); } else if (pt == typeof(char)) { obj2 = s[0]; } else { obj2 = Convert.ChangeType(value, pt, CultureInfo.InvariantCulture); } } } else { obj2 = Convert.ChangeType(value, pt, CultureInfo.InvariantCulture); } } } catch (Exception) { } Label_055E: if (obj2 != null) { return(obj2); } string str2 = null; if (RemotingServices.IsTransparentProxy(value)) { str2 = typeof(MarshalByRefObject).ToString(); } else { str2 = value.ToString(); } throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Message_CoercionFailed"), new object[] { str2, pt })); }
internal static object FromString(string value, InternalPrimitiveTypeE code) { switch (code) { case InternalPrimitiveTypeE.Boolean: if (!(value == "1") && !(value == "true")) { if ((value != "0") && (value != "false")) { throw new SerializationException(string.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_typeCoercion"), new object[] { value, "Boolean" })); } return(false); } return(true); case InternalPrimitiveTypeE.Double: if (!(value == "INF")) { if (value == "-INF") { return((double)-1.0 / (double)0.0); } return(double.Parse(value, CultureInfo.InvariantCulture)); } return((double)1.0 / (double)0.0); case InternalPrimitiveTypeE.Single: if (!(value == "INF")) { if (value == "-INF") { return((float)-1.0 / (float)0.0); } return(float.Parse(value, CultureInfo.InvariantCulture)); } return((float)1.0 / (float)0.0); case InternalPrimitiveTypeE.TimeSpan: return(SoapDuration.Parse(value)); case InternalPrimitiveTypeE.DateTime: return(SoapDateTime.Parse(value)); case InternalPrimitiveTypeE.Time: return(SoapTime.Parse(value)); case InternalPrimitiveTypeE.Date: return(SoapDate.Parse(value)); case InternalPrimitiveTypeE.YearMonth: return(SoapYearMonth.Parse(value)); case InternalPrimitiveTypeE.Year: return(SoapYear.Parse(value)); case InternalPrimitiveTypeE.MonthDay: return(SoapMonthDay.Parse(value)); case InternalPrimitiveTypeE.Day: return(SoapDay.Parse(value)); case InternalPrimitiveTypeE.Month: return(SoapMonth.Parse(value)); case InternalPrimitiveTypeE.HexBinary: return(SoapHexBinary.Parse(value)); case InternalPrimitiveTypeE.Base64Binary: return(SoapBase64Binary.Parse(value)); case InternalPrimitiveTypeE.Integer: return(SoapInteger.Parse(value)); case InternalPrimitiveTypeE.PositiveInteger: return(SoapPositiveInteger.Parse(value)); case InternalPrimitiveTypeE.NonPositiveInteger: return(SoapNonPositiveInteger.Parse(value)); case InternalPrimitiveTypeE.NonNegativeInteger: return(SoapNonNegativeInteger.Parse(value)); case InternalPrimitiveTypeE.NegativeInteger: return(SoapNegativeInteger.Parse(value)); case InternalPrimitiveTypeE.AnyUri: return(SoapAnyUri.Parse(value)); case InternalPrimitiveTypeE.QName: return(SoapQName.Parse(value)); case InternalPrimitiveTypeE.Notation: return(SoapNotation.Parse(value)); case InternalPrimitiveTypeE.NormalizedString: return(SoapNormalizedString.Parse(value)); case InternalPrimitiveTypeE.Token: return(SoapToken.Parse(value)); case InternalPrimitiveTypeE.Language: return(SoapLanguage.Parse(value)); case InternalPrimitiveTypeE.Name: return(SoapName.Parse(value)); case InternalPrimitiveTypeE.Idrefs: return(SoapIdrefs.Parse(value)); case InternalPrimitiveTypeE.Entities: return(SoapEntities.Parse(value)); case InternalPrimitiveTypeE.Nmtoken: return(SoapNmtoken.Parse(value)); case InternalPrimitiveTypeE.Nmtokens: return(SoapNmtokens.Parse(value)); case InternalPrimitiveTypeE.NcName: return(SoapNcName.Parse(value)); case InternalPrimitiveTypeE.Id: return(SoapId.Parse(value)); case InternalPrimitiveTypeE.Idref: return(SoapIdref.Parse(value)); case InternalPrimitiveTypeE.Entity: return(SoapEntity.Parse(value)); } if (code != InternalPrimitiveTypeE.Invalid) { return(Convert.ChangeType(value, ToTypeCode(code), CultureInfo.InvariantCulture)); } return(value); }