TableCraft.Core 1.0.2

dotnet add package TableCraft.Core --version 1.0.2
NuGet\Install-Package TableCraft.Core -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TableCraft.Core" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TableCraft.Core --version 1.0.2
#r "nuget: TableCraft.Core, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TableCraft.Core as a Cake Addin
#addin nuget:?package=TableCraft.Core&version=1.0.2

// Install TableCraft.Core as a Cake Tool
#tool nuget:?package=TableCraft.Core&version=1.0.2

TableCraft.Core

Commitizen friendly

Overview

TableCraft.Core is a .NET library that can extract key information (such as configuration file names and field names) from different types of configuration files based on rules. It also uses additional description files to supplement information about field types and labels, and outputs complete configuration file information in the specified JSON format.

In addition, TableCraft.Core can use this configuration file information to generate any text you want based on the template you provide (which is very useful for generating code files with repeated rules).

Features

  • Declare available field value types and collection types
  • Add labels to fields for special handling when generating text (such as primary keys in tables)
  • Support configuration files/data sources of different file types (currently only CSV is supported)
  • Support data description of different file types (currently only JSON is supported)
  • Text template rendering based on T4 Text Templates, generate business code in any language using the API provided by TableCraft.Core, modify generation rules without recompiling
  • Provide version control support (currently only Perforce)

Example

Assuming we have a Students.csv file:

ID ClassID Name Age Courses
0 1 Edward 24 CS61A;MIT18.01;MIT18.06
1 1 Alex 24 UCB CS61B;MIT 6.006

By supplementing field types, tags, etc. through an additional JSON file:

{
    "ConfigName" : "Students",
    "Usage"      : {
        "usage0" : {
            "ExportName" : "StudentsTable"
        }
    },
    "Attributes" : [
        {
            "AttributeName" : "ID",
            "Comment"       : "Identifier",
            "ValueType"     : "int",
            "DefaultValue"  : "",
            "CollectionType" : "none",
            "Usages"         : [
                {
                    "Usage" : "usage0",
                    "FieldName" : "ID"
                }
            ],
            "Tag"            : [
                "primary"
            ]
        },
        // ...
    ]
}

Completing such a JSON configuration file on your own may be frustrating. You can develop your own visualization tool and integrate it with TableCraft.Core to generate the JSON file; or you can take a look at TableCraft.Editor, which is a visual tool example based on AvaloniaUI.

Now by completing a text template (.tt) to simply describe your generation rules:

<#@ template debug="true" hostspecific="true" language="C#" #>
<#@ parameter type="System.String" name="CurrentUsage"#>
<#
    var configInfoObject = Host.GetHostOption("CurrentConfigInfo");
    var configInfo = configInfoObject as ConfigInfo;
    if (configInfo == null) throw new Exception("null CurrentConfigInfo received, exit!");
#>
namespace Foo {
    public class <#= configInfo.GetExportName(CurrentUsage) #> {
<# 
    foreach( var info in configInfo.AttributeInfos ){ 
        if(info.IsValid() && info.HasUsage(CurrentUsage)){
#>
            public <#= info.ValueType #> <#= info.GetUsageFieldName(CurrentUsage) #> { get; private set; }
<#
        }
    }
#>
    }
}

Congratulations! TableCraft.Core will now output the following results for you:

namespace Foo {
    public class StudentsTable {
            public int ID { get; private set; }
            public uint ClassID { get; private set; }
            public string Name { get; private set; }
            public uint Age { get; private set; }
            public string Courses { get; private set; }
    }
}

Configuration

libenv.json

To use the TableCraft.Core runtime library, you need to configure the libenv.json file and pass it in through the TableCraft.Core.Configuration.ReadConfigurationFromJson method for initialization before use.

{
    // Define data value types
    "DataValueType": ["int", "uint", "float", "boolean", "string"],
    // Define collection types
    "DataCollectionType": ["none", "array"],
    // Define available field tags
    "AttributeTag": ["primary", "label1", "label2"],
    // TableCraft uses UTF8 encoding by default. Specify whether a BOM header is needed here.
    "UTF8BOM": false,
     // For csv type data source files, specify the row number where field names are located and where comments are located (if they do not exist, fill in -1).
     "CsvSource":{
        "HeaderLineIndex": 0,
        "CommentLineIndex": 1
     },
     // Specify various export code methods.
    "ConfigUsageType":{
        "usage0":{
            // T4 template file used to generate code. This file needs to be placed in the Templates directory at the same level as the executable file.
            "CodeTemplateName":"usage0-template.tt",
            // The type of generated file. In this example, c# code is generated.
            "TargetFileType":".cs",
            // The format string of the generated file name, if this string contains a file type, it will be replaced by TargetFileType
            "OutputFormat": "{0}_base"
        }
     },
    // Specify group to support exporting multiple files for each usage
    "ConfigUsageGroup":{
        "group0":[
            "usage0",
            "usage1"
        ]
    }
}

License

MIT

Copyright (c) 2023 - Boming Chen

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 143 7/13/2023
1.0.1 111 7/12/2023
1.0.0 134 7/12/2023

# Changelog

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### 1.0.2 (2023-07-13)


### Bug Fixes

* remove duplicated README.md ([a032ce2](https://github.com/kalulas/TableCraft.Core/commit/a032ce2d833d648d563037e6c87e2e6ba48673a7))

### 1.0.1 (2023-07-12)