System.IO.Packaging.Check.ContentTypeIsValid C# (CSharp) Méthode

ContentTypeIsValid() public static méthode

public static ContentTypeIsValid ( string contentType ) : void
contentType string
Résultat void
        public static void ContentTypeIsValid(string contentType)
        {
            if (string.IsNullOrEmpty(contentType))
                return;

            // Must be in form of: type/subtype
            int index = contentType.IndexOf('/');
            bool result = (index > 0) && contentType.Length > (index + 1) && contentType.IndexOf('/', index + 1) == -1;

            if (!result)
                throw new ArgumentException("contentType", "contentType must be in the form of 'type/subtype'");
        }

Usage Example

        protected internal PackagePart(Package package, Uri partUri, string contentType, CompressionOption compressionOption)
        {
            Check.Package(package);
            Check.PartUri(partUri);
            Check.ContentTypeIsValid(contentType);

            Package              = package;
            Uri                  = partUri;
            ContentType          = contentType;
            CompressionOption    = compressionOption;
            RelationshipsPartUri = PackUriHelper.GetRelationshipPartUri(Uri);
        }
All Usage Examples Of System.IO.Packaging.Check::ContentTypeIsValid