Skip to content

Commit 981978c

Browse files
committed
Updated extension methods
1 parent 5c225c6 commit 981978c

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace MADE.Runtime.Extensions
2+
{
3+
using System;
4+
using System.Reflection;
5+
6+
/// <summary>
7+
/// Defines a collection of extensions for object reflection.
8+
/// </summary>
9+
public static class ReflectionExtensions
10+
{
11+
/// <summary>
12+
/// Gets a value for a property of the <paramref name="obj">specified object</paramref> based on the <paramref name="property">specified property name</paramref>.
13+
/// </summary>
14+
/// <param name="obj">The object to retrieve the property value from.</param>
15+
/// <param name="property">The name of the property to retrieve a value for.</param>
16+
/// <typeparam name="T">The type of expected value.</typeparam>
17+
/// <returns>The value of the property.</returns>
18+
public static T GetPropertyValue<T>(this object obj, string property)
19+
where T : class
20+
{
21+
Type type = obj.GetType();
22+
PropertyInfo prop = type.GetProperty(property);
23+
return prop?.GetValue(obj) as T;
24+
}
25+
}
26+
}

src/MADE.Web/Extensions/HttpResponseExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace MADE.Web.Extensions
77
using System.Text;
88
using System.Threading.Tasks;
99
using Microsoft.AspNetCore.Http;
10+
using Microsoft.Net.Http.Headers;
1011
using Newtonsoft.Json;
1112

1213
/// <summary>
@@ -43,7 +44,7 @@ public static async Task WriteJsonAsync(
4344
object value,
4445
JsonSerializerSettings serializerSettings)
4546
{
46-
response.ContentType = "application/json";
47+
response.ContentType = new MediaTypeHeaderValue("application/json") { Encoding = Encoding.UTF8 }.ToString();
4748
response.StatusCode = (int)statusCode;
4849

4950
string json = JsonConvert.SerializeObject(value, Formatting.Indented, serializerSettings);

src/MADE.Web/Responses/PaginatedResponse{T}.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// MADE Apps licenses this file to you under the MIT license.
1+
// MADE Apps licenses this file to you under the MIT license.
22
// See the LICENSE file in the project root for more information.
33

44
namespace MADE.Web.Responses
55
{
6+
using System;
67
using System.Collections.Generic;
78
using MADE.Web.Requests;
89

@@ -50,7 +51,6 @@ public PaginatedResponse(IEnumerable<T> items, int page, int pageSize, int avail
5051
/// <summary>
5152
/// Gets the total number of pages for the available items based on the page size.
5253
/// </summary>
53-
public int TotalPages =>
54-
this.AvailableCount == 0 || this.PageSize == 0 ? 0 : this.AvailableCount / this.PageSize;
54+
public int TotalPages => this.AvailableCount == 0 || this.PageSize == 0 ? 0 : (int)Math.Ceiling((double)this.AvailableCount / this.PageSize);
5555
}
5656
}

0 commit comments

Comments
 (0)