Ejemplo n.º 1
0
 /// <summary>
 /// Creates a structurally equivalent named type from a given type.
 /// </summary>
 /// <param name="type">The type to copy the structure of.</param>
 /// <returns>A structurally equivalent copy of the given type.</returns>
 public static IStonNamedType Copy(IStonNamedType type)
 {
     if (type == null)
     {
         throw new ArgumentNullException("type");
     }
     return(new StonNamedType(type));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Determines whether two named types are equivalent.
        /// </summary>
        /// <param name="x">The first named type to compare.</param>
        /// <param name="y">The second named type to compare.</param>
        /// <returns>True when types are equivalent, false otherwise.</returns>
        public bool Equals(IStonNamedType x, IStonNamedType y)
        {
            if (x == y)
            {
                return(true);
            }
            else if (x == null || y == null)
            {
                return(false);
            }

            return(x.IsExtension == y.IsExtension && x.Name == y.Name && x.TypeParameters.SequenceEqual(y.TypeParameters, this));
        }
Ejemplo n.º 3
0
        // writes a named type
        private void WriteType(StonTokenWriter writer, IStonNamedType type)
        {
            if (type.TypeParameters == null)
            {
                throw new StonException("A named type cannot have a non-existing type parameters collection.");
            }

            if (type.IsExtension)
            {
                writer.Write('!');
            }
            WriteStringLiteral(writer, type.Name);
            if (type.TypeParameters.Any())
            {
                writer.Write('<');
                WriteSequence(writer, type.TypeParameters, WriteType);
                writer.Write('>');
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns a hash code for a given named type.
        /// </summary>
        /// <param name="obj">The named type to get a hash code of.</param>
        /// <returns>The hash code for the type.</returns>
        public int GetHashCode(IStonNamedType obj)
        {
            if (obj == null)
            {
                return(0);
            }

            unchecked
            {
                int result = obj.IsExtension ? 19 : 23;
                result = result * 31 + obj.Name.GetHashCode();
                foreach (var parameter in obj.TypeParameters)
                {
                    result = result * 31 + GetHashCode(parameter);
                }

                return(result);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Checks the validity of a given STON named type.
 /// </summary>
 /// <param name="type">The named type to check the validity of.</param>
 public static void ValidateType(IStonNamedType type)
 {
     if (type == null)
     {
         throw new ArgumentNullException("type");
     }
     if (type.Name == null)
     {
         throw new StonException("A named type cannot have a non-existing name.");
     }
     if (type.TypeParameters == null)
     {
         throw new StonException("A named type cannot have a non-existing type parameters collection.");
     }
     foreach (var parameter in type.TypeParameters)
     {
         if (parameter == null)
         {
             throw new StonException("A named type cannot have a non-existing type parameter.");
         }
         ValidateType(parameter);
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Creates a structurally equivalent named type from a given type.
 /// </summary>
 /// <param name="type">The type to copy the structure of.</param>
 public StonNamedType(IStonNamedType type)
     : this(type.Name, type.TypeParameters, type.IsExtension)
 {
 }