Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use compound assignment and simplify delegate invocation #1749

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,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 @@ -60,15 +59,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 @@ -130,51 +130,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 @@ -366,10 +366,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 @@ -1202,15 +1199,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 @@ -1022,55 +1022,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