Example #1
0
 protected bool TryReadNullAtTopLevel(XmlReaderDelegator reader)
 {
     Attributes attributes = new Attributes();
     attributes.Read(reader);
     if (attributes.Ref != Globals.NewObjectId)
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.CannotDeserializeRefAtTopLevel, attributes.Ref)));
     if (attributes.XsiNil)
     {
         reader.Skip();
         return true;
     }
     return false;
 }
        internal override void ReadAttributes(XmlReaderDelegator xmlReader)
        {
            if (attributes == null)
                attributes = new Attributes();
            attributes.Reset();

            if (xmlReader.MoveToAttribute(JsonGlobals.typeString) && xmlReader.Value == JsonGlobals.nullString)
            {
                attributes.XsiNil = true;
            }
            else if (xmlReader.MoveToAttribute(JsonGlobals.serverTypeString))
            {
                XmlQualifiedName qualifiedTypeName = JsonReaderDelegator.ParseQualifiedName(xmlReader.Value);
                attributes.XsiTypeName = qualifiedTypeName.Name;

                string serverTypeNamespace = qualifiedTypeName.Namespace;

                if (!string.IsNullOrEmpty(serverTypeNamespace))
                {
                    switch (serverTypeNamespace[0])
                    {
                        case '#':
                            serverTypeNamespace = string.Concat(Globals.DataContractXsdBaseNamespace, serverTypeNamespace.Substring(1));
                            break;
                        case '\\':
                            if (serverTypeNamespace.Length >= 2)
                            {
                                switch (serverTypeNamespace[1])
                                {
                                    case '#':
                                    case '\\':
                                        serverTypeNamespace = serverTypeNamespace.Substring(1);
                                        break;
                                    default:
                                        break;
                                }
                            }
                            break;
                        default:
                            break;
                    }
                }

                attributes.XsiTypeNamespace = serverTypeNamespace;
            }
            xmlReader.MoveToElement();
        }
Example #3
0
 public Attribute(Attributes type)
 {
     Type = type;
     Score = 10;
 }
Example #4
0
 public Attribute(Attributes type, int score)
 {
     Type = type;
     Score = score;
 }
Example #5
0
 internal XmlObjectSerializerReadContext(DataContractSerializer serializer, DataContract rootTypeDataContract, DataContractResolver dataContractResolver)
     : base(serializer, rootTypeDataContract, dataContractResolver)
 {
     this.attributes = new Attributes();
 }
        public void JsonSerialiser_WriteObject_Honours_Important_DataMember_Attributes()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            var obj = new Attributes() {
                OriginalName = worksheet.Int("OriginalName"),
                NoEmitDefaultString = worksheet.EString("NoEmitDefaultString"),
                NoEmitDefaultInt = worksheet.Int("NoEmitDefaultInt"),
                NoEmitDefaultBool = worksheet.Bool("NoEmitDefaultBool"),
                NoEmitDefaultLong = worksheet.Long("NoEmitDefaultLong"),
                NoEmitDefaultDateTime = worksheet.DateTime("NoEmitDefaultDateTime"),
                NoEmitDefaultNullable = worksheet.NBool("NoEmitDefaultNullable"),
            };

            _JsonSerialiser.Initialise(typeof(Attributes));
            _JsonSerialiser.WriteObject(_Stream, obj);

            Assert.AreEqual(worksheet.EString("Json"), GetJson());
        }