![]() |
VOOZH | about |
dotnet add package TableCraft.Core --version 1.0.2
NuGet\Install-Package TableCraft.Core -Version 1.0.2
<PackageReference Include="TableCraft.Core" Version="1.0.2" />
<PackageVersion Include="TableCraft.Core" Version="1.0.2" />Directory.Packages.props
<PackageReference Include="TableCraft.Core" />Project file
paket add TableCraft.Core --version 1.0.2
#r "nuget: TableCraft.Core, 1.0.2"
#:package TableCraft.Core@1.0.2
#addin nuget:?package=TableCraft.Core&version=1.0.2Install as a Cake Addin
#tool nuget:?package=TableCraft.Core&version=1.0.2Install as a Cake Tool
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).
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; }
}
}
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"
]
}
}
Copyright (c) 2023 - Boming Chen
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
# 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)