public void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context) { if (this.Enable) { XsdDataContractExporter dataContractExporter; object dataContractExporterObj = null; if (exporter.State.TryGetValue(typeof(XsdDataContractExporter), out dataContractExporterObj)) { dataContractExporter = dataContractExporterObj as XsdDataContractExporter; } else { XmlSchemaSet set = exporter.GeneratedXmlSchemas; //Annotation.GetSchemaAnnotation(set); //set.Compile(); dataContractExporter = new XsdDataContractExporter(set); exporter.State.Add(typeof(XsdDataContractExporter), dataContractExporter); } if (dataContractExporter.Options == null) { dataContractExporter.Options = new ExportOptions(); } if (dataContractExporter.Options.DataContractSurrogate == null) { dataContractExporter.Options.DataContractSurrogate = new DataContractAnnotationSurrogate() { ExportAsText = this.ExportAsText, IsBehaviorExtension = this.IsBehaviorExtensions } } ; } }
private void MetadataImport() { //<snippet10> WsdlExporter exporter = new WsdlExporter(); //or //public void ExportContract(WsdlExporter exporter, // WsdlContractConversionContext context) { ... } object dataContractExporter; XsdDataContractExporter xsdInventoryExporter; if (!exporter.State.TryGetValue(typeof(XsdDataContractExporter), out dataContractExporter)) { xsdInventoryExporter = new XsdDataContractExporter(exporter.GeneratedXmlSchemas); } else { xsdInventoryExporter = (XsdDataContractExporter)dataContractExporter; } exporter.State.Add(typeof(XsdDataContractExporter), xsdInventoryExporter); if (xsdInventoryExporter.Options == null) { xsdInventoryExporter.Options = new ExportOptions(); } xsdInventoryExporter.Options.DataContractSurrogate = new InventorySurrogated(); //</snippet10> }
public void Ctor_Default() { XsdDataContractExporter xce = new XsdDataContractExporter(); Assert.NotNull(xce); Assert.Null(xce.Options); }
// This is a helper method called after a type has been selected to determine whether the type is valid // for use as a parameter type. This check it too expensive to perform during filtering. public static bool IsValidType(Type type) { bool result = true; if (!IsExemptType(type)) { try { XsdDataContractExporter exporter = new XsdDataContractExporter(); if (!exporter.CanExport(type)) { result = false; } } catch (InvalidDataContractException exception) { DiagnosticUtility.TraceHandledException(exception, TraceEventType.Warning); result = false; } catch (NotImplementedException exception) { // This occurs when a design-time type is involved (for example, as a type parameter), in // which case we don't want to exclude the type from use as parameter type. DiagnosticUtility.TraceHandledException(exception, TraceEventType.Information); } } return(result); }
/// <summary> /// Returns the sequence of properties of the specified type. /// </summary> /// <param name="type">The type.</param> /// <param name="schema">The schema.</param> /// <param name="schemaSet">The schema set.</param> /// <param name="serializationManager">The serialization manager.</param> /// <param name="exportedTypes">The exported types.</param> /// <returns>Sequence containing all properties.</returns> private static XmlSchemaSequence GetPropertiesSequence(Type type, XmlSchema schema, XmlSchemaSet schemaSet, ISerializationManager serializationManager, HashSet <string> exportedTypes) { Argument.IsNotNull("type", type); Argument.IsNotNull("schema", schema); Argument.IsNotNull("schemaSet", schemaSet); var propertiesSequence = new XmlSchemaSequence(); if (type.IsModelBase()) { var members = new List <MemberMetadata>(); members.AddRange(from field in serializationManager.GetFieldsToSerialize(type) select field.Value); members.AddRange(from property in serializationManager.GetCatelPropertiesToSerialize(type) select property.Value); members.AddRange(from property in serializationManager.GetRegularPropertiesToSerialize(type) select property.Value); foreach (var member in members) { var propertySchemaElement = new XmlSchemaElement(); propertySchemaElement.Name = member.MemberName; var memberType = member.MemberType; propertySchemaElement.IsNillable = memberType.IsNullableType(); propertySchemaElement.MinOccurs = 0; var exporter = new XsdDataContractExporter(schemaSet); var alreadyExported = IsAlreadyExported(schemaSet, memberType, exporter, exportedTypes); if (!alreadyExported) { if (!exportedTypes.Contains(memberType.FullName)) { exportedTypes.Add(memberType.FullName); } try { if (exporter.CanExport(memberType)) { exporter.Export(memberType); } } catch (Exception) { // Ignore } } propertySchemaElement.SchemaType = exporter.GetSchemaType(memberType); propertySchemaElement.SchemaTypeName = exporter.GetSchemaTypeName(memberType); propertiesSequence.Items.Add(propertySchemaElement); } } return(propertiesSequence); }
public static bool IsValidParameter(Type type, ICustomAttributeProvider attributeProvider, bool allowReferences, out string typeMismatchDetails) { typeMismatchDetails = type.ToString() + " "; object[] attributes = attributeProvider.GetCustomAttributes(typeof(MarshalAsAttribute), true); foreach (MarshalAsAttribute attr in attributes) { UnmanagedType marshalAs = attr.Value; if (marshalAs == UnmanagedType.IDispatch || marshalAs == UnmanagedType.Interface || marshalAs == UnmanagedType.IUnknown) { if (!allowReferences) { typeMismatchDetails += SR.GetString(SR.HasMarshalAsAttributeOfType, marshalAs); } return(allowReferences); } } XsdDataContractExporter exporter = new XsdDataContractExporter(); if (!exporter.CanExport(type)) { typeMismatchDetails += SR.GetString(SR.CannotBeExportedByDataContractExporter); return(false); } return(true); }
public static bool IsValidParameter(Type type, ICustomAttributeProvider attributeProvider, bool allowReferences) { object[] attributes = System.ServiceModel.Description.ServiceReflector.GetCustomAttributes(attributeProvider, typeof(MarshalAsAttribute), true); foreach (MarshalAsAttribute attr in attributes) { UnmanagedType marshalAs = attr.Value; if (marshalAs == UnmanagedType.IDispatch || marshalAs == UnmanagedType.Interface || marshalAs == UnmanagedType.IUnknown) { return(allowReferences); } } XsdDataContractExporter exporter = new XsdDataContractExporter(); if (!exporter.CanExport(type)) { return(false); } return(true); }
public void ExportContract(System.ServiceModel.Description.WsdlExporter exporter, System.ServiceModel.Description.WsdlContractConversionContext context) { if (exporter == null) { throw new ArgumentNullException("exporter"); } object dataContractExporter; XsdDataContractExporter xsdDCExporter; if (!exporter.State.TryGetValue(typeof(XsdDataContractExporter), out dataContractExporter)) { xsdDCExporter = new XsdDataContractExporter(exporter.GeneratedXmlSchemas); exporter.State.Add(typeof(XsdDataContractExporter), xsdDCExporter); } else { xsdDCExporter = (XsdDataContractExporter)dataContractExporter; } if (xsdDCExporter.Options == null) { xsdDCExporter.Options = new ExportOptions(); } if (xsdDCExporter.Options.DataContractSurrogate == null) { xsdDCExporter.Options.DataContractSurrogate = new DbusContainerSurrogate(); } }
private static void InitXsdDataContractExporter(WsdlExporter exporter, XmlCommentFormat format) { object dataContractExporter; XsdDataContractExporter xsdExporter; if (!exporter.State.TryGetValue(typeof(XsdDataContractExporter), out dataContractExporter)) { xsdExporter = new XsdDataContractExporter(exporter.GeneratedXmlSchemas); exporter.State.Add(typeof(XsdDataContractExporter), xsdExporter); } else { xsdExporter = (XsdDataContractExporter)dataContractExporter; } if (xsdExporter.Options == null) { xsdExporter.Options = new ExportOptions(); } if (!(xsdExporter.Options.DataContractSurrogate is XmlCommentsDataSurrogate)) { xsdExporter.Options.DataContractSurrogate = new XmlCommentsDataSurrogate(xsdExporter.Options.DataContractSurrogate, format); } }
static XmlSchemaSet Export() { XsdDataContractExporter ex = new XsdDataContractExporter(); ex.Export(typeof(Person)); return(ex.Schemas); }
public static string GetXsd(Type operationType) { if (operationType == null) { return(null); } var sb = StringBuilderCache.Allocate(); var exporter = new XsdDataContractExporter(); if (exporter.CanExport(operationType)) { exporter.Export(operationType); var mySchemas = exporter.Schemas; var qualifiedName = exporter.GetRootElementName(operationType); if (qualifiedName == null) { return(null); } foreach (XmlSchema schema in mySchemas.Schemas(qualifiedName.Namespace)) { schema.Write(new StringWriter(sb)); } } return(StringBuilderCache.ReturnAndFree(sb)); }
public void GetSchemaTypeTest() { XsdDataContractExporter xdce = new XsdDataContractExporter(); Assert.IsNull(xdce.GetSchemaType(typeof(dc))); Assert.AreEqual(new QName("_dc", "http://schemas.datacontract.org/2004/07/MonoTests.System.Runtime.Serialization"), xdce.GetSchemaTypeName(typeof(dc))); }
public void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context) { if (exporter == null) { throw new ArgumentNullException("exporter"); } object dataContractExporter; XsdDataContractExporter xsdDCExporter; if (!exporter.State.TryGetValue(typeof(XsdDataContractExporter), out dataContractExporter)) { xsdDCExporter = new XsdDataContractExporter(exporter.GeneratedXmlSchemas); exporter.State.Add(typeof(XsdDataContractExporter), xsdDCExporter); } else { xsdDCExporter = (XsdDataContractExporter)dataContractExporter; } if (xsdDCExporter.Options == null) { xsdDCExporter.Options = new ExportOptions(); } if (xsdDCExporter.Options.DataContractSurrogate == null) { xsdDCExporter.Options.DataContractSurrogate = new AllowNonSerializableTypesSurrogate(); } }
internal void ComputeOuterNameAndNs(out string name, out string ns) { if (this.outerName != null) { name = this.outerName; ns = this.outerNamespace; } else if (this.dataContractSerializer != null) { XmlQualifiedName rootElementName = new XsdDataContractExporter().GetRootElementName(this.extensionData.GetType()); if (rootElementName != null) { name = rootElementName.Name; ns = rootElementName.Namespace; } else { this.ReadOuterNameAndNs(out name, out ns); } } else { XmlTypeMapping mapping = new XmlReflectionImporter().ImportTypeMapping(this.extensionData.GetType()); if ((mapping != null) && !string.IsNullOrEmpty(mapping.ElementName)) { name = mapping.ElementName; ns = mapping.Namespace; } else { this.ReadOuterNameAndNs(out name, out ns); } } }
public void GetSchemaTypeName() { var xdce = new XsdDataContractExporter(); // bug #670539 Assert.AreEqual(new XmlQualifiedName("ArrayOfstring", MSArraysNamespace), xdce.GetSchemaTypeName(typeof(IEnumerable <string>)), "#1"); }
public void DcTest() { XsdDataContractExporter xdce = new XsdDataContractExporter(); xdce.Export(typeof(dc)); CheckDcFull(xdce.Schemas); }
public static XmlSchemaSet GetXmlSchemaSet(ICollection <Type> operationTypes) { var exporter = new XsdDataContractExporter(); exporter.Export(operationTypes); exporter.Schemas.Compile(); return(exporter.Schemas); }
public void Dc3Test() { //Check for duplicate dc2 ? XsdDataContractExporter xdce = new XsdDataContractExporter(); xdce.Export(typeof(dc3)); CheckDcFull(xdce.Schemas); }
public void EnumTest() { XsdDataContractExporter xdce = new XsdDataContractExporter(); xdce.Export(typeof(XColors)); CheckEnum(xdce.Schemas, colors_qname, new List <string> (new string [] { "_Red" })); }
public void RountTripTest() { // AppContext SetSwitch seems to be unreliable in the unit test case. So let's not rely on it // for test coverage. But let's do look at the app switch to get our verification correct. AppContext.TryGetSwitch("Switch.System.Runtime.Serialization.DataContracts.Auto_Import_KVP", out bool autoImportKVP); XsdDataContractExporter exporter = new XsdDataContractExporter(); exporter.Export(typeof(RootClass)); XsdDataContractImporter importer = new XsdDataContractImporter(); importer.Options = new ImportOptions(); importer.Options.ImportXmlType = true; importer.Options.ReferencedTypes.Add(typeof(DBNull)); importer.Options.ReferencedTypes.Add(typeof(DateTimeOffset)); importer.Import(exporter.Schemas); string code = SchemaUtils.DumpCode(importer.CodeCompileUnit); _output.WriteLine(code); Assert.Contains(@"This code was generated by a tool.", code); Assert.Contains(@"namespace System.Runtime.Serialization.Schema.Tests", code); Assert.Contains(@"public partial class RoundTripTestRootClass : object, System.Runtime.Serialization.IExtensibleDataObject", code); Assert.Contains(@"[System.Xml.Serialization.XmlRootAttribute(ElementName=""SchemaDefinedType"", Namespace=""http://schemas.datacontract.org/2004/07/System.Runtime.Serialization"")]", code); Assert.Contains(@"public partial class dataSetType : object, System.Xml.Serialization.IXmlSerializable", code); Assert.Contains(@"[System.Runtime.Serialization.DataContractAttribute(Name=""RoundTripTest.DataContractClass"", Namespace=""http://schemas.datacontract.org/2004/07/System.Runtime.Serialization.Schema.Tests""", code); Assert.Contains(@"public partial class RoundTripTestDataContractClass : object, System.Runtime.Serialization.IExtensibleDataObject", code); Assert.Contains(@"[System.Runtime.Serialization.DataContractAttribute(Name=""RoundTripTest.DataContractStruct"", Namespace=""http://schemas.datacontract.org/2004/07/System.Runtime.Serialization.Schema.Tests""", code); Assert.Contains(@"public partial struct RoundTripTestDataContractStruct : System.Runtime.Serialization.IExtensibleDataObject", code); Assert.Contains(@"[System.Runtime.Serialization.DataContractAttribute(Name=""RoundTripTest.EmitDefaultClass"", Namespace=""http://schemas.datacontract.org/2004/07/System.Runtime.Serialization.Schema.Tests""", code); Assert.Contains(@"public partial class RoundTripTestEmitDefaultClass : object, System.Runtime.Serialization.IExtensibleDataObject", code); Assert.Contains(@"public System.Nullable<System.Runtime.Serialization.Schema.Tests.RoundTripTestDataContractStruct> NullableDataContractStruct2", code); Assert.Contains(@"[System.Runtime.Serialization.DataContractAttribute(Name=""RoundTripTest.EncodingMismatchClass"", Namespace=""http://schemas.datacontract.org/2004/07/System.Runtime.Serialization.Schema.Tests""", code); Assert.Contains(@"public partial class RoundTripTestEncodingMismatchClass : object, System.Runtime.Serialization.IExtensibleDataObject", code); Assert.Contains(@"public enum RoundTripTestMyEnum : int", code); Assert.Contains(@"TwoHundred = 200", code); Assert.Contains(@"public enum RoundTripTestMyFlagsEnum : int", code); Assert.Contains(@"Four = 4,", code); Assert.Contains(@"public class ArrayOfNullableOfRoundTripTestMyEnumho3BZmza : System.Collections.Generic.List<System.Runtime.Serialization.Schema.Tests.RoundTripTestMyEnum>", code); Assert.Contains(@"namespace schemas.microsoft.com._2003._10.Serialization.Arrays", code); Assert.Contains(@"public partial class ArrayOfKeyValueOfintArrayOfstringty7Ep6D1 : object, System.Xml.Serialization.IXmlSerializable", code); Assert.Contains(@"private static System.Xml.XmlQualifiedName typeName = new System.Xml.XmlQualifiedName(""ArrayOfKeyValueOfintArrayOfstringty7Ep6D1"", ""http://schemas.microsoft.com/2003/10/Serialization/Arrays"");", code); Assert.Contains(@"public partial class ArrayOfKeyValueOfNullableOfunsignedByteNullableOfunsignedByte_ShTDFhl_P : object, System.Xml.Serialization.IXmlSerializable", code); if (autoImportKVP) { Assert.Contains(@"public partial struct KeyValuePairOfintArrayOfstringty7Ep6D1 : System.Runtime.Serialization.IExtensibleDataObject", code); Assert.Contains(@"public partial struct KeyValuePairOfNullableOfunsignedByteNullableOfunsignedByte_ShTDFhl_P : System.Runtime.Serialization.IExtensibleDataObject", code); Assert.Contains(@"[System.Runtime.Serialization.DataContractAttribute(Name=""KeyValuePairOfstringNullableOfintU6ho3Bhd"", Namespace=""http://schemas.datacontract.org/2004/07/System.Collections.Generic"")]", code); } else { Assert.DoesNotContain(@"public partial struct KeyValuePairOfintArrayOfstringty7Ep6D1 : System.Runtime.Serialization.IExtensibleDataObject", code); Assert.DoesNotContain(@"public partial struct KeyValuePairOfNullableOfunsignedByteNullableOfunsignedByte_ShTDFhl_P : System.Runtime.Serialization.IExtensibleDataObject", code); Assert.DoesNotContain(@"[System.Runtime.Serialization.DataContractAttribute(Name=""KeyValuePairOfstringNullableOfintU6ho3Bhd"", Namespace=""http://schemas.datacontract.org/2004/07/System.Collections.Generic"")]", code); } }
//</snippet1> //<snippet2> static void GetXmlElementName() { XsdDataContractExporter myExporter = new XsdDataContractExporter(); XmlQualifiedName xmlElementName = myExporter.GetRootElementName(typeof(Employee)); Console.WriteLine("Namespace: {0}", xmlElementName.Namespace); Console.WriteLine("Name: {0}", xmlElementName.Name); Console.WriteLine("IsEmpty: {0}", xmlElementName.IsEmpty); }
public static XmlSchemaSet GetXmlSchemaSet(ICollection <Type> operationTypes) { var exporter = new XsdDataContractExporter(); var types = HostContext.AppHost.ExportSoapTypes(operationTypes); exporter.Export(types); exporter.Schemas.Compile(); return(exporter.Schemas); }
public void GetImportOptions() { XsdDataContractExporter exporter = new XsdDataContractExporter(); var options = new ExportOptions(); exporter.Options = options; Assert.NotNull(exporter.Options); Assert.Equal(options, exporter.Options); }
public void SetImportOptions() { XsdDataContractExporter e = new XsdDataContractExporter(); e.Options = new ExportOptions(); Assert.Empty(e.Options.KnownTypes); e.Options.KnownTypes.Add(typeof(Types.Point)); Assert.Single(e.Options.KnownTypes); }
public void Ctor_Schemas() { XmlSchemaSet schemaSet = new XmlSchemaSet(); XsdDataContractExporter xce = new XsdDataContractExporter(schemaSet); Assert.NotNull(xce); Assert.Null(xce.Options); Assert.Equal(schemaSet, xce.Schemas); }
public void ReferenceTypes() // From IsReferenceTypes.cs { List <Type> types = new List <Type>() { typeof(ExporterTypesTests.Order_ContainsRef), typeof(ExporterTypesTests.Customers_ContainsDuplicateRefs), typeof(ExporterTypesTests.Student_ContainsDuplicateCollectionRefs), typeof(ExporterTypesTests.CircularLinkedList_ContainsBackpointingRef), typeof(ExporterTypesTests.RefCircularLinks_ContainsBackpointer), typeof(ExporterTypesTests.RefCircularNodeA_ContainsRefWithBackpointer), typeof(ExporterTypesTests.RefNestedNode_ContainsBackpointer), typeof(ExporterTypesTests.RefSimpleDataContractCycle_ContainsRefWithBackpointer), typeof(ExporterTypesTests.Fruit), typeof(ExporterTypesTests.RefApple), typeof(ExporterTypesTests.EdibleContainer_ContainsPolymorphicRefs), }; XsdDataContractExporter exporter = new XsdDataContractExporter(); ExportOptions options = new ExportOptions(); options.KnownTypes.Add(typeof(ArrayList)); options.KnownTypes.Add(typeof(Guid)); exporter.Export(types); exporter.Export(types); // Run twice, to ensure that types are not re-exported string schemas = SchemaUtils.DumpSchema(exporter.Schemas); _output.WriteLine(schemas); _output.WriteLine($"----------------- {exporter.Schemas.Count}, {exporter.Schemas.GlobalElements.Count}, {exporter.Schemas.GlobalTypes.Count}"); Assert.Equal(3, exporter.Schemas.Count); Assert.Equal(39, exporter.Schemas.GlobalElements.Count); Assert.Equal(21, exporter.Schemas.GlobalTypes.Count); SchemaUtils.OrderedContains(@"<xs:schema xmlns:tns=""http://schemas.datacontract.org/2004/07/System.Runtime.Serialization.Xml.XsdDataContractExporterTests"" xmlns:ser=""http://schemas.microsoft.com/2003/10/Serialization/"" elementFormDefault=""qualified"" targetNamespace=""http://schemas.datacontract.org/2004/07/System.Runtime.Serialization.Xml.XsdDataContractExporterTests"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">", ref schemas); SchemaUtils.OrderedContains(@"<xs:import namespace=""http://schemas.microsoft.com/2003/10/Serialization/"" />", ref schemas); SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.Order_ContainsRef"">", ref schemas); SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefCustomer"">", ref schemas); SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.Customers_ContainsDuplicateRefs"">", ref schemas); SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.Student_ContainsDuplicateCollectionRefs"">", ref schemas); SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefGrades"">", ref schemas); SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.CircularLinkedList_ContainsBackpointingRef"">", ref schemas); SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefNode"">", ref schemas); SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefCircularLinks_ContainsBackpointer"">", ref schemas); SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefCircularNodeA_ContainsRefWithBackpointer"">", ref schemas); SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefCircularNodeB_ContainsRefWithBackpointer"">", ref schemas); SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefNestedNode_ContainsBackpointer"">", ref schemas); SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefSimpleDataContractCycle_ContainsRefWithBackpointer"">", ref schemas); SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefSimpleDataContractCycleNextLink"">", ref schemas); SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.Fruit"">", ref schemas); SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefEdibleItem"">", ref schemas); SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefApple"">", ref schemas); SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.EdibleContainer_ContainsPolymorphicRefs"">", ref schemas); SchemaUtils.OrderedContains(@"<xs:schema targetNamespace=""http://www.w3.org/2001/XMLSchema"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">", ref schemas); }
public void CanExportTest() { XsdDataContractExporter xdce = new XsdDataContractExporter(); Assert.IsTrue(xdce.CanExport(typeof(int)), "#1"); Assert.IsTrue(xdce.CanExport(typeof(dc)), "#2"); //No DataContract/Serializable etc -> changed in 3.5 Assert.IsTrue(xdce.CanExport(this.GetType()), "#3"); }
public void TypesTest_Negative(Type badType, Type exType, string exMsg = null) { XsdDataContractExporter exporter = new XsdDataContractExporter(); var ex = Assert.Throws(exType, () => exporter.Export(badType)); if (exMsg != null) { Assert.Equal(exMsg, ex.Message); } }
public XmlObjectSerializerAddressHeader(object objectToSerialize, XmlObjectSerializer serializer) { this.serializer = serializer; this.objectToSerialize = objectToSerialize; System.Type type = (objectToSerialize == null) ? typeof(object) : objectToSerialize.GetType(); XmlQualifiedName rootElementName = new XsdDataContractExporter().GetRootElementName(type); this.name = rootElementName.Name; this.ns = rootElementName.Namespace; }
public void KnownTypes_Negative() { XsdDataContractExporter e = new XsdDataContractExporter(); e.Options = new ExportOptions(); e.Options.KnownTypes.Add(null); var ex = Assert.Throws <ArgumentException>(() => e.Export(typeof(Types.Point))); Assert.Equal(@"Cannot export null type provided via KnownTypesCollection.", ex.Message); }