Exemple #1
0
 /// <summary>
 /// Serves as a hash function for a particular type.
 /// </summary>
 /// <returns>
 /// A hash code for the current <see cref="T:System.Object"/>.
 /// </returns>
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Type.GetHashCode();
         hashCode = (hashCode * 397) ^ (Id?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Schema?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Comment?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Title?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Description?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Default?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ MultipleOf.GetHashCode();
         hashCode = (hashCode * 397) ^ Maximum.GetHashCode();
         hashCode = (hashCode * 397) ^ ExclusiveMaximum.GetHashCode();
         hashCode = (hashCode * 397) ^ Minimum.GetHashCode();
         hashCode = (hashCode * 397) ^ ExclusiveMinimum.GetHashCode();
         hashCode = (hashCode * 397) ^ (MaxLength?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (MinLength?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Pattern?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (AdditionalItems?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Items?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (MaxItems?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (MinItems?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (UniqueItems?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Contains?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (AdditionalProperties?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Definitions?.GetCollectionHashCode().GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Properties?.GetCollectionHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (PatternProperties?.GetCollectionHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Dependencies?.GetCollectionHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Const?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Enum?.GetCollectionHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Format?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (ContentMediaType?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (ContentEncoding?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (If?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Then?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Else?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (AllOf?.GetCollectionHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (AnyOf?.GetCollectionHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (OneOf?.GetCollectionHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Not?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Required?.GetCollectionHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Examples?.GetCollectionHashCode() ?? 0);
         return(hashCode);
     }
 }
        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <returns>
        /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
        /// </returns>
        /// <param name="other">An object to compare with this object.</param>
        public virtual bool Equals(IJsonSchema other)
        {
            var schema = other as JsonSchema04;

            if (ReferenceEquals(null, schema))
            {
                return(false);
            }
            if (ReferenceEquals(this, schema))
            {
                return(true);
            }
            if (Id != schema.Id)
            {
                return(false);
            }
            if (Schema != schema.Schema)
            {
                return(false);
            }
            if (Title != schema.Title)
            {
                return(false);
            }
            if (Description != schema.Description)
            {
                return(false);
            }
            if (!Equals(Default, schema.Default))
            {
                return(false);
            }
            if (MultipleOf != schema.MultipleOf)
            {
                return(false);
            }
            if (Maximum != schema.Maximum)
            {
                return(false);
            }
            if (ExclusiveMaximum != schema.ExclusiveMaximum)
            {
                return(false);
            }
            if (Minimum != schema.Minimum)
            {
                return(false);
            }
            if (ExclusiveMinimum != schema.ExclusiveMinimum)
            {
                return(false);
            }
            if (MaxLength != schema.MaxLength)
            {
                return(false);
            }
            if (MinLength != schema.MinLength)
            {
                return(false);
            }
            if (Pattern != schema.Pattern)
            {
                return(false);
            }
            if (!Equals(AdditionalItems, schema.AdditionalItems))
            {
                return(false);
            }
            if (!Equals(Items, schema.Items))
            {
                return(false);
            }
            if (MaxItems != schema.MaxItems)
            {
                return(false);
            }
            if (MinItems != schema.MinItems)
            {
                return(false);
            }
            if (UniqueItems != schema.UniqueItems)
            {
                return(false);
            }
            if (!Equals(AdditionalProperties, schema.AdditionalProperties))
            {
                return(false);
            }
            if (!Definitions.ContentsEqual(schema.Definitions))
            {
                return(false);
            }
            if (!Properties.ContentsEqual(schema.Properties))
            {
                return(false);
            }
            if (!PatternProperties.ContentsEqual(PatternProperties))
            {
                return(false);
            }
            if (!Dependencies.ContentsEqual(schema.Dependencies))
            {
                return(false);
            }
            if (!Enum.ContentsEqual(schema.Enum))
            {
                return(false);
            }
            if (!Equals(Type, schema.Type))
            {
                return(false);
            }
            if (!AllOf.ContentsEqual(schema.AllOf))
            {
                return(false);
            }
            if (!AnyOf.ContentsEqual(schema.AnyOf))
            {
                return(false);
            }
            if (!OneOf.ContentsEqual(schema.OneOf))
            {
                return(false);
            }
            if (!Equals(Not, schema.Not))
            {
                return(false);
            }
            if (!Equals(Format, schema.Format))
            {
                return(false);
            }
            if (!Required.ContentsEqual(schema.Required))
            {
                return(false);
            }
            return(Dependencies.ContentsEqual(schema.Dependencies));
        }
        /// <summary>
        /// Converts an object to a <see cref="JsonValue"/>.
        /// </summary>
        /// <param name="serializer">The <see cref="JsonSerializer"/> instance to use for additional serialization of values.</param>
        /// <returns>The <see cref="JsonValue"/> representation of the object.</returns>
        public virtual JsonValue ToJson(JsonSerializer serializer)
        {
            var json = new JsonObject();

            if (Id != null)
            {
                json["id"] = Id;
            }
            if (!string.IsNullOrWhiteSpace(Schema))
            {
                json["$schema"] = Schema;
            }
            if (Title != null)
            {
                json["title"] = Title;
            }
            if (!string.IsNullOrWhiteSpace(Description))
            {
                json["description"] = Description;
            }
            if (Default != null)
            {
                json["default"] = Default;
            }
            if (MultipleOf.HasValue)
            {
                json["multipleOf"] = MultipleOf;
            }
            if (Maximum.HasValue)
            {
                json["maximum"] = Maximum;
            }
            if (ExclusiveMaximum.HasValue)
            {
                json["exclusiveMaximum"] = ExclusiveMaximum;
            }
            if (Minimum.HasValue)
            {
                json["minimum"] = Minimum;
            }
            if (ExclusiveMinimum.HasValue)
            {
                json["exclusiveMinimum"] = ExclusiveMinimum;
            }
            if (MaxLength.HasValue)
            {
                json["maxLength"] = MaxLength;
            }
            if (MinLength.HasValue)
            {
                json["minLength"] = MinLength;
            }
            if (Pattern != null)
            {
                json["pattern"] = Pattern;
            }
            if (AdditionalItems != null)
            {
                json["additionalItems"] = AdditionalItems.ToJson(serializer);
            }
            if (Items != null)
            {
                json["items"] = Items.ToJson(serializer);
            }
            if (MaxItems.HasValue)
            {
                json["maxItems"] = MinItems;
            }
            if (MinItems.HasValue)
            {
                json["minItems"] = MinItems;
            }
            if (UniqueItems ?? false)
            {
                json["uniqueItems"] = UniqueItems;
            }
            if (MaxProperties.HasValue)
            {
                json["maxProperties"] = MaxProperties;
            }
            if (MinProperties.HasValue)
            {
                json["minProperties"] = MinProperties;
            }
            if (Required != null)
            {
                var array = Required.ToJson();
                array.Array.EqualityStandard = ArrayEquality.ContentsEqual;
                json["required"]             = array;
            }
            if (AdditionalProperties != null)
            {
                json["additionalProperties"] = AdditionalProperties.ToJson(serializer);
            }
            if (Definitions != null)
            {
                json["definitions"] = Definitions.ToJson(serializer);
            }
            if (Properties != null)
            {
                json["properties"] = Properties.ToJson(serializer);
            }
            if (PatternProperties != null && PatternProperties.Any())
            {
                json["patternProperties"] = PatternProperties.ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value).ToJson(serializer);
            }
            if (Dependencies != null && Dependencies.Any())
            {
                var jsonDependencies = new JsonObject();
                foreach (var dependency in Dependencies)
                {
                    jsonDependencies[dependency.PropertyName] = dependency.GetJsonData();
                }
                json["dependencies"] = jsonDependencies;
            }
            if (Enum != null)
            {
                var array = Enum.ToJson(serializer);
                array.Array.EqualityStandard = ArrayEquality.ContentsEqual;
                json["enum"] = Enum.ToJson(serializer);
            }
            if (Type != JsonSchemaType.NotDefined)
            {
                var array = Type.ToJson();
                if (array.Type == JsonValueType.Array)
                {
                    array.Array.EqualityStandard = ArrayEquality.ContentsEqual;
                }
                json["type"] = array;
            }
            if (AllOf != null)
            {
                var array = AllOf.Select(s => s.ToJson(serializer)).ToJson();
                array.EqualityStandard = ArrayEquality.ContentsEqual;
                json["allOf"]          = array;
            }
            if (AnyOf != null)
            {
                var array = AnyOf.Select(s => s.ToJson(serializer)).ToJson();
                array.EqualityStandard = ArrayEquality.ContentsEqual;
                json["anyOf"]          = array;
            }
            if (OneOf != null)
            {
                var array = OneOf.Select(s => s.ToJson(serializer)).ToJson();
                array.EqualityStandard = ArrayEquality.ContentsEqual;
                json["oneOf"]          = array;
            }
            if (Not != null)
            {
                json["not"] = Not.ToJson(serializer);
            }
            if (Format != null)
            {
                json["format"] = Format.Key;
            }
            if (ExtraneousDetails != null)
            {
                foreach (var kvp in ExtraneousDetails.Where(kvp => !_definedProperties.Contains(kvp.Key)))
                {
                    json[kvp.Key] = kvp.Value;
                }
            }
            return(json);
        }
Exemple #4
0
        public bool Equals(JsonSchema other)
        {
            if (other is null)
            {
                return(false);
            }

            return(Id == other.Id &&
                   (SchemaVersion == null
                        ? other.SchemaVersion == null
                        : SchemaVersion.EqualsWithFragments(other.SchemaVersion)) &&
                   string.Equals(Title, other.Title, StringComparison.Ordinal) &&
                   string.Equals(Description, other.Description, StringComparison.Ordinal) &&
                   Type.HasSameElementsAs(other.Type) &&
                   Enum.HasSameElementsAs(other.Enum) &&
                   (Items == null
                        ? other.Items == null
                        : Items.Equals(other.Items)) &&
                   (Properties == null
                        ? other.Properties == null
                        : Properties.HasSameElementsAs(other.Properties)) &&
                   Required.HasSameElementsAs(other.Required) &&
                   Definitions.HasSameElementsAs(other.Definitions) &&
                   (AdditionalItems == null
                        ? other.AdditionalItems == null
                        : AdditionalItems.Equals(other.AdditionalItems)) &&
                   (AdditionalProperties == null
                        ? other.AdditionalProperties == null
                        : AdditionalProperties.Equals(other.AdditionalProperties)) &&
                   (Dependencies == null
                        ? other.Dependencies == null
                        : Dependencies.HasSameElementsAs(other.Dependencies)) &&
                   (PatternProperties == null
                        ? other.PatternProperties == null
                        : PatternProperties.HasSameElementsAs(other.PatternProperties)) &&
                   (Reference == null
                        ? other.Reference == null
                        : Reference.Equals(other.Reference)) &&
                   Object.Equals(Default, other.Default) &&
                   Pattern == other.Pattern &&
                   MaxLength == other.MaxLength &&
                   MinLength == other.MinLength &&
                   MultipleOf == other.MultipleOf &&
                   Maximum == other.Maximum &&
                   ExclusiveMaximum == other.ExclusiveMaximum &&
                   MinItems == other.MinItems &&
                   MaxItems == other.MaxItems &&
                   UniqueItems == other.UniqueItems &&
                   string.Equals(Format, other.Format, StringComparison.Ordinal) &&
                   (AllOf == null
                        ? other.AllOf == null
                        : AllOf.HasSameElementsAs(other.AllOf)) &&
                   (AnyOf == null
                        ? other.AnyOf == null
                        : AnyOf.HasSameElementsAs(other.AnyOf)) &&
                   (OneOf == null
                        ? other.OneOf == null
                        : OneOf.HasSameElementsAs(other.OneOf)) &&
                   (Not == null
                        ? other.Not == null
                        : Not.Equals(other.Not)));
        }
Exemple #5
0
 public PatternSM(List <StateMachine> states, PatternProperties props) : base(states)
 {
     this.props = props;
     phases     = states.Select(x => (x as PhaseSM) !).ToArray();
     phases.ForEachI((i, p) => p.props.LoadDefaults(props, i));
 }