Skip to content

Commit

Permalink
Adds comments to the remaining undocumented code
Browse files Browse the repository at this point in the history
  • Loading branch information
acupofjose committed Apr 21, 2024
1 parent 0896b05 commit 19dcfdb
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 6 deletions.
14 changes: 14 additions & 0 deletions Core/Attributes/MapToAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,23 @@ namespace Supabase.Core.Attributes
[AttributeUsage(AttributeTargets.Field)]
public class MapToAttribute : Attribute
{
/// <summary>
/// The externally specified target value.
/// </summary>
public string Mapping { get; set; }

/// <summary>
/// A formatter to be passed into the <see cref="String.ToString()" /> method.
/// </summary>
public string? Formatter { get; set; }

/// <summary>
/// Creates a Mapping to be used internally.
///
/// For example, specifying an Enum that has a different string value elsewhere.
/// </summary>
/// <param name="mapping"></param>
/// <param name="formatter"></param>
public MapToAttribute(string mapping, string? formatter = null)
{
Mapping = mapping;
Expand Down
25 changes: 19 additions & 6 deletions Core/Extensions/DictionaryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,27 @@

namespace Supabase.Core.Extensions
{
/// <summary>
/// Extensions for the `Dictionary` Classes
/// </summary>
public static class DictionaryExtensions
{
// Works in C#3/VS2008:
// Returns a new dictionary of this ... others merged leftward.
// Keeps the type of 'this', which must be default-instantiable.
// Example:
// result = map.MergeLeft(other1, other2, ...)
// From: https://stackoverflow.com/a/2679857/3629438
/// <summary>
/// Merges two dictionaries, allowing overwrite priorities leftward.
///
/// Works in C#3/VS2008:
/// Returns a new dictionary of this ... others merged leftward.
/// Keeps the type of 'this', which must be default-instantiable.
/// Example:
/// result = map.MergeLeft(other1, other2, ...)
/// From: https://stackoverflow.com/a/2679857/3629438
/// </summary>
/// <param name="me"></param>
/// <param name="others"></param>
/// <typeparam name="T"></typeparam>
/// <typeparam name="K"></typeparam>
/// <typeparam name="V"></typeparam>
/// <returns></returns>
public static T MergeLeft<T, K, V>(this T me, params IDictionary<K, V>[] others)
where T : IDictionary<K, V>, new()
{
Expand Down
29 changes: 29 additions & 0 deletions Core/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,41 @@

namespace Supabase.Core
{
/// <summary>
/// Shortcut Methods, mostly focused on getting attributes from class properties and enums.
/// </summary>
public static class Helpers
{
/// <summary>
/// Returns the current value from a given class property
/// </summary>
/// <param name="obj"></param>
/// <param name="propName"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static T GetPropertyValue<T>(object obj, string propName) => (T)obj.GetType().GetProperty(propName).GetValue(obj, null);

/// <summary>
/// Returns a cast Custom Attribute from a given object.
/// </summary>
/// <param name="obj"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static T GetCustomAttribute<T>(object obj) where T : Attribute => (T)Attribute.GetCustomAttribute(obj.GetType(), typeof(T));

/// <summary>
/// Returns a cast Custom Attribute from a given type.
/// </summary>
/// <param name="type"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static T GetCustomAttribute<T>(Type type) where T : Attribute => (T)Attribute.GetCustomAttribute(type, typeof(T));

/// <summary>
/// Shortcut method for accessing a `MapTo` attribute, combined with an Enum.
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public static MapToAttribute GetMappedToAttr(Enum obj)
{
var type = obj.GetType();
Expand Down
6 changes: 6 additions & 0 deletions Core/Interfaces/IGettableHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@

namespace Supabase.Core.Interfaces
{
/// <summary>
/// Used for classes that need to retrieve `Headers` externally.
/// </summary>
public interface IGettableHeaders
{
/// <summary>
/// An executable `Func` that returns a dictionary of headers to be appended onto a request.
/// </summary>
Func<Dictionary<string, string>>? GetHeaders { get; set; }
}
}
8 changes: 8 additions & 0 deletions Core/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@

namespace Supabase.Core
{
/// <summary>
/// A shared utilities class
/// </summary>
public static class Util
{
/// <summary>
/// Returns the Current Assembly version - this is usually appended into the headers of each request.
/// </summary>
/// <param name="clientType"></param>
/// <returns></returns>
public static string GetAssemblyVersion(Type clientType)
{
var assembly = clientType.Assembly;
Expand Down

0 comments on commit 19dcfdb

Please sign in to comment.