Code Monkey home page Code Monkey logo

base-types's Introduction

Hi, Iโ€™m @Andreas-Dorfer. I'm a software developer for more than 10 years. I'm all about writing high-quality enterprise software.

My preferred languages / technologies / libraries / tools are:

  • F#, C# and TypeScript
  • Visual Studio and Visual Studio Code
  • .NET and ASP.NET
  • Azure
  • Cosmos DB and SQL Server
  • FsCheck

base-types's People

Contributors

adampaquette avatar andreas-dorfer avatar jeffward01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

base-types's Issues

Discord

I want to light up this library, open many PRs and use it in production. A discord server for base-types would be handy.

Allow Implicit Casting of operators to work on struct types

There's already a way to make that work. You can specify that you want an implicit cast to the wrapped type. For example:

[DateTime, BaseType(Cast.Implicit)] public partial record MyDateTime;

That way, all the operators should work out of the box. Beware that the BaseTypeAttribute in the released version doesn't work on struct records. But that will be fixed in the next release.

Originally posted by @Andreas-Dorfer in #13 (comment)

IComparable

Only implement IComparable when the wrapped type implements IComparable.

[Update] Update to Net 7.0

Great library!

Would love to upgrade it to net7 - if I have some time I can make a pull request - if you beat me to it thats great too.

You know the library better than I do, I have to examine the F# and other projects you have.


If you want - you can target both net6 and net7 like this:

Source Example Meziantou.Framework/Directory.Build.props

  <PropertyGroup>
    <LatestTargetFrameworkLts>net6.0</LatestTargetFrameworkLts>
    <LatestTargetFramework>net7.0</LatestTargetFramework>
    <LatestTargetFrameworkPreview></LatestTargetFrameworkPreview>

    <LatestTargetFrameworkLtsWindows>$(LatestTargetFrameworkLts)-windows</LatestTargetFrameworkLtsWindows>
    <LatestTargetFrameworkWindows>$(LatestTargetFramework)-windows</LatestTargetFrameworkWindows>
    <LatestTargetFrameworkPreviewWindows Condition="'$(LatestTargetFrameworkPreview)' != ''">$(LatestTargetFrameworkPreview)-windows</LatestTargetFrameworkPreviewWindows>

    <LatestTargetFrameworks>$(LatestTargetFrameworkPreview);$(LatestTargetFramework);$(LatestTargetFrameworkLts)</LatestTargetFrameworks>
    <LatestTargetFrameworksWindows>$(LatestTargetFrameworkPreviewWindows);$(LatestTargetFrameworkWindows);$(LatestTargetFrameworkLtsWindows)</LatestTargetFrameworksWindows>

    <SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
  </PropertyGroup>

Something like that

Very cool library! I have tried many 'base type' libraries, and I love how your validation works.

Memory allocation for attributes

I'm looking for ways to remove the memory allocation caused by attributes in the generated classes.

[Years(1990, 1999)] partial record SomeWeekendInThe90s;
...
public SomeWeekendInThe90s(DateTime value)
{
    new YearsAttribute(1990, 1999).Validate(value);
    this.value = value;
}

What we need to know is what validation function to call with what values as parameters.

Maybe we could use some static interface with a convention to route parameters from the attribute to the validation function.

[AttributeUsage(AttributeTargets.Class)]
public class MaxLengthStringAttribute : Attribute
{
    public MaxLengthStringAttribute(int maxLength) { }
    public static void Validate(string value, int maxLength) => StringValidation.MaxLength(maxLength, value);
}

Then it could generate something like

[MaxLengthString(25)] partial record Name;
...
public Name(string value)
{
    MaxLengthStringAttribute.Validate(value, 25);
    this.value = value;
}

[Feature Request] ByteArray (byte[]) or BitArray) implementation

Hello!

I was working on a PR myself for this, but I have been stumped since byte[] and BitArray do not implement the IComparable interface.

You know your library much better than I do - do you have any advice how an implementation for this can be done?

My thoughts are to:

  • Create some internal 'wrapper' type for byte[]
  • Autmatically cast the byte[] to the wrapper type
  • Keep the wrapper type 'hidden' from the user (developer) in an internal class / struct

What do you think? Any advice? Im struggling with the wrapper type being convertible to your IBaseType in the code

Can you point me in the right direction with solving this?

public class BitArrayComparable : IComparable<byte[]>

{
    private readonly byte[] _bitArray;

    public BitArrayComparable(byte[] bitArray)
    {
        this._bitArray = bitArray;
    }

    /// <inheritdoc />
    public int CompareTo(byte[]? other)
    {
        var len = Math.Min(this._bitArray.Length, other.Length);
        for (var i = 0; i < len; i++)
        {
            var c = this._bitArray[i]
                .CompareTo(other[i]);
            if (c != 0)
            {
                return c;
            }
        }

        return other.Length.CompareTo(other.Length);
    }
} 

I had something like this, but its not convertible to IBaseType

Thanks

Configurable Casts

Make generated casts configurable via BaseTypeAttribute:

  • Explicit
  • Implicit
  • None

Release doesn't compile : Using the generic type 'IBaseType<TWrapped>' requires 1 type arguments

In release mode projects uses a package reference and crashes with the error Using the generic type 'IBaseType<TWrapped>' requires 1 type arguments.

<ItemGroup Condition="'$(Configuration)'!='Debug'">
  <PackageReference Include="AndreasDorfer.BaseTypes.Core" Version="1.4.0" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)'=='Debug'">
  <ProjectReference Include="..\AD.BaseTypes.Core\AD.BaseTypes.Core.csproj" />
</ItemGroup>

Publishing a branch relying on a nuget package still not built is supposed to work? The use of package references in release looks strange, maybe you can explain. Thanks

[Feature Request] Add ability for == and != types

Would be cool to be able to do something like this:

image

Example interface:

public interface IOperators<in TSelf, in TOther, out TResult> 
where TSelf : IOperators<TSelf, TOther,TResult>

{
    static abstract TResult operator ==(TSelf self, TOther other);
    static abstract TResult operator ==(TOther self, TSelf other);
    static abstract TResult operator !=(TSelf  self, TOther other);
    static abstract TResult operator !=(TOther self, TSelf other);

}

For struct implementation:

public interface IOperators<TSelf, TOther, out TResult> 
where TSelf : IOperators<TSelf, TOther,TResult>

{
    static abstract TResult operator ==(in TSelf self, in TOther other);
    static abstract TResult operator ==(in TOther self,in  TSelf other);
    static abstract TResult operator !=(in TSelf  self,in TOther other);
    static abstract TResult operator !=(in TOther self,in  TSelf other);

}

IParsable

Implement IParsable if the wrapped type implements IParsable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.