Skip to content

Commit

Permalink
Use compound assignment and simplify delegate invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed Nov 20, 2024
1 parent f86d896 commit c242bdd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 85 deletions.
4 changes: 1 addition & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
[IDE0057] Substring can be simplified
[IDE0059] Unnecessary assignment of a value
[IDE0060] Remove unused parameter
[IDE0074] Use compound assignment
[IDE0078] Use pattern matching
[IDE0083] Use pattern matching
[IDE0090] 'new' expression can be simplified
Expand All @@ -59,15 +58,14 @@
[IDE0160] Convert to block scoped namespace
[IDE0260] Use pattern matching
[IDE0290] Use primary constructor
[IDE1005] Delegate invocation can be simplified
[CA1200] Avoid using cref tags with a prefix
[CA1510] Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance
[CA1716] rename parameter property so that it no longer conflicts with the reserved language keyword
[CA1720] Identifier 'xxx' contains type name
[CA1870] Use a cached 'SearchValues' instance for improved searching performance
[CA2263] Prefer the generic overload 'System.Enum.GetValues<TEnum>()'
-->
<NoWarn>$(NoWarn);IDE0008;IDE0019;IDE0021;IDE0022;IDE0025;IDE0027;IDE0028;IDE0029;IDE0032;IDE0039;IDE0045;IDE0046;IDE0055;IDE0057;IDE0059;IDE0060;IDE0074;IDE0078;IDE0083;IDE0090;IDE0100;IDE0130;IDE0160;IDE0260;IDE0290;IDE1005;CA1200;CA1510;CA1716;CA1720;CA1870;CA2263</NoWarn>
<NoWarn>$(NoWarn);IDE0008;IDE0019;IDE0021;IDE0022;IDE0025;IDE0027;IDE0028;IDE0029;IDE0032;IDE0039;IDE0045;IDE0046;IDE0055;IDE0057;IDE0059;IDE0060;IDE0078;IDE0083;IDE0090;IDE0100;IDE0130;IDE0160;IDE0260;IDE0290;CA1200;CA1510;CA1716;CA1720;CA1870;CA2263</NoWarn>
</PropertyGroup>

</Project>
25 changes: 5 additions & 20 deletions src/NJsonSchema/Collections/ObservableDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,51 +133,36 @@ private void Insert(TKey key, TValue? value, bool add)
private void OnPropertyChanged(string propertyName)
{
var copy = PropertyChanged;
if (copy != null)
{
copy(this, new PropertyChangedEventArgs(propertyName));
}
copy?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

private void OnCollectionChanged()
{
OnPropertyChanged();
var copy = CollectionChanged;
if (copy != null)
{
copy(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
copy?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}

private void OnCollectionChanged(NotifyCollectionChangedAction action, KeyValuePair<TKey, TValue?> changedItem)
{
OnPropertyChanged();
var copy = CollectionChanged;
if (copy != null)
{
copy(this, new NotifyCollectionChangedEventArgs(action, changedItem, 0));
}
copy?.Invoke(this, new NotifyCollectionChangedEventArgs(action, changedItem, 0));
}

private void OnCollectionChanged(NotifyCollectionChangedAction action, KeyValuePair<TKey, TValue?> newItem,
KeyValuePair<TKey, TValue?> oldItem)
{
OnPropertyChanged();
var copy = CollectionChanged;
if (copy != null)
{
copy(this, new NotifyCollectionChangedEventArgs(action, newItem, oldItem, 0));
}
copy?.Invoke(this, new NotifyCollectionChangedEventArgs(action, newItem, oldItem, 0));
}

private void OnCollectionChanged(NotifyCollectionChangedAction action, IList newItems)
{
OnPropertyChanged();
var copy = CollectionChanged;
if (copy != null)
{
copy(this, new NotifyCollectionChangedEventArgs(action, newItems, 0));
}
copy?.Invoke(this, new NotifyCollectionChangedEventArgs(action, newItems, 0));
}

private void OnPropertyChanged()
Expand Down
16 changes: 3 additions & 13 deletions src/NJsonSchema/Generation/JsonSchemaGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,7 @@ public virtual void ApplyDataAnnotations(JsonSchema schema, JsonTypeDescription
{
if (typeDescription.IsDictionary)
{
if (schema.AdditionalPropertiesSchema == null)
{
schema.AdditionalPropertiesSchema = new JsonSchema();
}
schema.AdditionalPropertiesSchema ??= new JsonSchema();

schema.AdditionalPropertiesSchema.Pattern = regexAttribute.Pattern;
}
Expand Down Expand Up @@ -1205,15 +1202,8 @@ public void AddProperty(
propertySchema.IsReadOnly = readOnlyAttribute.IsReadOnly;
}

if (propertySchema.Description == null)
{
propertySchema.Description = property.GetDescription(Settings);
}

if (propertySchema.Example == null)
{
propertySchema.Example = GenerateExample(property);
}
propertySchema.Description ??= property.GetDescription(Settings);
propertySchema.Example ??= GenerateExample(property);

dynamic? obsoleteAttribute = property.GetAttributes(true).FirstAssignableToTypeNameOrDefault("System.ObsoleteAttribute");
if (obsoleteAttribute != null)
Expand Down
59 changes: 10 additions & 49 deletions src/NJsonSchema/JsonSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,55 +1028,16 @@ private static JsonObjectType ConvertStringToJsonObjectType(string? value)
private void Initialize()
#pragma warning disable CS8774
{
if (Items == null)
{
Items = new ObservableCollection<JsonSchema>();
}

if (Properties == null)
{
Properties = new ObservableDictionary<string, JsonSchemaProperty>();
}

if (PatternProperties == null)
{
PatternProperties = new ObservableDictionary<string, JsonSchemaProperty>();
}

if (Definitions == null)
{
Definitions = new ObservableDictionary<string, JsonSchema>();
}

if (RequiredProperties == null)
{
RequiredProperties = new Collection<string>();
}

if (AllOf == null)
{
AllOf = new ObservableCollection<JsonSchema>();
}

if (AnyOf == null)
{
AnyOf = new ObservableCollection<JsonSchema>();
}

if (OneOf == null)
{
OneOf = new ObservableCollection<JsonSchema>();
}

if (Enumeration == null)
{
Enumeration = new Collection<object?>();
}

if (EnumerationNames == null)
{
EnumerationNames = [];
}
Items ??= new ObservableCollection<JsonSchema>();
Properties ??= new ObservableDictionary<string, JsonSchemaProperty>();
PatternProperties ??= new ObservableDictionary<string, JsonSchemaProperty>();
Definitions ??= new ObservableDictionary<string, JsonSchema>();
RequiredProperties ??= new Collection<string>();
AllOf ??= new ObservableCollection<JsonSchema>();
AnyOf ??= new ObservableCollection<JsonSchema>();
OneOf ??= new ObservableCollection<JsonSchema>();
Enumeration ??= new Collection<object?>();
EnumerationNames ??= [];
}
#pragma warning restore CS8774

Expand Down

0 comments on commit c242bdd

Please sign in to comment.