public void TestClassAttributeSort() { var builder = new TypeMetadataBuilder <object>(); var attrBuilder = builder.NewAttribute(); IAttributeMetadata <object>[] expected = new IAttributeMetadata <object>[] { attrBuilder.SetVersion(0).SetIndex(0).SetName("c").Build(), attrBuilder.SetVersion(0).SetIndex(1).SetName("a").Build(), attrBuilder.SetVersion(0).SetIndex(2).SetName("b").Build(), attrBuilder.SetVersion(1).SetIndex(3).SetName("e").Build(), attrBuilder.SetVersion(1).SetIndex(-1).SetName("d").Build(), attrBuilder.SetVersion(1).SetIndex(-1).SetName("f").Build() }; builder.AddAttribute(expected[3]); builder.AddAttribute(expected[1]); builder.AddAttribute(expected[5]); builder.AddAttribute(expected[0]); builder.AddAttribute(expected[4]); builder.AddAttribute(expected[2]); TypeMetadata <object> cmd = builder.Build(); Assert.AreEqual(0, cmd.GetAttribute("c").Index); Assert.AreEqual(1, cmd.GetAttribute("a").Index); Assert.AreEqual(2, cmd.GetAttribute("b").Index); Assert.AreEqual(3, cmd.GetAttribute("e").Index); Assert.AreEqual(4, cmd.GetAttribute("d").Index); Assert.AreEqual(5, cmd.GetAttribute("f").Index); }
/// <summary> /// Serialize a user type instance to a POF stream by writing its /// state using the specified <see cref="IPofWriter"/> object. /// </summary> /// <remarks> /// An implementation of <b>IPofSerializer</b> is required to follow /// the following steps in sequence for writing out an object of a /// user type: /// <list type="number"> /// <item> /// <description> /// If the object is evolvable, the implementation must set the /// version by calling <see cref="IPofWriter.VersionId"/>. /// </description> /// </item> /// <item> /// <description> /// The implementation may write any combination of the properties of /// the user type by using the "write" methods of the /// <b>IPofWriter</b>, but it must do so in the order of the property /// indexes. /// </description> /// </item> /// <item> /// <description> /// After all desired properties of the user type have been written, /// the implementation must terminate the writing of the user type by /// calling <see cref="IPofWriter.WriteRemainder"/>. /// </description> /// </item> /// </list> /// </remarks> /// <param name="writer"> /// The <b>IPofWriter</b> with which to write the object's state. /// </param> /// <param name="o"> /// The object to serialize. /// </param> /// <exception cref="IOException"> /// If an I/O error occurs. /// </exception> public virtual void Serialize(IPofWriter writer, object o) { // set the version identifier bool isEvolvable = o is IEvolvable; IEvolvable evolvable = null; if (isEvolvable) { evolvable = (IEvolvable)o; writer.VersionId = Math.Max(evolvable.DataVersion, evolvable.ImplVersion); } // POF Annotation processing for (IEnumerator enmr = m_tmd.GetAttributes(); enmr.MoveNext();) { IAttributeMetadata <object> attr = (IAttributeMetadata <object>)enmr.Current; attr.Codec.Encode(writer, attr.Index, attr.Get(o)); } // write out any future properties Binary remainder = null; if (isEvolvable) { remainder = evolvable.FutureData; } writer.WriteRemainder(remainder); }
/// <summary> /// Deserialize a user type instance from a POF stream by reading its /// state using the specified <see cref="IPofReader"/> object. /// </summary> /// <remarks> /// An implementation of <b>IPofSerializer</b> is required to follow /// the following steps in sequence for reading in an object of a /// user type: /// <list type="number"> /// <item> /// <description> /// If the object is evolvable, the implementation must get the /// version by calling <see cref="IPofWriter.VersionId"/>. /// </description> /// </item> /// <item> /// <description> /// The implementation may read any combination of the /// properties of the user type by using "read" methods of the /// <b>IPofReader</b>, but it must do so in the order of the property /// indexes. /// </description> /// </item> /// <item> /// <description> /// After all desired properties of the user type have been read, /// the implementation must terminate the reading of the user type by /// calling <see cref="IPofReader.ReadRemainder"/>. /// </description> /// </item> /// </list> /// </remarks> /// <param name="reader"> /// The <b>IPofReader</b> with which to read the object's state. /// </param> /// <returns> /// The deserialized user type instance. /// </returns> /// <exception cref="IOException"> /// If an I/O error occurs. /// </exception> public virtual object Deserialize(IPofReader reader) { ITypeMetadata <object> tmd = m_tmd; object value = tmd.NewInstance(); // set the version identifier bool isEvolvable = value is IEvolvable; IEvolvable evolvable = null; if (isEvolvable) { evolvable = (IEvolvable)value; evolvable.DataVersion = reader.VersionId; } // POF Annotation processing for (IEnumerator enmr = tmd.GetAttributes(); enmr.MoveNext();) { IAttributeMetadata <object> attr = (IAttributeMetadata <object>)enmr.Current; attr.Set(value, attr.Codec.Decode(reader, attr.Index)); } // read any future properties Binary remainder = reader.ReadRemainder(); if (isEvolvable) { evolvable.FutureData = remainder; } return(value); }
/// <summary> /// Compares the current object with another object of the same type. /// </summary> /// <remarks> /// Sorting of attributes is determined by: /// <list type="number"> /// <item>version</item> /// <item>index</item> /// <item>name</item> /// </list> /// </remarks> /// <returns> /// A 32-bit signed integer that indicates the relative order of /// the objects being compared. The return value has the /// following meanings: Value Meaning Less than zero This object /// is less than the <paramref name="that"/> parameter.Zero This /// object is equal to <paramref name="that"/>. Greater than /// zero This object is greater than <paramref name="that"/>. /// </returns> /// <param name="that"> /// An object to compare with this object. /// </param> public virtual int CompareTo(IAttributeMetadata <T> that) { if (that == null) { return(1); } if (that == this) { return(0); } int n = VersionId - that.VersionId; if (n == 0) { n = Index - that.Index; if (n == 0) { string thisName = Name; string thatName = that.Name; n = thisName == null ? (thatName == null ? 0 : -1) : (thatName == null ? 1 : thisName.CompareTo(thatName)); } } return(n); }
/// <summary> /// Compare this TypeAttribute with another object to determine /// equality. /// </summary> /// <remarks> /// Two TypeAttribute objects are considered equal iff their /// <see cref="Name"/>, <see cref="Index"/> and /// <see cref="VersionId"/> are equal. /// </remarks> /// <param name="that"> /// IAttributeMetadata instance to compare this instance to. /// </param> /// <returns> /// <c>true</c> iff this TypeAttribute and the passed object are equivalent. /// </returns> public virtual bool Equals(IAttributeMetadata <T> that) { if (this == that) { return(true); } return(Equals(VersionId, that.VersionId) && Equals(Index, that.Index) && Equals(Name, that.Name)); }
/// <summary> /// Add an attribute to this TypeMetadata. /// </summary> /// <param name="attribute"> /// Attribute metadata definition to add. /// </param> /// <returns> /// Whether the attribute metadata was added. /// </returns> public virtual bool AddAttribute(IAttributeMetadata <T> attribute) { var typeAttributes = m_attributes; bool add = !typeAttributes.Contains(attribute); if (add) { typeAttributes.Add(attribute); m_attributesByName[attribute.Name] = attribute; } return(add); }
private AttributeImpl(IAttributeMetadata metadata, Item parent) { this.metadata = metadata; this.Parent = parent; }
public SerializationAttributeMetadata(IAttributeMetadata attributeMetadata) { Name = attributeMetadata.Name; SavedHash = attributeMetadata.SavedHash; }
private AttributeImpl(IAttributeMetadata metadata, Item parent) { _metadata = metadata; Parent = parent; }
public AttributeMetadata(IAttributeMetadata attributeMetadata) { Name = attributeMetadata.Name; SavedHash = attributeMetadata.SavedHash; }
private AttributeImpl(IAttributeMetadata metadata, Object parent) { _metadata = metadata; Parent = parent; }
/// <summary> /// Add an <see cref="IAttributeMetadata{PT}"/> instance that is a /// child of the <see cref="ITypeMetadata{T}"/> instance. /// </summary> /// <param name="attribute"> /// <see cref="IAttributeMetadata{PT}"/> implementation to add to the /// enclosing <see cref="ITypeMetadata{T}"/> instance. /// </param> /// <returns> /// A reference to this for chained set calls. /// </returns> /// <seealso cref="Tangosol.IO.Pof.Reflection.Internal.TypeMetadata{T}.AddAttribute"/> public virtual TypeMetadataBuilder <T> AddAttribute(IAttributeMetadata <T> attribute) { m_cmd.AddAttribute(attribute); return(this); }