1 Star 0 Fork 0

senki/dtomap

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
destclass.go 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
senki 提交于 2020-07-06 16:01 . dtomap
package dtomap
import (
"fmt"
"strings"
)
const (
classStart = "public class %s {"
classField = "%s public %s %s {get;set;}"
classEnd = "}"
separator = "\r\n"
NewClassAStart = "new A(){"
NewClassAField = "%s %s=temp.%s,"
)
type DestClass struct {
Name string
Fields []DestField
}
type DestField struct {
Name string
Type string
}
func (df *DestField) String() string {
return fmt.Sprintf(classField, separator, df.Type, df.Name)
}
func (df *DestField) NewClassString() string {
return fmt.Sprintf(NewClassAField, separator, df.Name, df.Name)
}
/*
public class A{
public int SysNo{get;set;}
public int SysNo2{get;set;}
}
*/
func (dc *DestClass) String() string {
sb := strings.Builder{}
sb.WriteString(fmt.Sprintf(classStart, dc.Name))
for _, field := range dc.Fields {
sb.WriteString(field.String())
}
sb.WriteString(separator)
sb.WriteString(classEnd)
return sb.String()
}
/*
new A(){
SysNo=tmp.SysNo,
SysNo2=tmp.SysNo2
}
*/
func (dc *DestClass) NewClassString() string {
sb := strings.Builder{}
sb.WriteString(NewClassAStart)
for _, field := range dc.Fields {
sb.WriteString(field.NewClassString())
}
sb.WriteString(separator)
sb.WriteString(classEnd)
return sb.String()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/glzsk/dtomap.git
[email protected]:glzsk/dtomap.git
glzsk
dtomap
dtomap
master

搜索帮助