/// <summary> /// 得到功能块的后缀描述字符串。 /// </summary> /// <param name="type">后缀描述字符串类型</param> /// <returns>功能块的后缀描述字符串。</returns> public string GetSuffixDecl(ViFirmBlockSuffixType type) { string decl = string.Empty; if (((uint)(type & ViFirmBlockSuffixType.Modes)) != 0) { decl += "#Modes:" + this.ModesDecl; } else if (((uint)(type & ViFirmBlockSuffixType.SModes)) != 0) { decl += "#" + this.ModesDecl; } if (((uint)(type & ViFirmBlockSuffixType.FWLibrary)) != 0) { string fwLibraryDecl = this.FWLibraryDecl; if (!string.IsNullOrEmpty(fwLibraryDecl)) { decl += "#FwLib:" + fwLibraryDecl; } } if (((uint)(type & ViFirmBlockSuffixType.Comment)) != 0) { string comment = this.Comment; if (!string.IsNullOrEmpty(comment)) { decl += "@" + comment; } } return(decl); }
/// <summary> /// 将对象转化成字符串显示。 /// </summary> /// <param name="comment">是否包含注释信息?</param> /// <param name="leading">每行的前缀</param> /// <param name="tabbing">每个缩进的字符串</param> /// <param name="suffixType">功能块后缀描述类型</param> /// <returns>对象的字符串显示。</returns> public virtual string ToString(bool comment, string leading, string tabbing, ViFirmBlockSuffixType suffixType) { if (leading == null) { leading = string.Empty; } if (tabbing == null) { tabbing = string.Empty; } string str = leading, prefix; if (this.IsFunctionBlock) { str += string.Format("{0} {1}\n", "FUNCTION_BLOCK", this.Name); } else { str += string.Format("{0} {1} : {2}\n", "FUNCTION", this.Name, this.Type.Name); } // Task Usage if (comment) { str += string.Format("\n{0}(* task usage: {1} *)\n\n", leading, this.ModesDecl); } // INPUT if (this.InOutConnectorCount < this.InputConnectors.Count) { str += leading + tabbing + "VAR_INPUT\n"; prefix = leading + tabbing + tabbing; for (int i = this.InOutConnectorCount; i < this.InputConnectors.Count; ++i) { ViConnType connType = this.InputConnectors[i]; str += string.Format("{0}{1}\n", prefix, connType.ToString(comment)); } str += leading + tabbing + "END_VAR\n"; } // OUTPUT if (this.InOutConnectorCount < this.OutputConnectors.Count) { str += leading + tabbing + "VAR_OUTPUT\n"; prefix = leading + tabbing + tabbing; for (int i = this.InOutConnectorCount; i < this.OutputConnectors.Count; ++i) { ViConnType connType = this.OutputConnectors[i]; str += string.Format("{0}{1}\n", prefix, connType.ToString(comment)); } str += leading + tabbing + "END_VAR\n"; } // IN_OUT if (this.InOutConnectorCount > 0) { str += leading + tabbing + "VAR_IN_OUT\n"; prefix = leading + tabbing + tabbing; for (int i = 0; i < this.InOutConnectorCount; ++i) { ViConnType connType = this.InputConnectors[i]; str += string.Format("{0}{1}\n", prefix, connType.ToString(comment)); } str += leading + tabbing + "END_VAR\n"; } if (this.IsFunctionBlock) { str += string.Format("{0}{1}", leading, "END_FUNCTION_BLOCK"); } else { str += string.Format("{0}{1}", leading, "END_FUNCTION"); } // Suffix Decl str += string.Format("{0}{1}", this.GetSuffixDecl(suffixType), "\n"); return(str); }