candoumbe / miscutilities Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
Add support for converting a string to Pascal case.
This would help supporting this DataFilters feature
Package version :
0.5.3
public record MyId : StrongId<Guid>();
public record StrongId<T>();
bool actual = typeof(MyId).IsAssignableToGenericType(typeof(StrongId<Guid>));
Expected actual
to be true
Build https://github.com/candoumbe/MiscUtilities/actions/runs/1441329530 failure seems to be related to GitVersion.Tool not being reading for net6.0
yet
Add operators to merge several instances of MultiTimeOnlyRange
/ MultiDateOnlyRange` together
Package version : 0.5.2
DateTime date = new DateTime(2019, 01, 24, 10, 39, 57)
new { date }.ToQueryString()
What did you expect to happen?
Expected result to be 2019-01-24T10:39:57
but got 2012-01-24T10:39:57Z
RouteValueDictionary
instances should be treated as a IDictionary<string, object> using the latest 0.5.0
version
Package version : 0.6.1
var date = new { date = new DateOnly(2019, 5, 13) };
string dateOnly = date.Jsonify();
What did you expect to happen?
Expected string to be {"date" : "2019-05-13" }
Package version : 0.5.1
public static class StronglyTypedIdHelper
{
private static readonly ConcurrentDictionary<Type, Delegate> StronglyTypedIdFactories = new();
public static Func<TValue, object> GetFactory<TValue>(Type stronglyTypedIdType)
where TValue : notnull
{
return (Func<TValue, object>)StronglyTypedIdFactories.GetOrAdd(
stronglyTypedIdType,
CreateFactory<TValue>);
}
private static Func<TValue, object> CreateFactory<TValue>(Type stronglyTypedIdType)
where TValue : notnull
{
if (!IsStronglyTypedId(stronglyTypedIdType))
{
throw new ArgumentException($"Type '{stronglyTypedIdType}' is not a strongly-typed id type", nameof(stronglyTypedIdType));
}
System.Reflection.ConstructorInfo ctor = stronglyTypedIdType.GetConstructor(new[] { typeof(TValue) });
if (ctor is null)
{
throw new ArgumentException($"Type '{stronglyTypedIdType}' doesn't have a constructor with one parameter of type '{typeof(TValue)}'", nameof(stronglyTypedIdType));
}
ParameterExpression param = Expression.Parameter(typeof(TValue), "value");
NewExpression body = Expression.New(ctor, param);
Expression<Func<TValue, object>> lambda = Expression.Lambda<Func<TValue, object>>(body, param);
return lambda.Compile();
}
public static bool IsStronglyTypedId(Type type) => IsStronglyTypedId(type, out _);
public static bool IsStronglyTypedId(Type type, [NotNullWhen(true)] out Type idType)
{
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
bool isStronglyType = false;
if (type.BaseType is Type baseType &&
baseType.IsGenericType &&
baseType.GetGenericTypeDefinition() == typeof(StronglyTypedId<>))
{
idType = baseType.GetGenericArguments()[0];
isStronglyType = true;
}
else if (type.BaseType == typeof(StronglyTypedGuidId))
{
idType = typeof(Guid);
isStronglyType = true;
}
else
{
idType = null;
}
return isStronglyType;
}
}
public class StronglyTypedIdConverter<TValue> : TypeConverter where TValue : notnull
{
private static readonly TypeConverter IdValueConverter = GetIdValueConverter();
private static TypeConverter GetIdValueConverter()
{
TypeConverter converter = TypeDescriptor.GetConverter(typeof(TValue));
if (!converter.CanConvertFrom(typeof(string)))
{
throw new InvalidOperationException(
$"Type '{typeof(TValue)}' doesn't have a converter that can convert from string");
}
return converter;
}
private readonly Type _type;
public StronglyTypedIdConverter(Type type)
{
_type = type;
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string)
|| sourceType == typeof(TValue)
|| base.CanConvertFrom(context, sourceType);
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
return destinationType == typeof(string)
|| destinationType == typeof(TValue)
|| base.CanConvertTo(context, destinationType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string s)
{
value = IdValueConverter.ConvertFrom(s);
}
object result;
if (value is TValue idValue)
{
Func<TValue, object> factory = StronglyTypedIdHelper.GetFactory<TValue>(_type);
result = factory(idValue);
}
else
{
result = base.ConvertFrom(context, culture, value);
}
return result;
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
StronglyTypedId<TValue> stronglyTypedId = (StronglyTypedId<TValue>)value;
TValue idValue = stronglyTypedId.Value;
object result;
if (destinationType == typeof(string))
{
result = idValue.ToString()!;
}
else if (destinationType == typeof(TValue))
{
result = idValue;
}
else
{
result = base.ConvertTo(context, culture, value, destinationType);
}
return result;
}
}
[TypeConverter(typeof(StronglyTypedIdConverter))]
public abstract record StronglyTypedId<TValue>
where TValue : notnull
{
public TValue Value { get; }
protected StronglyTypedId(TValue value) => Value = value;
public override string ToString() => Value.ToString();
}
public record Identifier : StronglyTypedId<Guid>(Value)
{
public static Identifier New() => new(Guid.NewGuid());
}
and a RouteValueDictionary
instance as follow
RouteValueDictionary routeValues = new() {
["simpleId"] = "abc",
["strongId"] = Identifier.New()
};
routesValue.ToQueryString() // "simpleId=abc"
Given that there is a TypeConverter
that can convert to a primitive type, the consumer of the library would expect the output to be simpleId=abc&strongId=<value of the guid>
Extension methods in EnumerableExtensions
should not used Expression<Func<T, bool>>
but Func<T,bool>
as they run in memory and not against an IQueryable<T>
Provide a delegate that could be used to replace/tranform the value of a property when calling ToQueryString
.
Update nuke to its latest version and create GitHub release on each push to nuget
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
.github/workflows/delivery.yml
actions/checkout v3
actions/cache v3
actions/upload-artifact v3
actions/upload-artifact v3
actions/upload-artifact v3
actions/upload-artifact v3
.github/workflows/integration.yml
actions/checkout v3
actions/cache v3
actions/upload-artifact v3
actions/upload-artifact v3
actions/upload-artifact v3
actions/upload-artifact v3
.config/dotnet-tools.json
nuke.globaltool 7.0.1
dotnet-stryker 3.9.0
build/_build.csproj
ReportGenerator 5.1.9
Candoumbe.Pipelines 0.3.0
Nuke.Common 6.3.0
core.props
Microsoft.SourceLink.GitHub 1.1.1
Microsoft.SourceLink.AzureRepos.Git 1.1.1
global.json
dotnet-sdk 7.0.302
src/Candoumbe.MiscUtilities/Candoumbe.MiscUtilities.csproj
Microsoft.Extensions.Primitives 7.0.0
System.ValueTuple 4.5.0
System.Text.Json 7.0.2
System.Text.Json 7.0.2
Newtonsoft.Json 13.0.3
tests.props
FsCheck.Xunit 3.0.0-beta2
FluentAssertions.Json 6.1.0
FluentAssertions 6.11.0
xunit.categories 2.0.6
xunit.runner.visualstudio 2.4.5
xunit 2.4.2
Bogus 34.0.2
A builder that allows to write try ... catch
expressions in a fluent manner.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.