12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace IntelligentControlForsx.CodeGenerator
- {
- public class CodeGenerator
- {
- public static string Generate(string clsName, string[] varArray)
- {
- StringBuilder sbVarDelare = new StringBuilder();
- for(int i=1;i<varArray.Length;i++)
- {
- string varDelareField = string.Format(VarDeclare, i, varArray[i]);
- sbVarDelare.AppendLine(varDelareField);
- }
- StringBuilder sbAssignment = new StringBuilder();
- for (int i = 1; i < varArray.Length; i++)
- {
- string varDelareField = string.Format(Assignment, i-1, varArray[i]);
- sbAssignment.AppendLine(varDelareField);
- }
- return string.Format(Outline, clsName, varArray[0],
- sbVarDelare.ToString(), sbAssignment.ToString());
- }
- #region 代码模版
- public const string Outline = @"
- using System;
- using System.ComponentModel;
- using System.Runtime.CompilerServices;
- namespace GdxnyWindTurbineContorls.CodeGenerator
- {{
- public class {0} : TableModel
- {{
- public {0}(string deviceName) : base(deviceName)
- {{
- this.deviceId = deviceName;
- }}
- public string {1}
- {{
- get {{ return deviceId;}}
- set {{
- if (value != this.deviceId)
- {{
- this.deviceId = value;
- NotifyPropertyChanged();
- }}
- }}
- }}
- {2}
- public override void bindingData(double[] vals)
- {{
- {3}
- }}
- }}
- }}
- ";
- public const string VarDeclare = @"
- private string var{0} =""0.00"";
- public string {1}
- {{
- get {{ return var{0}; }}
- set
- {{
- if (value != this.var{0})
- {{
- this.var{0} = value;
- NotifyPropertyChanged();
- }}
- }}
- }}
- ";
- public const string Assignment = "this.{1} = vals[{0}].ToString(\"f2\");";
- #endregion
- }
- }
|