Skip to content

Commit d498a8f

Browse files
committed
Cleanup and C# 6
1 parent c1a016f commit d498a8f

7 files changed

+34
-47
lines changed

src/Skybrud.ImagePicker/Extensions/PublishedContentExtensions.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public static class PublishedContentExtensions {
1616
/// </summary>
1717
/// <param name="content">An instance of <see cref="IPublishedContent"/> to read the property from.</param>
1818
/// <param name="propertyAlias">The alias of the property.</param>
19-
/// <returns>Returns an instance of <see cref="ImagePickerItem"/>.</returns>
19+
/// <returns>An instance of <see cref="ImagePickerItem"/>.</returns>
2020
public static ImagePickerItem GetImagePickerItem(this IPublishedContent content, string propertyAlias) {
2121
var list = content.GetPropertyValue(propertyAlias) as ImagePickerList;
22-
ImagePickerItem item = (list == null ? null : list.Items.FirstOrDefault());
22+
ImagePickerItem item = list?.Items.FirstOrDefault();
2323
return item ?? new ImagePickerItem();
2424
}
2525

@@ -28,9 +28,9 @@ public static ImagePickerItem GetImagePickerItem(this IPublishedContent content,
2828
/// </summary>
2929
/// <param name="content">An instance of <see cref="IPublishedContent"/> to read the property from.</param>
3030
/// <param name="propertyAlias">The alias of the property.</param>
31-
/// <returns>Returns an instance of <see cref="ImagePickerList"/>.</returns>
31+
/// <returns>An instance of <see cref="ImagePickerList"/>.</returns>
3232
public static ImagePickerList GetImagePickerList(this IPublishedContent content, string propertyAlias) {
33-
return (content == null ? null : content.GetPropertyValue<ImagePickerList>(propertyAlias)) ?? new ImagePickerList();
33+
return content?.GetPropertyValue<ImagePickerList>(propertyAlias) ?? new ImagePickerList();
3434
}
3535
}
3636

src/Skybrud.ImagePicker/Grid/Config/GridEditorImagePickerConfig.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class GridEditorImagePickerConfig : GridJsonObject, IGridEditorConfig {
1515
/// <summary>
1616
/// Gets a reference to the parent editor.
1717
/// </summary>
18-
public GridEditor Editor { get; private set; }
18+
public GridEditor Editor { get; }
1919

2020
#endregion
2121

src/Skybrud.ImagePicker/Grid/Config/GridEditorImagePickerTitleConfig.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class GridEditorImagePickerTitleConfig : GridJsonObject {
1414
/// <summary>
1515
/// Gets whether the title of the image picker list should be shown.
1616
/// </summary>
17-
public bool Show { get; private set; }
17+
public bool Show { get; }
1818

1919
#endregion
2020

src/Skybrud.ImagePicker/Grid/Values/GridControlImagePickerValue.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class GridControlImagePickerValue : ImagePickerList, IGridControlValue {
1515
/// <summary>
1616
/// Gets a reference to the parent control.
1717
/// </summary>
18-
public GridControl Control { get; private set; }
18+
public GridControl Control { get; }
1919

2020
#endregion
2121

@@ -34,6 +34,9 @@ protected GridControlImagePickerValue(GridControl control, JObject obj) : base(o
3434

3535
#region Member methods
3636

37+
/// <summary>
38+
/// Gets the searchable text for this image picker value.
39+
/// </summary>
3740
public string GetSearchableText() {
3841

3942
StringBuilder sb = new StringBuilder();

src/Skybrud.ImagePicker/ImagePickerImage.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class ImagePickerImage {
1616
/// Gets a reference to the underlying instance of <see cref="IPublishedContent"/>.
1717
/// </summary>
1818
[JsonIgnore]
19-
public IPublishedContent Image { get; private set; }
19+
public IPublishedContent Image { get; }
2020

2121
/// <summary>
2222
/// Gets the width of the image.
@@ -47,7 +47,7 @@ public class ImagePickerImage {
4747
#region Constructors
4848

4949
/// <summary>
50-
/// Initializes a new instance based on the specified <code>content</code>.
50+
/// Initializes a new instance based on the specified <paramref name="content"/>.
5151
/// </summary>
5252
/// <param name="content">An instance of <see cref="IPublishedContent"/> representing the selected image.</param>
5353
protected ImagePickerImage(IPublishedContent content) {
@@ -88,17 +88,17 @@ public string GetCropUrl(int? width = null, int? height = null, string propertyA
8888
#region Static methods
8989

9090
/// <summary>
91-
/// Parses the specified <code>content</code> into an instance of <see cref="ImagePickerImage"/>.
91+
/// Parses the specified <paramref name="content"/> into an instance of <see cref="ImagePickerImage"/>.
9292
/// </summary>
9393
/// <param name="content">The instance of <see cref="ImagePickerImage"/> to be parsed.</param>
9494
/// <returns>Returns an instance of <see cref="ImagePickerImage"/>, or <code>null</code> if
95-
/// <code>content</code> is <code>null</code>.</returns>
95+
/// <paramref name="content"/> is <code>null</code>.</returns>
9696
public static ImagePickerImage GetFromContent(IPublishedContent content) {
9797
return content == null ? null : new ImagePickerImage(content);
9898
}
9999

100100
/// <summary>
101-
/// Gets a reference to the image with the specified <code>imageId</code>.
101+
/// Gets a reference to the image with the specified <paramref name="imageId"/>.
102102
/// </summary>
103103
/// <param name="imageId">The ID of the image..</param>
104104
/// <returns>Returns an instance of <see cref="ImagePickerImage"/>, or <code>null</code> if the image could not

src/Skybrud.ImagePicker/ImagePickerItem.cs

+9-18
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class ImagePickerItem {
1919
/// Gets a reference to the <see cref="JObject"/> the item was parsed from.
2020
/// </summary>
2121
[JsonIgnore]
22-
public JObject JObject { get; private set; }
22+
public JObject JObject { get; }
2323

2424
/// <summary>
2525
/// Gets a reference to the selected image.
@@ -31,9 +31,7 @@ public class ImagePickerItem {
3131
/// Gets whether an image has been selected for this item.
3232
/// </summary>
3333
[JsonIgnore]
34-
public bool HasImage {
35-
get { return Image != null; }
36-
}
34+
public bool HasImage => Image != null;
3735

3836
/// <summary>
3937
/// Gets the title of this item.
@@ -45,9 +43,7 @@ public bool HasImage {
4543
/// Gets whether a title has been specified for this item.
4644
/// </summary>
4745
[JsonIgnore]
48-
public bool HasTitle {
49-
get { return !String.IsNullOrWhiteSpace(Title); }
50-
}
46+
public bool HasTitle => !String.IsNullOrWhiteSpace(Title);
5147

5248
/// <summary>
5349
/// Gets the description of this item.
@@ -59,9 +55,7 @@ public bool HasTitle {
5955
/// Gets whether a description has been specified for this item.
6056
/// </summary>
6157
[JsonIgnore]
62-
public bool HasDescription {
63-
get { return !String.IsNullOrWhiteSpace(Description); }
64-
}
58+
public bool HasDescription => !String.IsNullOrWhiteSpace(Description);
6559

6660
/// <summary>
6761
/// Gets a reference to the selected <see cref="LinkPickerItem"/>.
@@ -74,18 +68,14 @@ public bool HasDescription {
7468
/// Gets whether a valid link has been specified for this item.
7569
/// </summary>
7670
[JsonIgnore]
77-
public bool HasLink {
78-
get { return Link != null && Link.IsValid; }
79-
}
71+
public bool HasLink => Link != null && Link.IsValid;
8072

8173
/// <summary>
8274
/// Gets whether the item is valid. Since an item can exist without a title, description or link, but must have
8375
/// an image, this property equals calling <see cref="HasImage"/>.
8476
/// </summary>
8577
[JsonIgnore]
86-
public bool IsValid {
87-
get { return HasImage; }
88-
}
78+
public bool IsValid => HasImage;
8979

9080
#endregion
9181

@@ -100,7 +90,8 @@ public ImagePickerItem() {
10090
}
10191

10292
/// <summary>
103-
/// Initializes a new image picker item based on the specified <code>image</code>, <code>title</code>, <code>description</code> and <code>link</code>.
93+
/// Initializes a new image picker item based on the specified <paramref name="image"/>, <paramref name="title"/>,
94+
/// <paramref name="description"/> and <paramref name="link"/>.
10495
/// </summary>
10596
/// <param name="image">An instance of <see cref="IPublishedContent"/> representing the selected image.</param>
10697
/// <param name="title">The title of the item.</param>
@@ -133,7 +124,7 @@ protected ImagePickerItem(JObject obj) {
133124
/// Parses the specified <see cref="JObject"/> into an instance of <see cref="ImagePickerItem"/>.
134125
/// </summary>
135126
/// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param>
136-
/// <returns>Returns an instance of <see cref="ImagePickerItem"/>, or <code>null</code> if <code>obj</code> is
127+
/// <returns>An instance of <see cref="ImagePickerItem"/>, or <code>null</code> if <code>obj</code> is
137128
/// <code>null</code>.</returns>
138129
public static ImagePickerItem Parse(JObject obj) {
139130
return obj == null ? null : new ImagePickerItem(obj);

src/Skybrud.ImagePicker/ImagePickerList.cs

+10-17
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class ImagePickerList {
1717
/// Gets a reference to the <see cref="JObject"/> the list was parsed from.
1818
/// </summary>
1919
[JsonIgnore]
20-
public JObject JObject { get; private set; }
20+
public JObject JObject { get; }
2121

2222
/// <summary>
2323
/// Gets the title of the list.
@@ -29,9 +29,7 @@ public class ImagePickerList {
2929
/// Gets whether a title has been specified for the list.
3030
/// </summary>
3131
[JsonIgnore]
32-
public bool HasTitle {
33-
get { return !String.IsNullOrWhiteSpace(Title); }
34-
}
32+
public bool HasTitle => !String.IsNullOrWhiteSpace(Title);
3533

3634
/// <summary>
3735
/// Gets an array of all valid items of the list.
@@ -43,25 +41,19 @@ public bool HasTitle {
4341
/// Gets whether the list hs any valid items.
4442
/// </summary>
4543
[JsonIgnore]
46-
public bool HasItems {
47-
get { return Items != null && Items.Any(); }
48-
}
44+
public bool HasItems => Items != null && Items.Any();
4945

5046
/// <summary>
5147
/// Gets the total amount of items in the list.
5248
/// </summary>
5349
[JsonProperty("count")]
54-
public int Count {
55-
get { return Items.Length; }
56-
}
50+
public int Count => Items.Length;
5751

5852
/// <summary>
5953
/// Gets whether the image picker list is valid (alias of <see cref="HasItems"/>).
6054
/// </summary>
6155
[JsonIgnore]
62-
public bool IsValid {
63-
get { return HasItems; }
64-
}
56+
public bool IsValid => HasItems;
6557

6658
#endregion
6759

@@ -93,18 +85,19 @@ protected ImagePickerList(JObject obj) {
9385
/// Parses the specified <see cref="JObject"/> into an instance of <see cref="ImagePickerList"/>.
9486
/// </summary>
9587
/// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param>
96-
/// <returns>Returns an instance of <see cref="ImagePickerList"/>, or <code>null</code> if <code>obj</code> is
88+
/// <returns>An instance of <see cref="ImagePickerList"/>, or <code>null</code> if <paramref name="obj"/> is
9789
/// <code>null</code>.</returns>
9890
public static ImagePickerList Parse(JObject obj) {
9991
return obj == null ? null : new ImagePickerList(obj);
10092
}
10193

10294
/// <summary>
103-
/// Parses the specified JSON <code>str</code> into an instance of <see cref="ImagePickerList"/>. If
104-
/// <code>str</code> is not a valid JSON object, an empty instance of <see cref="ImagePickerList"/> will be returned instead.
95+
/// Parses the specified JSON <paramref name="str"/> into an instance of <see cref="ImagePickerList"/>. If
96+
/// <paramref name="str"/> is not a valid JSON object, an empty instance of <see cref="ImagePickerList"/> will
97+
/// be returned instead.
10598
/// </summary>
10699
/// <param name="str">The JSON string to be parsed.</param>
107-
/// <returns>Returns an instance of <see cref="ImagePickerList"/>.</returns>
100+
/// <returns>An instance of <see cref="ImagePickerList"/>.</returns>
108101
public static ImagePickerList Deserialize(string str) {
109102
if (str == null) return new ImagePickerList();
110103
if (str.StartsWith("{") && str.EndsWith("}")) return Parse(JsonConvert.DeserializeObject<JObject>(str));

0 commit comments

Comments
 (0)