代码模板 使用代码模板生成代码

很简单的东西 用于批量生产代码


Buttons LeftThumbX LeftThumbY LeftTrigger RightThumbX RightThumbY RightTrigger


<TextBlock Text="{0} = " />


<TextBlock Text="{{Binding {0}}}"/>




<StackPanel Grid.Column="0">
   <TextBlock Text="Buttons = " />
   <TextBlock Text="LeftThumbX = " />
   <TextBlock Text="LeftThumbY = " />
   <TextBlock Text="LeftTrigger = " />
   <TextBlock Text="RightThumbX = " />
   <TextBlock Text="RightThumbY = " />
   <TextBlock Text="RightTrigger = " />
</StackPanel>


<StackPanel Grid.Column="1">
   <TextBlock Text="{Binding Buttons}"/>
   <TextBlock Text="{Binding LeftThumbX}"/>
   <TextBlock Text="{Binding LeftThumbY}"/>
   <TextBlock Text="{Binding LeftTrigger}"/>
   <TextBlock Text="{Binding RightThumbX}"/>
   <TextBlock Text="{Binding RightThumbY}"/>
   <TextBlock Text="{Binding RightTrigger}"/>
</StackPanel>
 namespace CodeTemplate
{
    class Program
    {
        static void Main(string[] args)
        {
            var Input = string.Empty;
            while (true)
            {
                Input = Console.ReadLine();
                switch (Input.ToLower())
                {
                    case "?":
                        Help.Instance.Write();
                        break;
                    case "c":
                    case "cls":
                        Console.Clear();
                        break;
                    case "t":
                    case "template":
                        Console.Clear();
                        Template.Instance.ReadTemplate();
                        Console.Clear();
                        break;
                    default:
                        ClearCurrentConsoleLine();
                        BuildCode.Instance.Read(Input);
                        break;
                }

            }
        }

        public static void ClearCurrentConsoleLine()
        {
            int currentLineCursor = Console.CursorTop - 1;
            Console.SetCursorPosition(0, currentLineCursor);
            Console.Write(new string(' ', Console.WindowWidth));
            Console.SetCursorPosition(0, currentLineCursor);
        }
    }
}

 class Template
    {
        static Template _Instance = new Template();
        public static Template Instance
        {
            get
            {
                return _Instance;
            }

        }
        private Template()
        {

        }

        public void ReadTemplate()
        {
            Console.WriteLine("请输入 Template");
            var input = Console.ReadLine();
            var Template = new StringBuilder();
            while (input != "end" && input != "e")
            {
                Template.Append(input);
                input = Console.ReadLine();
            }
            CodeTemplate = Template.ToString();
        }
        public string CodeTemplate { get; private set; }
    } 




class BuildCode
    {
        static BuildCode _Instance = new BuildCode();
        public static BuildCode Instance
        {
            get
            {
                return _Instance;
            }

        }
        private BuildCode()
        {

        }

        public void Read(string Input)
        {
            try
            {
                Console.WriteLine(Template.Instance.CodeTemplate, Input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    } 





[修改于 2 年前 - 2017-04-28 14:41:57]

来自 Windows
2017-4-28 14:20:18
张静茹(作者)
1楼
再举个栗子

变量
LeftThumbX
LeftThumbY
RightThumbX
RightThumbY


模板
public event EventHandler<short> Joypad_{0};
Joypad_{0}?.Invoke(this, JoypadKeyState.Gamepad.{0});



生成结果
public event EventHandler<short> Joypad_LeftThumbX;
public event EventHandler<short> Joypad_LeftThumbY;
public event EventHandler<short> Joypad_RightThumbX;
public event EventHandler<short> Joypad_RightThumbY;


Joypad_LeftThumbX?.Invoke(this, JoypadKeyState.Gamepad.LeftThumbX);
Joypad_LeftThumbY?.Invoke(this, JoypadKeyState.Gamepad.LeftThumbY);
Joypad_RightThumbX?.Invoke(this, JoypadKeyState.Gamepad.RightThumbX);
Joypad_RightThumbY?.Invoke(this, JoypadKeyState.Gamepad.RightThumbY);
折叠评论
加载评论中,请稍候...
折叠评论
张静茹(作者)
2楼
再举个栗子


变量
Y
None
DPadUp
DPadDown
DPadLeft
DPadRight
Start
Back
LeftThumb
RightThumb
LeftShoulder
RightShoulder
A
B
X



模板
public event EventHandler Joypad_{0};
Joypad_{0}?.Invoke(this, EventArgs.Empty);



结果
public event EventHandler Joypad_Y;
public event EventHandler Joypad_None;
public event EventHandler Joypad_DPadUp;
public event EventHandler Joypad_DPadDown;
public event EventHandler Joypad_DPadLeft;
public event EventHandler Joypad_DPadRight;
public event EventHandler Joypad_Start;
public event EventHandler Joypad_Back;
public event EventHandler Joypad_LeftThumb;
public event EventHandler Joypad_RightThumb;
public event EventHandler Joypad_LeftShoulder;
public event EventHandler Joypad_RightShoulder;
public event EventHandler Joypad_A;
public event EventHandler Joypad_B;
public event EventHandler Joypad_X;



Joypad_Y?.Invoke(this, EventArgs.Empty);
Joypad_None?.Invoke(this, EventArgs.Empty);
Joypad_DPadUp?.Invoke(this, EventArgs.Empty);
Joypad_DPadDown?.Invoke(this, EventArgs.Empty);
Joypad_DPadLeft?.Invoke(this, EventArgs.Empty);
Joypad_DPadRight?.Invoke(this, EventArgs.Empty);
Joypad_Start?.Invoke(this, EventArgs.Empty);
Joypad_Back?.Invoke(this, EventArgs.Empty);
Joypad_LeftThumb?.Invoke(this, EventArgs.Empty);
Joypad_RightThumb?.Invoke(this, EventArgs.Empty);
Joypad_LeftShoulder?.Invoke(this, EventArgs.Empty);
Joypad_RightShoulder?.Invoke(this, EventArgs.Empty);
Joypad_A?.Invoke(this, EventArgs.Empty);
Joypad_B?.Invoke(this, EventArgs.Empty);
Joypad_X?.Invoke(this, EventArgs.Empty);
折叠评论
加载评论中,请稍候...
折叠评论
2017-4-29 01:32:43
3楼

做了个C语言窗口版的

codetemp.rar358k4次



[修改于 2 年前 - 2017-05-17 17:15:16]

折叠评论
加载评论中,请稍候...
折叠评论
2018-3-2 10:29:27
2018-3-2 10:29:27
张静茹(作者)
4楼
正确方法是使用 Visual Stuidio的 T4 模板  方便 功能强大的多。。。。。。
折叠评论
加载评论中,请稍候...
折叠评论

想参与大家的讨论?现在就 登录 或者 注册

插入资源
全部
图片
视频
音频
附件
全部
未使用
已使用
正在上传
空空如也~
上传中..{{f.progress}}%
处理中..
上传失败,点击重试
{{f.name}}
空空如也~
(视频){{r.oname}}
{{selectedResourcesId.indexOf(r.rid) + 1}}
ID:{{user.uid}}
{{user.username}}
{{user.info.certsName}}
{{user.description}}
{{format("YYYY/MM/DD", user.toc)}}注册,{{fromNow(user.tlv)}}活动
{{submitted?"":"投诉"}}
请选择违规类型:
{{reason.description}}
支持的图片格式:jpg, jpeg, png