- ApiClaimTypes
- AssemblyExtensions
- ClaimsPrincipalExtensions
- DateExtensions
- DictionaryExtensions
- ExpressionExtensions
- HttpRequestExtensions
- HttpResponseMessageExtensions
- IConfigurationRootExtensions
- IEnumerableExtensions
- IQueryableExtensions
- AppendOrderByExpression``1(query,propertyName,direction,isAdditionalOrderBy)
- HasValues``1()
- HasValues``1()
- IsEmpty``1()
- IsEmpty``1()
- IsNullOrEmpty``1()
- IsNullOrEmpty``1()
- OrderBy``1(query,propertyName,direction)
- PickRandom``1(source)
- PickRandom``1()
- Shuffle``1()
- ThenBy``1(query,propertyName,direction)
- LambdaComparer`1
- OrderByDirection
- StringExtensions
- TypeExtensions
AndcultureCode.CSharp.Core.Constants
Commonly used Claim types for APIs
TODO: Migrate to AndcultureCode.CSharp.Core
Is the current user elevated to super admin
Active Role Id
Available Role Ids
Active Role Type
Current User Id
Current User Login Id
AndcultureCode.CSharp.Extensions
Extensions for Assembly
Safely returns types that can be loaded from the given assembly
| Name | Type | Description |
|---|---|---|
| assembly | System.Reflection.Assembly |
AndcultureCode.CSharp.Extensions
Extension methods for ClaimsPrincipal
Whether the current user is authenticated
| Name | Type | Description |
|---|---|---|
| principal | System.Security.Claims.ClaimsPrincipal |
Retrieves whether the user is a super admin by way of their identity claims
| Name | Type | Description |
|---|---|---|
| principal | System.Security.Claims.ClaimsPrincipal |
Whether the current user is unauthenticated
| Name | Type | Description |
|---|---|---|
| principal | System.Security.Claims.ClaimsPrincipal |
Retrieves user's current role id by way of their identity claims
| Name | Type | Description |
|---|---|---|
| principal | System.Security.Claims.ClaimsPrincipal |
Retrieves user's role ids by way of their identity claims
| Name | Type | Description |
|---|---|---|
| principal | System.Security.Claims.ClaimsPrincipal |
Retrieves user's id by way of identity claims
| Name | Type | Description |
|---|---|---|
| principal | System.Security.Claims.ClaimsPrincipal |
Retrieves user's UserLoginId from identity claims.
| Name | Type | Description |
|---|---|---|
| principal | System.Security.Claims.ClaimsPrincipal |
AndcultureCode.CSharp.Extensions
DateTime/Offset Extensions
Sets and returns the time to 11:59:59 on the given DateTimeOffset.
| Name | Type | Description |
|---|---|---|
| date | System.DateTimeOffset |
Useful when you only care about the date, but do not want to lose the offset. Returns the midnight representation of the given DateTimeOffset.
| Name | Type | Description |
|---|---|---|
| date | System.DateTimeOffset |
Convenience method to calculate an age from a birthdate
This method has no parameters.
Convenience method to default the inclusive parameter LINQ doesn't like optional parameters on methods used in expressions
This method has no parameters.
Provides filtering method for date ranges (excluding time portions)
This method has no parameters.
Sets the hour, minute, and second on the given DateTimeOffset with the supplied values.
| Name | Type | Description |
|---|---|---|
| date | System.DateTimeOffset | |
| hour | System.Int32 | |
| minute | System.Int32 | |
| second | System.Int32 |
Convenience method to subtract weekdays
This method has no parameters.
Convenience method to subtract weekdays
This method has no parameters.
AndcultureCode.CSharp.Extensions
Extension methods for Dictionary
'Merges' two dictionaries into one. If duplicate keys are encountered, either the first or last occurrence will be used. See 'takeLastKey'
| Name | Type | Description |
|---|---|---|
| left | System.Collections.Generic.Dictionary{``0,``1} | Dictionary to be merged into. |
| right | System.Collections.Generic.Dictionary{``0,``1} | Dictionary to be merged into the left dictionary. |
| takeLastKey | System.Boolean | Determines whether the value of the last occurrence of a key is used as the final value |
| when duplicates are encountered. If false, uses the value of the first occurrence. |
| Name | Description |
|---|---|
| TKey | |
| TValue |
AndcultureCode.CSharp.Extensions
Expression extension methods
Adds another expression filter to original expression using AndAlso operator
| Name | Type | Description |
|---|---|---|
| expr1 | System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}} | Main filter expression |
| expr2 | System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}} | Additional filter expression on the same type of object as the main expression |
| Name | Description |
|---|---|
| T | Type of object in the main filter |
Adds another expression filter to original expression using AndAlso operator
| Name | Type | Description |
|---|---|---|
| expr1 | System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}} | Main filter expression |
| expr2 | System.Linq.Expressions.Expression{System.Func{``1,System.Boolean}} | Filter expression that filters on the navigated property |
| navigationProperty | System.Linq.Expressions.Expression{System.Func{``0,``1}} | Expression to the navigation property (eg e => e.PropA.PropB) |
| Name | Description |
|---|---|
| T | Type of object in the main filter |
| TNav | Type of the navigation property (can be deeply nested) |
Adds another expression filter to original expression using OrElse operator
| Name | Type | Description |
|---|---|---|
| expr1 | System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}} | Main filter expression |
| expr2 | System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}} | Additional filter expression on the same type of object as the main expression |
| Name | Description |
|---|---|
| T | Type of object in the main filter |
Adds another expression filter to original expression using OrElse operator
| Name | Type | Description |
|---|---|---|
| expr1 | System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}} | Main filter expression |
| expr2 | System.Linq.Expressions.Expression{System.Func{``1,System.Boolean}} | Filter expression that filters on the navigated property |
| navigationProperty | System.Linq.Expressions.Expression{System.Func{``0,``1}} | Expression to the navigation property (eg e => e.PropA.PropB) |
| Name | Description |
|---|---|
| T | Type of object in the main filter |
| TNav | Type of the navigation property (can be deeply nested) |
Adds another expression filter to original expression using Or operator
| Name | Type | Description |
|---|---|---|
| expr1 | System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}} | Main filter expression |
| expr2 | System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}} | Additional filter expression on the same type of object as the main expression |
| Name | Description |
|---|---|
| T | Type of object in the main filter |
Adds another expression filter to original expression using Or operator
| Name | Type | Description |
|---|---|---|
| expr1 | System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}} | Main filter expression |
| expr2 | System.Linq.Expressions.Expression{System.Func{``1,System.Boolean}} | Filter expression that filters on the navigated property |
| navigationProperty | System.Linq.Expressions.Expression{System.Func{``0,``1}} | Expression to the navigation property (eg e => e.PropA.PropB) |
| Name | Description |
|---|---|
| T | Type of object in the main filter |
| TNav | Type of the navigation property (can be deeply nested) |
AndcultureCode.CSharp.Extensions
Extension methods for HttpRequest
Standard X-Header for forwarding IP addresses in varying infrastructures
Returns the specified cookie by name
If no cookie is found, returns null
| Name | Type | Description |
|---|---|---|
| request | Microsoft.AspNetCore.Http.HttpRequest | The request to pull the cookie from |
| name | System.String | The name of the cookie to be returned |
Attempts to retrieve requested header value
| Name | Type | Description |
|---|---|---|
| request | Microsoft.AspNetCore.Http.HttpRequest | |
| name | System.String | Header name/key |
Retrieves the client's forwarded IP address, if present. Returns null otherwise. Ensure you have 'AddForwardedHeaders' enabled in startup.
| Name | Type | Description |
|---|---|---|
| request | Microsoft.AspNetCore.Http.HttpRequest |
Requesting user's agent
This method has no parameters.
Returns whether or not the specified cookie is found in the request
If the cookie is found but its value is null/whitespace, it will return false.
| Name | Type | Description |
|---|---|---|
| request | Microsoft.AspNetCore.Http.HttpRequest | The request to check for the cookie |
| name | System.String | The name of the cookie to check for |
AndcultureCode.CSharp.Extensions
HttpResponseMessage extension methods
Deserializes http response into supplied object
| Name | Type | Description |
|---|---|---|
| response | System.Net.Http.HttpResponseMessage |
| Name | Description |
|---|---|
| T |
AndcultureCode.CSharp.Extensions
Extension methods for IConfigurationRoot
Version value when application is run in development environment
Key value for build version number
Template string replaced with current version number
Default connection string database key
Retrieves web application's primary database connection string
| Name | Type | Description |
|---|---|---|
| configuration | Microsoft.Extensions.Configuration.IConfigurationRoot | |
| databaseKey | System.String |
Retrieves the database name of the primary database connection string
| Name | Type | Description |
|---|---|---|
| configuration | Microsoft.Extensions.Configuration.IConfigurationRoot |
Loads and conditionally updates the Version number based upon environment
| Name | Type | Description |
|---|---|---|
| configuration | Microsoft.Extensions.Configuration.IConfigurationRoot | |
| isDevelopment | System.Boolean |
AndcultureCode.CSharp.Extensions
IEnumerable extension methods
Returns items in source collection that do not exist in exclusion collection based on predicate
This method has no parameters.
Determines if the source collection is non-null and has values
This method has no parameters.
Determines if the source collection is non-null and has values
This method has no parameters.
Returns items in source collection that exist in inclusion collection based on the predicate
This method has no parameters.
Determines if the source list is empty
This method has no parameters.
Determines if the source list is empty
This method has no parameters.
Determines if the source list is null or empty
This method has no parameters.
Determines if the source list is null or empty
This method has no parameters.
Convenience method so joining strings reads better :)
This method has no parameters.
Convenience method for joining dictionary key values into a string
This method has no parameters.
Convenience method so joining a list of strings
This method has no parameters.
Convenience method for joining key value pairs
This method has no parameters.
Returns a random value in the related IEnumerable list
This method has no parameters.
Returns X number of random values in the related IEnumerable list
This method has no parameters.
Returns source enumerable in randomized order
This method has no parameters.
AndcultureCode.CSharp.Extensions
IQueryable extension methods
Adds an additional sorting expression to the supplied IQueryable.
| Name | Type | Description |
|---|---|---|
| query | System.Linq.IQueryable{``0} | The IQueryable to add additional sorting to. |
| propertyName | System.String | The path to the property to order by (e.g. Path.To.Property). |
| direction | AndcultureCode.CSharp.Extensions.Enumerations.OrderByDirection | Order by which to sort items. |
| isAdditionalOrderBy | System.Boolean | Whether the order by is an addition to an existing OrderBy statement. |
| Name | Description |
|---|---|
| T |
Determines if the source collection is non-null and has values
This method has no parameters.
Determines if the source collection is non-null and has values
This method has no parameters.
Determines if the source list is empty
This method has no parameters.
Determines if the source list is empty (based on the given predicate)
This method has no parameters.
Determines if the source list is null or empty
This method has no parameters.
Determines if the source list is null or empty (based on the given predicate)
This method has no parameters.
Order by the string expression provided.
| Name | Type | Description |
|---|---|---|
| query | System.Linq.IQueryable{``0} | The IOrderedQueryable to add additional sorting to. |
| propertyName | System.String | The path to the property to order by (e.g. Path.To.Property). |
| direction | AndcultureCode.CSharp.Extensions.Enumerations.OrderByDirection | Order by which to sort items. |
| Name | Description |
|---|---|
| T |
Returns a random value in the related IQueryable list
| Name | Type | Description |
|---|---|---|
| source | System.Linq.IQueryable{``0} |
| Name | Description |
|---|---|
| T |
Returns X number of random values in the related IQueryable list
This method has no parameters.
Returns source enumerable in randomized order
This method has no parameters.
Order then by the string expression provided.
| Name | Type | Description |
|---|---|---|
| query | System.Linq.IOrderedQueryable{``0} | The IOrderedQueryable to add additional sorting to. |
| propertyName | System.String | The path to the property to order by (e.g. Path.To.Property). |
| direction | AndcultureCode.CSharp.Extensions.Enumerations.OrderByDirection | Order by which to sort items. |
| Name | Description |
|---|---|
| T |
AndcultureCode.CSharp.Extensions.Models
Generic comparator class for ease of use with comparison functions
Constructor for new comparator based on predicate
| Name | Type | Description |
|---|---|---|
| predicate | System.Func{`0,`0,System.Boolean} | Predicate to be used for equality comparison |
Inherit from parent.
This method has no parameters.
Inherit from parent.
This method has no parameters.
AndcultureCode.CSharp.Extensions.Enumerations
Directions for ordering items.
Sorted in ascending order.
Sorted in descending order.
AndcultureCode.CSharp.Extensions
String extension methods
Formats string for pretty printing of a JSON string
| Name | Type | Description |
|---|---|---|
| str | System.String |
Determines if the supplied string is not a valid HTTP or HTTPS Url
Uses the native Uri class
| Name | Type | Description |
|---|---|---|
| source | System.String |
Determine if supplied string is not a valid Guid
| Name | Type | Description |
|---|---|---|
| guidString | System.String |
Determines if the supplied string is an email address
| Name | Type | Description |
|---|---|---|
| System.String |
Determine if supplied string is a valid Guid
| Name | Type | Description |
|---|---|---|
| guidString | System.String |
Determines if the supplied string is a valid HTTP or HTTPS url
Uses the native Uri class
| Name | Type | Description |
|---|---|---|
| source | System.String |
Converts a string representation of a boolean into an actual boolean
This method has no parameters.
Converts a string of ints into an enumerable
| Name | Type | Description |
|---|---|---|
| input | System.String | |
| separator | System.Char |
Convert a string to integer, otherwise default the value
Converted string as an integer value
| Name | Type | Description |
|---|---|---|
| number | System.String | String that should be a number |
| defaultValue | System.Int32 | Default value used if the number cannot be parse (0 is default) |
Returns true or false if the value can be converted
| Name | Type | Description |
|---|---|---|
| value | System.Object | |
| conversionType | System.Type |
AndcultureCode.CSharp.Extensions
Extensions for Type
Retrieve all constant values for given type whose value matches type T
This method has no parameters.
Get the PropertyInfo for specified property, if it exists on the type and is public, otherwise returns null.
The PropertyInfo for the property, if it exists and is public, null otherwise.
| Name | Type | Description |
|---|---|---|
| type | System.Type | |
| propertyName | System.String |
Get the value of a property specified by propertyName, if it exists on the object and is public. If no such public property exists, returns null.
The property value, if it exists and is public, null otherwise.
| Name | Type | Description |
|---|---|---|
| src | System.Object | |
| propertyName | System.String |
Get the value of a property specified by propertyName, if it exists on the object and is public, casted to type T. If no such property exists, returns null.
The property value, if it exists, null otherwise.
| Name | Type | Description |
|---|---|---|
| src | System.Object | |
| propertyName | System.String |
Returns the name the underlying type of any object
| Name | Type | Description |
|---|---|---|
| obj | System.Object |
Returns the full name of the type as well as the assembly qualified name
| Name | Type | Description |
|---|---|---|
| type | System.Type |
Checks whether a property specified by propertyName exists on the specified type.
true if type has property with specified name, false otherwise
| Name | Type | Description |
|---|---|---|
| type | System.Type | |
| propertyName | System.String |
Filters the provided list of types to only those that are decorated with the TAttribute attribute at the class level.
This method has no parameters.
Filters the provided list of types to only those that aren't decorated with the TAttribute attribute at the class level.
This method has no parameters.