/// <summary> /// Creates a structurally equivalent 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 IStonType Copy(IStonType type) { if (type == null) { throw new ArgumentNullException("type"); } if (type is IStonNamedType) { return(StonNamedType.Copy(type as IStonNamedType)); } if (type is IStonCollectionType) { return(StonCollectionType.Copy(type as IStonCollectionType)); } if (type is IStonUnionType) { return(StonUnionType.Copy(type as IStonUnionType)); } throw new StonImplementationException(type.GetType(), typeof(IStonType), typeof(IStonNamedType), typeof(IStonCollectionType), typeof(IStonUnionType)); }
/// <summary> /// Checks the validity of a given STON type. /// </summary> /// <param name="type">The type to check the validity of.</param> public static void ValidateType(IStonType type) { if (type == null) { throw new ArgumentNullException("type"); } else if (type is IStonNamedType) { ValidateType(type as IStonNamedType); } else if (type is IStonCollectionType) { ValidateType(type as IStonCollectionType); } else if (type is IStonUnionType) { ValidateType(type as IStonUnionType); } else { throw new StonImplementationException(type.GetType(), typeof(IStonType), typeof(IStonNamedType), typeof(IStonCollectionType), typeof(IStonUnionType)); } }
// writes any type private void WriteType(StonTokenWriter writer, IStonType type) { if (type == null) { throw new StonException("A non-existing type has been found in the structure to be written."); } else if (type is IStonNamedType) { WriteType(writer, type as IStonNamedType); } else if (type is IStonCollectionType) { WriteType(writer, type as IStonCollectionType); } else if (type is IStonUnionType) { WriteType(writer, type as IStonUnionType); } else { throw new StonImplementationException(type.GetType(), typeof(IStonType), typeof(IStonNamedType), typeof(IStonCollectionType), typeof(IStonUnionType)); } }