Example #1
0
 /// <summary>
 /// Construct a ClassAttributeBuilder instance.
 /// </summary>
 public ClassAttributeBuilder()
 {
     m_attribute = new TypeMetadata <T> .TypeAttribute();
 }
Example #2
0
 /// <summary>
 /// Constructs a new TypeMetadataBuilder.
 /// </summary>
 public TypeMetadataBuilder()
 {
     m_cmd     = new TypeMetadata <T>();
     m_cmd.Key = m_key = new TypeMetadata <T> .TypeKey();
 }
Example #3
0
        /// <summary>
        /// Based on the state that the builder has been informed of create
        /// and return a <see cref="ITypeMetadata{T}"/> instance.
        /// </summary>
        /// <returns>
        /// The built <see cref="ITypeMetadata{T}"/> instance.
        /// </returns>
        public virtual TypeMetadata <T> Build()
        {
            var cmd = m_cmd;
            var key = (TypeMetadata <T> .TypeKey)cmd.Key;

            // now that we are aware of entirety of this TypeMetadata instance
            // determine the appropriate indexes or ensure they are explicitly
            // defined
            IList <IAttributeMetadata <T> > nonSortedAttributes = new List <IAttributeMetadata <T> >();

            // create an exclusion list of indexes that are explicitly defined, i.e.
            // we must be aware of the obstacles on the road to determining POF binary
            // structure
            ICollection <int> reservedIndexes = new HashSet <int>();

            for (IEnumerator enmrAttr = cmd.GetAttributes(); enmrAttr.MoveNext();)
            {
                var attr = (TypeMetadata <T> .TypeAttribute)enmrAttr.Current;
                if (attr.Index >= 0)
                {
                    int proposedIndex, attributeIndex = proposedIndex = attr.Index;
                    while (reservedIndexes.Contains(proposedIndex))
                    {
                        ++proposedIndex;
                    }

                    if (proposedIndex != attributeIndex)
                    {
                        if (CacheFactory.IsLogEnabled(CacheFactory.LogLevel.Debug))
                        {
                            CacheFactory.Log("The requested index " + attributeIndex
                                             + " on a PortableProperty annotation "
                                             + "for [typeId=" + key.TypeId
                                             + ", version=" + key.VersionId
                                             + ", property-name=" + attr.Name
                                             + "] is already allocated to an existing PortableProperty. "
                                             + "Allocated index " + proposedIndex + " instead.",
                                             CacheFactory.LogLevel.Debug);
                        }
                        attr.Index = proposedIndex;
                    }
                    reservedIndexes.Add(proposedIndex);
                }
            }

            int i = 0;

            for (IEnumerator attributes = cmd.GetAttributes(); attributes.MoveNext(); ++i)
            {
                var attr = (TypeMetadata <T> .TypeAttribute)attributes.Current;
                if (attr.Index < 0)
                {
                    for (; reservedIndexes.Contains(i); ++i)
                    {
                    }
                    attr.Index = i;
                }
                nonSortedAttributes.Add(attr);
            }
            cmd.SetAttributes(nonSortedAttributes);

            // inform key of the hash of the class structure now that we are primed
            key.Hash = cmd.GetHashCode();

            m_cmd     = new TypeMetadata <T>();
            m_cmd.Key = m_key = new TypeMetadata <T> .TypeKey();

            return(cmd);
        }