Git Product home page Git Product logo

ics's People

Contributors

adamzvara avatar antoninjarolim avatar autrimpo avatar emachacek-swi avatar feanor60 avatar jasho avatar martindybal avatar matojeje avatar michaltichy avatar mrnustik avatar ondrej-mahdalik avatar padresvk avatar pluskal avatar pri0r avatar safarmirek avatar seb-stian avatar stefanpeknik avatar tjasek225 avatar xmicha82 avatar

Stargazers

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

Watchers

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

ics's Issues

CookBook's example of Model Mappers does not allow mapping to models without Details

The problem

Let's say we want to extend CookBook with ingredient types and we want our user to input that ingredient type.

public record IngredientEntity : IEntity {
    public required string Name { get; set; }
    public required string Description { get; set; }
    // Add this
    public required IngridientTypeEntity Type { get; set; }
    public string? ImageUrl { get; set; }
    public required Guid Id { get; set; }
}

However, current implementation of IModelMapper and ModelMapperBase won't allow this kind of implementation:

public interface IModelMapper<TEntity, out TListModel, TDetailModel>;

So, in any case we are required to make a model even for the simplest of things that could just be solved with a list, text box and two buttons.

Workarounds

One of the workarounds would be creating dummy classes that just won't be used and changing ModelMapperBase.MapToEntity function signature to make it virtual and adding an overload that would allow mapping from TListModel. Or just using TListModel for TDetailModel.

The question

Was this intentional or did anyone just not consider the possibility of using something other than enum/string for this kind of problem?

Prefer IParsable over Convert

For a long time now, it was preferable to use int.Parse(string) over Convert.ToInt32(string). If you look at the implementation of ToInt32, you can see that it internally calls int.Parse(string), BUT returns 0 when input is null. This behaviour is rarely desirable. Even better than Parse is TryParse, since it is cleaner and performs better than handling exceptions with try catch. Parse is of course better when it comes to writing a simple code snippet for a lecture.

In modern .NET (version 7+) there is IParsable<TSelf> interface that reinforces the suggested pattern even further.

My suggested changes are to reflect these facts in lecture notes (and in related code examples).

The only relevant code example I could find with VS search was in CodeDemonstrations.cs:

Console.WriteLine("Waiting for input (number)...");
int input = Convert.ToInt32(Console.ReadLine());
Console.WriteLine($"Input: {input}");

So that's not too bad, but the lack of it in lecture notes is worse.

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.