示例#1
0
 /// <summary>
 /// Creates a structurally equivalent complex-valued entity from a given entity.
 /// </summary>
 /// <param name="entity">The entity to copy the structure of.</param>
 /// <returns>A structurally equivalent copy of the given entity.</returns>
 public static IStonComplexEntity Copy(IStonComplexEntity entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException("entity");
     }
     return(new StonComplexEntity(entity));
 }
示例#2
0
 /// <summary>
 /// Returns a hash code for a given complex-valued entity, applied to entities semantic equivalence.
 /// Among complex entities, it is the same as reference equality.
 /// </summary>
 /// <param name="obj">The complex-valued entity to get a hash code of.</param>
 /// <returns>The hash code for the entity.</returns>
 public int GetHashCode(IStonComplexEntity obj)
 {
     if (obj == null)
     {
         return(0);
     }
     return(System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(obj));
 }
示例#3
0
        // writes a complex valued entity
        private void WriteEntity(StonTokenWriter writer, IStonComplexEntity entity)
        {
            WriteGlobalIdentifier(writer, entity.GlobalIdentifier);
            WriteTypeDefinition(writer, entity.Type);

            WriteConstruction(writer, entity.Construction);
            WriteMemberInit(writer, entity.MemberInit);
            WriteCollectionInit(writer, entity.CollectionInit);
        }
示例#4
0
        // initializes an object using a corresponding STON value
        private static void InitializeFromSton(object obj, IStonDocument document, IStonComplexEntity entity, IDictionary <IStonValuedEntity, object> builtObjects)
        {
            switch (obj)
            {
            case IPlaylistItem item:
                InitializeFromSton(item, document, entity, builtObjects);
                break;

            case IStreamProvider provider:
                InitializeFromSton(provider, document, entity, builtObjects);
                break;
            }
        }
示例#5
0
        /// <summary>
        /// Checks a validity of a given STON complex-valued entity.
        /// The validation does not include check for duplicate members, as that might require resolving references in a STON document.
        /// </summary>
        /// <param name="entity">The entity to check the validity of.</param>
        public static void ValidateEntity(IStonComplexEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            try
            {
                if (entity.GlobalIdentifier != null)
                {
                    ValidateGlobalIdentifier(entity.GlobalIdentifier);
                }
                if (entity.Type != null)
                {
                    ValidateType(entity.Type);
                }

                if (entity.Construction == null && entity.MemberInit == null && entity.CollectionInit == null)
                {
                    throw new StonException("A complex-valued entity must have a construction, a member initialization or a collection initialization component.");
                }
                if (entity.Construction != null)
                {
                    ValidateConstruction(entity.Construction);
                }
                if (entity.MemberInit != null)
                {
                    ValidateMemberInit(entity.MemberInit);
                }
                if (entity.CollectionInit != null)
                {
                    ValidateCollectionInit(entity.CollectionInit);
                }
            }
            catch (StonException ex)
            {
                throw new StonValueException(entity, ex.Message);
            }
        }
示例#6
0
 /// <summary>
 /// Creates a structurally equivalent complex-valued entity from a given entity.
 /// </summary>
 /// <param name="entity">The entity to copy the structure of.</param>
 public StonComplexEntity(IStonComplexEntity entity)
     : this(entity.Construction, entity.MemberInit, entity.CollectionInit, entity.Type, entity.GlobalIdentifier)
 {
 }
示例#7
0
 /// <summary>
 /// Determines whether two complex-valued entities are semantically equivalent.
 /// For two complex entities, it is the same as reference equality.
 /// </summary>
 /// <param name="x">The first complex-valued entity to compare.</param>
 /// <param name="y">The second complex-valued entity to compare.</param>
 /// <returns>True when entities are semantically equivalent, false otherwise.</returns>
 public bool Equals(IStonComplexEntity x, IStonComplexEntity y)
 {
     return(ReferenceEquals(x, y));
 }
示例#8
0
 // initializes a stream provider using a corresponding STON value
 private static void InitializeFromSton(IStreamProvider provider, IStonDocument document, IStonComplexEntity entity, IDictionary <IStonValuedEntity, object> builtObjects)
 {
     if (provider is LoopStreamProvider)
     {
         var loop = provider as LoopStreamProvider;
         loop.TrackStart      = FromSton <long?>(document, GetValue(document, document.GetMember(entity, new StonBindingName("TrackStart"))), builtObjects) ?? -1;
         loop.StreamLoopStart = FromSton <long?>(document, GetValue(document, document.GetMember(entity, new StonBindingName("LoopStart"))), builtObjects) ?? -1;
         loop.StreamLoopEnd   = FromSton <long?>(document, GetValue(document, document.GetMember(entity, new StonBindingName("LoopEnd"))), builtObjects) ?? -1;
         loop.TrackEnd        = FromSton <long?>(document, GetValue(document, document.GetMember(entity, new StonBindingName("TrackEnd"))), builtObjects) ?? -1;
         loop.Loops           = FromSton <int?>(document, GetValue(document, document.GetMember(entity, new StonBindingName("Loops"))), builtObjects) ?? -1;
     }
 }
示例#9
0
        // initializes a playlist item using a corresponding STON value
        private static void InitializeFromSton(IPlaylistItem item, IStonDocument document, IStonComplexEntity entity, IDictionary <IStonValuedEntity, object> builtObjects)
        {
            item.Name = FromSton <string>(document, GetValue(document, document.GetMember(entity, new StonBindingName("Name"))), builtObjects) ?? item.GetType().Name;

            // playlist never declares its path explicitly
            // in general, it should be based on the playlist location instead
            if (!(item is Playlist))
            {
                item.Path = FromSton <string>(document, GetValue(document, document.GetMember(entity, new StonBindingName("Path"))), builtObjects) ?? "";
            }

            // loading subitems of a container
            if (item is IPlaylistContainer)
            {
                var container = item as IPlaylistContainer;
                foreach (var subitemData in entity.CollectionInit.Elements)
                {
                    var subitem = FromSton <IPlaylistItem>(document, GetValue(document, subitemData), builtObjects);
                    container.Add(subitem);
                }
            }

            // loading the loop provider of a playlist
            if (item is Track)
            {
                (item as Track).StreamProvider = FromSton <IStreamProvider>(document, GetValue(document, document.GetMember(entity, new StonBindingName("Stream"))), builtObjects);
            }
        }