コード例 #1
0
        /// <summary>
        /// Throws an exception if the <see cref="BsipaManifest"/> is not valid.
        /// </summary>
        /// <param name="requiresBsipa"></param>
        /// <exception cref="ManifestValidationException"/>
        /// <exception cref="BsipaDependsOnException"/>
        public void Validate(bool requiresBsipa)
        {
            var nullProps = json.Linq.Where(n =>
                                            n.Value == null || (n.Value.ToString() == string.Empty)).Select(n => n.Key).ToArray();

            foreach (var prop in nullProps)
            {
                json.Remove(prop);
            }
            List <string> invalidProperties = new List <string>();

            if (string.IsNullOrWhiteSpace(Id))
            {
                invalidProperties.Add(nameof(Id));
            }
            if (string.IsNullOrWhiteSpace(Name))
            {
                invalidProperties.Add(nameof(Name));
            }
            if (string.IsNullOrWhiteSpace(Author))
            {
                invalidProperties.Add(nameof(Author));
            }
            if (string.IsNullOrWhiteSpace(Version))
            {
                invalidProperties.Add(nameof(Version));
            }
            if (string.IsNullOrWhiteSpace(GameVersion) && requiresBsipa)
            {
                invalidProperties.Add(nameof(GameVersion));
            }
            if (string.IsNullOrWhiteSpace(GetDescription()))
            {
                invalidProperties.Add(nameof(Description));
            }
            if (requiresBsipa && !(DependsOn?.TryGetValue("BSIPA", out _) ?? false))
            {
                throw new BsipaDependsOnException();
            }
            if (invalidProperties.Count > 0)
            {
                string message;
                if (invalidProperties.Count == 1)
                {
                    message = $"The property '{invalidProperties.First()}' cannot be empty.";
                }
                else
                {
                    message = $"The properties '{string.Join(", ", invalidProperties)}' cannot be empty.";
                }
                throw new ManifestValidationException(message, invalidProperties);
            }
        }