GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - godsharp/FluentMember: Fluent Member Source Generator

BranchesTags
Open more actions menu

Latest commit

 

History

4 Commits
4 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
.nuke
.nuke
 
 
nuke
nuke
 
 
src
src
 
 
test/GodSharp.FluentMember.Test
test/GodSharp.FluentMember.Test
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.release
.release
 
 
Directory.Build.props
Directory.Build.props
 
 
Directory.Build.targets
Directory.Build.targets
 
 
GodSharp.FluentMember.sln
GodSharp.FluentMember.sln
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
azure-pipelines.yml
azure-pipelines.yml
 
 
build.cmd
build.cmd
 
 
build.ps1
build.ps1
 
 
build.sh
build.sh
 
 
global.json
global.json
 
 
icon.png
icon.png
 
 

Repository files navigation

GodSharp.FluentMember

Azure DevOps builds (main) GitHub Workflow Status (branch)

Generate extension method to fluent set member for class, strcut, interface.

Package Version

Name NuGet MyGet
GodSharp.FluentMember NuGet MyGet

Get Started

  • Install Package

    <ItemGroup>
      <PackageReference Include="GodSharp.FluentMember" Version="2021.206.26" />
    </ItemGroup>
  • Add Attribute

    [FluentMemberGenerator(Partial = true)]
    public partial class User
    {
        public int Id { get; internal set; }
        public int Age { get; set; }
        internal string Name { get; set; }
        public string Secret { get; private set; }
        public Role Role { get; set; } = new();
    
        [FluentMemberGenerator(Partial = true)]
        public partial struct Address
        {
            public string Country { get; set; }
            public string City { get; set; }
            internal string Postcode { get; set; }
            public string Secret { get; private set; }
        }
    }
  • Build Project

    You will be use fluent api to set member, like With* and Set method by extension method.

    generated code like this:

    //-----------------------------------------------------------------------   -------
    // <auto-generated>
    //     Generated by SourceGenerator generator at 2022/6/26 15:07:32.
    //     Source: User
    // </auto-generated>
    //------------------------------------------------------------------------------
    
    using System;
    using System.Linq.Expressions;
    using GodSharp.FluentMember;
    
    namespace GodSharpFluentMemberTest;
    
    public partial class User
    {
        internal User WithId(Int32 id)
        {
            this.Id = id;
            return this;
        }
    
        public User WithAge(Int32 age)
        {
            this.Age = age;
            return this;
        }
    
        internal User WithName(String name)
        {
            this.Name = name;
            return this;
        }
    
        public User WithRole(Role role)
        {
            this.Role = role;
            return this;
        }
    
        public User Set<TMember>(Expression<Func<User,TMember>> predicate,  TMember value)
            => TypeSetter.Set(this,predicate,value);
    
    }
    
    public static class UserExtensions
    {
        internal static User WithId(this User user ,Int32 id)
        {
            user.Id = id;
            return user;
        }
    
        public static User WithAge(this User user ,Int32 age)
        {
            user.Age = age;
            return user;
        }
    
        internal static User WithName(this User user ,String name)
        {
            user.Name = name;
            return user;
        }
    
        public static User WithRole(this User user ,Role role)
        {
            user.Role = role;
            return user;
        }
    
        public static User Set<TMember>(this User user,     Expression<Func<User,TMember>> predicate, TMember value)
            => TypeSetter.Set(user, predicate, value);
    
    }

License

MIT

About

Fluent Member Source Generator

Topics

csharp-sourcegeneratorfluentfluent-memberfluentmembersourcegenerator

Resources

Readme
MIT license
Activity
Custom properties

Stars

1 star

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.