Skip to content

Commit

Permalink
C# code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
abjerner committed Jun 29, 2018
1 parent 0602a68 commit 0d29536
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class PublishedContentExtensions {
/// <returns>An instance of <see cref="LinkPickerItem"/>.</returns>
public static LinkPickerItem GetLinkPickerItem(this IPublishedContent content, string propertyAlias) {
LinkPickerList list = content.GetPropertyValue(propertyAlias) as LinkPickerList;
LinkPickerItem item = (list == null ? null : list.Items.FirstOrDefault());
LinkPickerItem item = list?.Items.FirstOrDefault();
return item ?? new LinkPickerItem();
}

Expand All @@ -37,7 +37,7 @@ public static LinkPickerItem GetLinkPickerItem(this IPublishedContent content, s
/// <param name="propertyAlias">The alias of the property.</param>
/// <returns>An instance of <see cref="LinkPickerList"/>.</returns>
public static LinkPickerList GetLinkPickerList(this IPublishedContent content, string propertyAlias) {
return (content == null ? null : content.GetPropertyValue<LinkPickerList>(propertyAlias)) ?? new LinkPickerList {
return content?.GetPropertyValue<LinkPickerList>(propertyAlias) ?? new LinkPickerList {
Items = new LinkPickerItem[0]
};
}
Expand Down
10 changes: 5 additions & 5 deletions src/Skybrud.LinkPicker/Grid/Config/GridEditorLinkPickerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ public class GridEditorLinkPickerConfig : GridEditorConfigBase {

#region Properties

public GridEditorLinkPickerConfigTitle Title { get; private set; }
public GridEditorLinkPickerConfigTitle Title { get; }

public int Limit { get; private set; }
public int Limit { get; }

public GridEditorLinkPickerConfigTypes Types { get; private set; }
public GridEditorLinkPickerConfigTypes Types { get; }

public bool ShowTable { get; private set; }
public bool ShowTable { get; }

public GridEditorLinkPickerConfigColumns Columns { get; private set; }
public GridEditorLinkPickerConfigColumns Columns { get; }


#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public class GridEditorLinkPickerConfigColumns : GridJsonObject {

#region Properties

public bool Type { get; private set; }
public bool Type { get; }

public bool Id { get; private set; }
public bool Id { get; }

public bool Name { get; private set; }
public bool Name { get; }

public bool Url { get; private set; }
public bool Url { get; }

public bool Target { get; private set; }
public bool Target { get; }

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,27 @@ public class GridEditorLinkPickerConfigTitle : GridJsonObject {
/// <summary>
/// Gets whether the title of the link picker list should be shown.
/// </summary>
public bool Show { get; private set; }
public bool Show { get; }

/// <summary>
/// Gets the placeholder title of the link picker.
/// </summary>
public string Placeholder { get; private set; }
public string Placeholder { get; }

/// <summary>
/// Gets whether the <see cref="Placeholder"/> property has a value.
/// </summary>
public bool HasPlaceholder {
get { return !String.IsNullOrWhiteSpace(Placeholder); }
}
public bool HasPlaceholder => !String.IsNullOrWhiteSpace(Placeholder);

/// <summary>
/// Gets the default (fallback) title of the link picker.
/// </summary>
public string Default { get; private set; }
public string Default { get; }

/// <summary>
/// Gets whether the <see cref="Default"/> property has a value.
/// </summary>
public bool HasDefault {
get { return !String.IsNullOrWhiteSpace(Default); }
}
public bool HasDefault => !String.IsNullOrWhiteSpace(Default);

#endregion

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Linq;
using Skybrud.Essentials.Json.Extensions;
using Skybrud.Umbraco.GridData.Json;

Expand All @@ -12,11 +11,11 @@ public class GridEditorLinkPickerConfigTypes : GridJsonObject {

#region Properties

public bool Url { get; private set; }
public bool Url { get; }

public bool Content { get; private set; }
public bool Content { get; }

public bool Media { get; private set; }
public bool Media { get; }

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ public class GridControlLinkPickerValue : LinkPickerList, IGridControlValue {
/// <summary>
/// Gets a reference to the parent control.
/// </summary>
public GridControl Control { get; private set; }
public GridControl Control { get; }

/// <summary>
/// Gets whether the link picker list is valid (alias of <see cref="LinkPickerList.HasItems"/>).
/// </summary>
[JsonIgnore]
public override bool IsValid {
get { return HasItems; }
}
public override bool IsValid => HasItems;

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ namespace Skybrud.LinkPicker.Json.Converters {
/// </summary>
public class LinkPickerConverter : JsonConverter {

public override bool CanWrite {
get { return false; }
}
public override bool CanWrite => false;

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Skybrud.LinkPicker.Json.Converters {
/// <summary>
/// JSON converter specifically for serializing and deserializing instances of <see cref="LinkPickerItem" />. This
/// converter differs from <see cref="LinkPickerConverter" /> as this converter will serialize an invalid
/// <see cref="LinkPickerItem" /> to <code>null</code>.
/// <see cref="LinkPickerItem" /> to <c>null</c>.
/// </summary>
public class LinkPickerItemConverter : JsonConverter {

Expand Down Expand Up @@ -53,7 +53,7 @@ private object ReadJsonObject(JsonReader reader, Type objectType) {
/// Determines whether this instance can convert the specified <paramref name="objectType"/>.
/// </summary>
/// <param name="objectType">Type of the object.</param>
/// <returns><code>true</code> if this instance can convert the specified object type; otherwise <code>false</code>.</returns>
/// <returns><c>true</c> if this instance can convert the specified object type; otherwise <c>false</c>.</returns>
public override bool CanConvert(Type objectType){
return objectType == typeof(LinkPickerItem);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Skybrud.LinkPicker/LinkPickerItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class LinkPickerItem {
public JObject JObject { get; private set; }

/// <summary>
/// Gets the ID of the selected content or media. If an URL has been selected, this will return <code>0</code>.
/// Gets the ID of the selected content or media. If an URL has been selected, this will return <c>0</c>.
/// </summary>
[JsonProperty("id")]
public int Id { get; private set; }
Expand Down
4 changes: 2 additions & 2 deletions src/Skybrud.LinkPicker/LinkPickerList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ select link
/// Parses the specified <see cref="JObject"/> into an instance of <see cref="LinkPickerList"/>.
/// </summary>
/// <param name="obj">An instance of <see cref="JObject"/> representing the link picker list.</param>
/// <returns>Returns an instacne of <see cref="LinkPickerList"/>, or <code>null</code> if <paramref name="obj"/> is <code>null</code>.</returns>
/// <returns>An instacne of <see cref="LinkPickerList"/>, or <c>null</c> if <paramref name="obj"/> is <c>null</c>.</returns>
public static LinkPickerList Parse(JObject obj) {
return obj == null ? null : new LinkPickerList(obj);
}
Expand All @@ -108,7 +108,7 @@ public static LinkPickerList Parse(JObject obj) {
/// Parses the specified <see cref="JArray"/> into an instance of <see cref="LinkPickerList"/>.
/// </summary>
/// <param name="array">An instance of <see cref="JArray"/> representing the link picker list.</param>
/// <returns>Returns an instacne of <see cref="LinkPickerList"/>, or <code>null</code> if <paramref name="array"/> is <code>null</code>.</returns>
/// <returns>An instacne of <see cref="LinkPickerList"/>, or <c>null</c> if <paramref name="array"/> is <c>null</c>.</returns>
public static LinkPickerList Parse(JArray array) {
return array == null ? null : new LinkPickerList(array);
}
Expand Down

0 comments on commit 0d29536

Please sign in to comment.