⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tag.cs

📁 代码模版 codtemplate
💻 CS
字号:
using System;
using System.Collections;
using System.Windows.Forms;

namespace CodeTemplate
{
	internal enum TagControlType 
	{
		SingleLineControl,
		MultiLineControl,
		DropDownControl,
		DropDownListControl
	}

	internal class Tag
    {
		public Tag(String text, String rawTag)
        {
            m_formats = new FormatList();
			m_rawTag = rawTag;

            parseTag(text);
        }

        public String Name
        {
            get { return m_name; }
        }

		public String RawTag
		{
			get { return m_rawTag; }
		}

        public Boolean IsPrompt
        {
            get { return m_prompt; }
        }

		public Boolean IsCombo
		{
			get { return this.ControlType == TagControlType.DropDownControl || this.ControlType == TagControlType.DropDownListControl; }
		}

		public Boolean IsNestedTemplate
		{
			get { return String.Compare(this.Name, s_nestedTemplateKeyword, true) == 0; }
		}

		public TagControlType ControlType
		{
			get { return m_controlType; }
		}

        public FormatList Formats
        {
            get { return m_formats; }
        }

        public Object Value
        {
            get { return m_value; }
            set { m_value = value; }
        }
		
		public override Boolean Equals(Object obj)
		{
			if(obj == null || GetType() != obj.GetType()) 
				return false;

			Tag tag = (Tag)obj;			
			return this.Name.ToUpper() == tag.Name.ToUpper();
		}

		public override Int32 GetHashCode() 
		{
			return this.Name.ToUpper().GetHashCode();
		}

        private Int32 extractFormat(String tag, Int32 pos, out String fmtSpec, out String fmtArgs)
        {
            Int32 startPos = pos + 1;
            pos = tag.IndexOf(':', startPos);

            Int32 length = (pos == -1) ? tag.Length - startPos : pos - startPos;
            String fmt = tag.Substring(startPos, length);

            Int32 i = fmt.IndexOf('=');
            if(i != -1)
            {
                fmtSpec = fmt.Substring(0, i);
                fmtArgs = fmt.Substring(i + 1);
            }

            else
            {
                fmtSpec = fmt;
                fmtArgs = null;
            }

            return pos;
        }

        private void parseTag(String tag)
        {
            m_prompt = (tag[0] == '?');

            Int32 colonPos = tag.IndexOf(':');
            Int32 length = (colonPos == -1) ? tag.Length : colonPos;
            Int32 startPos = 0;

            if(m_prompt)
            {
                ++startPos;
                --length;
            }

            m_name = tag.Substring(startPos, length);

            while(colonPos != -1)
            {
                String fmtSpec, fmtArgs;
                colonPos = extractFormat(tag, colonPos, out fmtSpec, out fmtArgs);
                
				if(fmtSpec.Length > 0)
				{
					switch(fmtSpec.ToUpper())
					{
						case "VALUES": 
							m_controlType = TagControlType.DropDownControl; 
							break;

						case "FIXEDVALUES":
							m_controlType = TagControlType.DropDownListControl;
							break;

						case "MULTILINE":
							m_controlType = TagControlType.MultiLineControl;
							break;

						default:
							m_controlType = TagControlType.SingleLineControl;
							break;
					}

					if(fmtArgs == null || fmtArgs.Length == 0)
						m_controlType = TagControlType.SingleLineControl;

					m_formats.Add(fmtSpec, fmtArgs);
				}
            }
        }

        private String m_name;
		private String m_rawTag;
        private Boolean m_prompt;
		private TagControlType m_controlType;
        private FormatList m_formats;
        private Object m_value;
		private const String s_nestedTemplateKeyword = "TEMPLATE";
    };
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -