Last active
May 9, 2022 13:32
-
-
Save CheetahChrome/a63167cb629e76b364cc2b40f960e9e3 to your computer and use it in GitHub Desktop.
C# Static Class Extensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// This is a repistory of many differen extensions I use throughout multiple projects. | |
/// A location here for ultimate move to other named extensions. | |
public static class HTTPExtensions | |
{ | |
/// <summary> | |
/// Allow one to build a URL from its parts, similar to Path.Combine. | |
/// </summary> | |
/// <remarks>HMTL Extensions</Remarks> | |
/// <param name="baseUrl">Initial bitof the url</param> | |
/// <param name="segments">Each inidividual segment to join.</param> | |
/// <returns>The full Url with slashes.</returns> | |
public static string UrlCombine(this string baseUrl, params string[] segments) | |
=> string.Join("/", new[] { baseUrl.TrimEnd('/') }.Concat(segments.Select(s => s.Trim('/')))); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class MicrosoftGraphExtensions | |
{ | |
/// <summary> | |
/// Provide string data if it exists at target key/value. | |
/// </summary> | |
/// <remarks>Microsoft Graph Extensions</remarks> | |
/// <param name="dictionary">Data dictionary</param> | |
/// <param name="key">Key of value to extract</param> | |
/// <returns>String of the value if key exists.</returns> | |
public static string? SetAsStringIfExists(this IDictionary<string, object> dictionary, string key) | |
=> dictionary.ContainsKey(key) ? dictionary[key]?.ToString() : null; | |
/// <summary> | |
/// Generate a Sharepont shared link with the url provided. | |
/// </summary> | |
/// <remarks>Microsoft Graph Extensions</remarks>/// | |
/// <param name="url">Valid url</param> | |
/// <returns>Sharepont shared code url item.</returns> | |
public static string ToDirectSharedCode(this string url) | |
{ | |
if (string.IsNullOrEmpty(url)) | |
return string.Empty; | |
string sharingUrl = url; | |
string base64Value = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(sharingUrl)); | |
string encodedUrl = "u!" + base64Value.TrimEnd('=').Replace('/', '_').Replace('+', '-'); | |
return encodedUrl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment