//[Variation(Desc = "v1 - CopyTo with array = null")] public void v1() { try { XmlSchemaSet sc = new XmlSchemaSet(); sc.Add("xsdauthor", TestData._XsdAuthor); sc.CopyTo(null, 0); } catch (ArgumentNullException) { // GLOBALIZATION return; } Assert.True(false); }
public void v3() { XmlSchemaSet sc = new XmlSchemaSet(); XmlSchema Schema1 = sc.Add("xsdauthor1", TestData._XsdNoNs); XmlSchema Schema2 = sc.Add("xsdauthor", TestData._XsdAuthor); ICollection Col = sc.Schemas(); CError.Compare(Col.Count, 2, "Count"); XmlSchema[] Schemas = new XmlSchema[2]; sc.CopyTo(Schemas, 0); int i = 0; foreach (XmlSchema Schema in Col) { CError.Compare(Schema, Schemas[i], "Schema"); i++; } return; }
internal XmlSerializableMapping(XmlRootAttribute root, string elementName, string ns, TypeData typeData, string xmlType, string xmlTypeNamespace) : base(elementName, ns, typeData, xmlType, xmlTypeNamespace) { #if NET_2_0 && !MOONLIGHT XmlSchemaProviderAttribute schemaProvider = (XmlSchemaProviderAttribute) Attribute.GetCustomAttribute (typeData.Type, typeof (XmlSchemaProviderAttribute)); if (schemaProvider != null) { string method = schemaProvider.MethodName; MethodInfo mi = typeData.Type.GetMethod (method, BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy); if (mi == null) throw new InvalidOperationException (String.Format ("Type '{0}' must implement public static method '{1}'", typeData.Type, method)); if (!typeof (XmlQualifiedName).IsAssignableFrom (mi.ReturnType) && // LAMESPEC: it is undocumented. (We don't have to tell users about it in the error message.) // Also do not add such a silly compatibility test to assert that it does not raise an error. !typeof (XmlSchemaComplexType).IsAssignableFrom (mi.ReturnType)) throw new InvalidOperationException (String.Format ("Method '{0}' indicated by XmlSchemaProviderAttribute must have its return type as XmlQualifiedName", method)); XmlSchemaSet xs = new XmlSchemaSet (); object retVal = mi.Invoke (null, new object [] { xs }); _schemaTypeName = XmlQualifiedName.Empty; if (retVal == null) return; if (retVal is XmlSchemaComplexType) { _schemaType = (XmlSchemaComplexType) retVal; if (!_schemaType.QualifiedName.IsEmpty) _schemaTypeName = _schemaType.QualifiedName; else _schemaTypeName = new XmlQualifiedName (xmlType, xmlTypeNamespace); } else if (retVal is XmlQualifiedName) { _schemaTypeName = (XmlQualifiedName)retVal; } else throw new InvalidOperationException ( String.Format ("Method {0}.{1}() specified by XmlSchemaProviderAttribute has invalid signature: return type must be compatible with System.Xml.XmlQualifiedName.", typeData.Type.Name, method)); // defaultNamespace at XmlReflectionImporter takes precedence for Namespace, but not for XsdTypeNamespace. UpdateRoot (new XmlQualifiedName (root != null ? root.ElementName : _schemaTypeName.Name, root != null ? root.Namespace : Namespace ?? _schemaTypeName.Namespace)); XmlTypeNamespace = _schemaTypeName.Namespace; XmlType = _schemaTypeName.Name; if (!_schemaTypeName.IsEmpty && xs.Count > 0) { XmlSchema [] schemas = new XmlSchema [xs.Count]; xs.CopyTo (schemas, 0); _schema = schemas [0]; } return; } #endif #if NET_2_0 && !MOONLIGHT IXmlSerializable serializable = (IXmlSerializable)Activator.CreateInstance (typeData.Type, true); try { _schema = serializable.GetSchema(); } catch (Exception) { // LAMESPEC: .NET has a bad exception catch and swallows it silently. } #else IXmlSerializable serializable = (IXmlSerializable)Activator.CreateInstance (typeData.Type); _schema = serializable.GetSchema(); #endif #if !MOONLIGHT if (_schema != null) { if (_schema.Id == null || _schema.Id.Length == 0) throw new InvalidOperationException("Schema Id is missing. The schema returned from " + typeData.Type.FullName + ".GetSchema() must have an Id."); } #endif }
public void CopyTo(XmlSchema[] array, int index) { lock (schemaSet) { schemaSet.CopyTo(array, index); } }
//[Variation(Desc = "v4 - CopyTo with index < 0")] public void v4() { XmlSchemaSet sc = new XmlSchemaSet(); try { sc.Add("xsdauthor", TestData._XsdAuthor); sc.Add(null, TestData._XsdNoNs); XmlSchema[] array = new XmlSchema[1]; sc.CopyTo(array, -1); } catch (ArgumentException) { // GLOBALIZATION return; } Assert.True(false); }
//[Variation(Desc = "v8 - 378346: CopyTo throws correct exception for index < 0 but incorrect exception for index > maxLength of array.", Priority = 0)] public void v8() { try { XmlSchemaSet ss = new XmlSchemaSet(); ss.CopyTo(new XmlSchema[2], 3); } catch (ArgumentOutOfRangeException e) { _output.WriteLine(e.Message); return; } Assert.True(false); }
//[Variation(Desc = "v7 - Copy all to array of the same size", Priority = 0)] public void v7() { XmlSchemaSet sc = new XmlSchemaSet(); XmlSchema Schema1 = sc.Add("xsdauthor", TestData._XsdAuthor); XmlSchema Schema2 = sc.Add(null, TestData._XsdNoNs); XmlSchema[] array = new XmlSchema[2]; sc.CopyTo(array, 0); Assert.Equal(array[0], Schema1); Assert.Equal(array[1], Schema2); return; }
static void ReprocessAll(XmlSchemaSet schemas)// and remove duplicate items { Hashtable elements = new Hashtable(); Hashtable types = new Hashtable(); XmlSchema[] schemaArray = new XmlSchema[schemas.Count]; schemas.CopyTo(schemaArray, 0); for (int i = 0; i < schemaArray.Length; i++) { XmlSchema schema = schemaArray[i]; XmlSchemaObject[] itemArray = new XmlSchemaObject[schema.Items.Count]; schema.Items.CopyTo(itemArray, 0); for (int j = 0; j < itemArray.Length; j++) { XmlSchemaObject item = itemArray[j]; Hashtable items; XmlQualifiedName qname; if (item is XmlSchemaElement) { items = elements; qname = new XmlQualifiedName(((XmlSchemaElement)item).Name, schema.TargetNamespace); } else if (item is XmlSchemaType) { items = types; qname = new XmlQualifiedName(((XmlSchemaType)item).Name, schema.TargetNamespace); } else continue; object otherItem = items[qname]; if (otherItem != null) { if (DiagnosticUtility.ShouldTraceWarning) { Dictionary<string, string> values = new Dictionary<string, string>(2) { { "ItemType", item.ToString() }, { "Name", qname.Namespace + ":" + qname.Name } }; TraceUtility.Trace(TraceEventType.Warning, TraceCode.XsdExportDupItems, SR.GetString(SR.TraceCodeXsdExportDupItems), new DictionaryTraceRecord(values)); } schema.Items.Remove(item); } else items.Add(qname, item); } schemas.Reprocess(schema); } }
private static void ReprocessAll(XmlSchemaSet schemas) { Hashtable hashtable = new Hashtable(); Hashtable hashtable2 = new Hashtable(); XmlSchema[] schemaArray = new XmlSchema[schemas.Count]; schemas.CopyTo(schemaArray, 0); for (int i = 0; i < schemaArray.Length; i++) { XmlSchema schema = schemaArray[i]; XmlSchemaObject[] array = new XmlSchemaObject[schema.Items.Count]; schema.Items.CopyTo(array, 0); for (int j = 0; j < array.Length; j++) { Hashtable hashtable3; XmlQualifiedName name; XmlSchemaObject item = array[j]; if (item is XmlSchemaElement) { hashtable3 = hashtable; name = new XmlQualifiedName(((XmlSchemaElement) item).Name, schema.TargetNamespace); } else { if (!(item is XmlSchemaType)) { continue; } hashtable3 = hashtable2; name = new XmlQualifiedName(((XmlSchemaType) item).Name, schema.TargetNamespace); } if (hashtable3[name] != null) { if (DiagnosticUtility.ShouldTraceWarning) { Dictionary<string, string> dictionary2 = new Dictionary<string, string>(2); dictionary2.Add("ItemType", item.ToString()); dictionary2.Add("Name", name.Namespace + ":" + name.Name); Dictionary<string, string> dictionary = dictionary2; TraceUtility.Trace(TraceEventType.Warning, 0x30010, System.Runtime.Serialization.SR.GetString("TraceCodeXsdExportDupItems"), new DictionaryTraceRecord(dictionary)); } schema.Items.Remove(item); } else { hashtable3.Add(name, item); } } schemas.Reprocess(schema); } }