var cns = GetCodeNamespace (qname.Namespace);
var td = new CodeTypeDeclaration () {
Name = GetUniqueName (CodeIdentifier.MakeValid (qname.Name), cns),
- TypeAttributes = GenerateInternal ? TypeAttributes.NotPublic : TypeAttributes.Public };
+ TypeAttributes = GenerateInternal ? TypeAttributes.NotPublic : TypeAttributes.Public,
+ IsPartial = true };
cns.Types.Add (td);
td.BaseTypes.Add (new CodeTypeReference (typeof (IXmlSerializable)));
if (!schemas.IsCompiled)
schemas.Compile ();
- return CanImport (schemas, element.ElementSchemaType as XmlSchemaType);
+ if (element.ElementSchemaType != null)
+ return CanImport (schemas, element.ElementSchemaType as XmlSchemaType);
+ else if (element.SchemaTypeName != null && !element.SchemaTypeName.Equals (QName.Empty))
+ return CanImport (schemas, element.SchemaTypeName);
+ else
+ // anyType
+ return true;
}
if (typeName == null)
throw new ArgumentNullException ("typeName");
+ if (!schemas.IsCompiled)
+ schemas.Compile ();
+
if (IsPredefinedType (typeName))
return;
var elname = element.QualifiedName;
+ if (IsPredefinedType (element.SchemaTypeName))
+ return elname;
+
switch (elname.Namespace) {
case KnownTypeCollection.MSSimpleNamespace:
switch (elname.Name) {
}
// FIXME: use element to fill nillable and arrays.
- var qname = element.SchemaType != null ? element.QualifiedName : element.ElementSchemaType.QualifiedName;
- Import (schemas, element.ElementSchemaType, qname);
+ var qname =
+ elname != null && !elname.Equals (QName.Empty) ? elname :
+ element.ElementSchemaType != null ? element.ElementSchemaType.QualifiedName :
+ qname_anytype;
+
+ if (element.ElementSchemaType != null)
+ Import (schemas, element.ElementSchemaType, qname);
+ else if (element.SchemaTypeName != null && !element.SchemaTypeName.Equals (QName.Empty))
+ Import (schemas, schemas.GlobalTypes [element.SchemaTypeName] as XmlSchemaType, qname);
+ // otherwise it is typeless == anyType.
+ else
+ Import (schemas, XmlSchemaType.GetBuiltInComplexType (qname_anytype), qname);
+
return qname;
}
var td = new CodeTypeDeclaration () {
Name = GetUniqueName (CodeIdentifier.MakeValid (qname.Name), cns),
- TypeAttributes = GenerateInternal ? TypeAttributes.NotPublic : TypeAttributes.Public };
+ TypeAttributes = GenerateInternal ? TypeAttributes.NotPublic : TypeAttributes.Public,
+ IsPartial = true };
cns.Types.Add (td);
var info = new TypeImportInfo () { ClrType = clrRef, XsdType = type, XsdTypeName = qname };
bool IsPredefinedType (XmlQualifiedName qname)
{
+ if (qname == null)
+ return false;
switch (qname.Namespace) {
case KnownTypeCollection.MSSimpleNamespace:
return KnownTypeCollection.GetPrimitiveTypeFromName (qname) != null;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel.Description;
using System.Xml;
if (section.Metadata is XmlSchema)
xss.Add (section.Metadata as XmlSchema);
+ Assert.AreEqual (3, xss.Schemas ().Count, "#1");
return xss;
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
- [Category ("NotWorking")]
public void GetCodeTypeReferenceTest ()
{
XsdDataContractImporter xsdi = GetImporter ();
}
[Test]
- [Category ("NotWorking")]
public void GetCodeTypeReferenceTest2 ()
{
NewXmlSchemaSet ();
}
[Test]
- [Category ("NotWorking")]
public void ImportDataContract1 ()
{
NewXmlSchemaSet ();
}
[Test]
- [Category ("NotWorking")]
public void ImportDataContract2 ()
{
NewXmlSchemaSet ();
[Test]
[ExpectedException (typeof (InvalidDataContractException))]
- [Category ("NotWorking")]
public void ImportMessageEcho ()
{
XsdDataContractImporter xsdi = GetImporter ();
private void CheckDataContractAttribute (CodeTypeDeclaration type, string msg)
{
- Assert.AreEqual (3, type.CustomAttributes.Count, msg + "a");
+ // DebuggerStepThrouAttribute is insignificant. So, no reason to check the attribute count.
+ // Assert.AreEqual (3, type.CustomAttributes.Count, msg + "a");
// DebuggerStepThroughAttribute - skip it
//GeneratedCodeAttribute
- CodeAttributeDeclaration ca = type.CustomAttributes [1];
- Assert.AreEqual ("System.CodeDom.Compiler.GeneratedCodeAttribute", ca.Name, msg + "b");
+ var l = new List<CodeAttributeDeclaration> ();
+ foreach (CodeAttributeDeclaration a in type.CustomAttributes)
+ l.Add (a);
+ Assert.IsTrue (l.Any (a => a.Name == "System.CodeDom.Compiler.GeneratedCodeAttribute"), msg + "b");
- ca = type.CustomAttributes [2];
- Assert.AreEqual ("System.Runtime.Serialization.DataContractAttribute", ca.Name, msg + "c");
+ var ca = l.FirstOrDefault (a => a.Name == "System.Runtime.Serialization.DataContractAttribute");
+ Assert.IsNotNull (ca, msg + "b");
Assert.AreEqual (2, ca.Arguments.Count, msg + "d");
}