Esempio n. 1
0
 protected override bool WriteIdentifiedObject(XmlWriter writer, object obj, XmlIdentificationMode identificationMode, ITypeSerializationInfo info, XmlSerializationContext context)
 {
     if (identificationMode == XmlIdentificationMode.Identifier)
     {
         var model = context.Root as Model;
         if (model != null)
         {
             var modelElement = obj as IModelElement;
             if (modelElement != null)
             {
                 Uri uri;
                 if (modelElement.Model == model)
                 {
                     uri = modelElement.RelativeUri;
                 }
                 else
                 {
                     uri = MakeShortUri(modelElement.AbsoluteUri, model.ModelUri);
                 }
                 if (uri != null)
                 {
                     writer.WriteString(uri.ConvertToString());
                     return(true);
                 }
             }
         }
     }
     return(base.WriteIdentifiedObject(writer, obj, identificationMode, info, context));
 }
Esempio n. 2
0
 protected override bool WriteIdentifiedObject(XmlWriter writer, object obj, XmlIdentificationMode identificationMode, ITypeSerializationInfo info, XmlSerializationContext context)
 {
     if (identificationMode == XmlIdentificationMode.Identifier)
     {
         var model = context.Root as Model;
         if (model != null)
         {
             var modelElement = obj as IModelElement;
             if (modelElement != null)
             {
                 Uri uri;
                 if (modelElement.Model == model)
                 {
                     uri = modelElement.RelativeUri;
                 }
                 else
                 {
                     uri = MakeShortUri(modelElement.AbsoluteUri, model.ModelUri);
                 }
                 if (uri != null)
                 {
                     writer.WriteString(uri.ConvertToString());
                     return true;
                 }
             }
         }
     }
     return base.WriteIdentifiedObject(writer, obj, identificationMode, info, context);
 }
Esempio n. 3
0
 protected override bool WriteIdentifiedObject(XmlWriter writer, object obj, XmlIdentificationMode identificationMode, ITypeSerializationInfo info, XmlSerializationContext context)
 {
     if (identificationMode == XmlIdentificationMode.Identifier)
     {
         var model = context.Root as Model;
         if (model != null)
         {
             var modelElement = obj as IModelElement;
             if (modelElement != null)
             {
                 Uri uri = model.CreateUriForElement(modelElement);
                 if (uri != null)
                 {
                     writer.WriteString(uri.ConvertToString());
                     return(true);
                 }
             }
         }
     }
     return(base.WriteIdentifiedObject(writer, obj, identificationMode, info, context));
 }
Esempio n. 4
0
 public override void Serialize(object obj, XmlWriter writer, IPropertySerializationInfo property, bool writeInstance, XmlIdentificationMode identificationMode, XmlSerializationContext context)
 {
     var modelElement = obj as IModelElement;
     if (modelElement == null)
     {
         base.Serialize(obj, writer, property, writeInstance, identificationMode, context);
     }
     else
     {
         var model = modelElement.Model;
         var modelContext = context as ModelSerializationContext;
         if (modelContext == null || model == modelContext.Model)
         {
             base.Serialize(obj, writer, property, writeInstance, identificationMode, context);
         }
         else
         {
             writer.WriteStartAttribute("href");
             WriteIdentifiedObject(writer, obj, property.IdentificationMode, GetSerializationInfo(obj.GetType(), false), context);
             writer.WriteEndAttribute();
         }
     }
 }
 /// <inheritdoc />
 protected override bool WriteIdentifiedObject(XmlWriter writer, object obj, XmlIdentificationMode identificationMode, ITypeSerializationInfo info, XmlSerializationContext context)
 {
     return(false);
 }
Esempio n. 6
0
        public override void Serialize(object obj, XmlWriter writer, IPropertySerializationInfo property, bool writeInstance, XmlIdentificationMode identificationMode, XmlSerializationContext context)
        {
            var modelElement         = obj as IModelElement;
            var useBaseSerialization = true;

            if (modelElement != null)
            {
                var modelSerializationContext = context as ModelSerializationContext;
                if (modelSerializationContext != null && modelSerializationContext.Model != null)
                {
                    useBaseSerialization = !modelSerializationContext.Model.SerializeAsReference(modelElement);
                }
            }
            if (useBaseSerialization)
            {
                base.Serialize(obj, writer, property, writeInstance, identificationMode, context);
            }
            else
            {
                writer.WriteStartAttribute("href");
                WriteIdentifiedObject(writer, obj, XmlIdentificationMode.Identifier, GetSerializationInfo(obj.GetType(), false), context);
                writer.WriteEndAttribute();
            }
        }
Esempio n. 7
0
 protected override bool WriteIdentifiedObject(XmlWriter writer, object obj, XmlIdentificationMode identificationMode, ITypeSerializationInfo info, XmlSerializationContext context)
 {
     return false;
 }
Esempio n. 8
0
        public override void Serialize(object obj, XmlWriter writer, IPropertySerializationInfo property, bool writeInstance, XmlIdentificationMode identificationMode, XmlSerializationContext context)
        {
            var modelElement = obj as IModelElement;

            if (modelElement == null)
            {
                base.Serialize(obj, writer, property, writeInstance, identificationMode, context);
            }
            else
            {
                var model        = modelElement.Model;
                var modelContext = context as ModelSerializationContext;
                if (modelContext == null || model == modelContext.Model)
                {
                    base.Serialize(obj, writer, property, writeInstance, identificationMode, context);
                }
                else
                {
                    writer.WriteStartAttribute("href");
                    WriteIdentifiedObject(writer, obj, property.IdentificationMode, GetSerializationInfo(obj.GetType(), false), context);
                    writer.WriteEndAttribute();
                }
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Creates a new XmlIdentificationModeAttribute with the given identification mode
 /// </summary>
 /// <param name="positionalString">The mode for identification</param>
 public XmlIdentificationModeAttribute(XmlIdentificationMode mode)
 {
     this.mode = mode;
 }
 /// <summary>
 /// Creates a new XmlIdentificationModeAttribute with the given identification mode
 /// </summary>
 /// <param name="positionalString">The mode for identification</param>
 public XmlIdentificationModeAttribute(XmlIdentificationMode mode)
 {
     this.mode = mode;
 }