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

📄 field.cs

📁 pureIRCd是一个用c语音写的irc(RFC459)服务,可以给您带来很多的方便
💻 CS
字号:
using System.Runtime.Serialization;
using System;
using System.Collections.Generic;

namespace SDP
{
    /// <summary>
    /// A Field represents a single line of information in a SessionDescription.
    /// </summary>
    public abstract class Field
    {
        private static Dictionary<string, Type> fields = new Dictionary<string, Type>();

        /// <summary>
        /// Allows constructors of descendants to set the TypeCharacter
        /// </summary>
        protected char typechar;
        /// <summary>
        /// Gets the type character for the field.
        /// </summary>
        public virtual char TypeCharacter
        {
            get { return this.typechar; }
        }

        /// <summary>
        /// Allows constructors of descendants to set the value.
        /// </summary>
        protected string value;
        /// <summary>
        /// Gets the value of this field.
        /// </summary>
        public virtual string Value
        {
            get { return this.value; }
        }

        /// <summary>
        /// Creates a new Field.
        /// </summary>
        /// <param name="type">The type of the field. For example "a" for attribute.</param>
        /// <param name="value">The value of the field. Anything to the right of but not including the "="</param>
        public Field(string type, string value)
        {
            this.typechar = Convert.ToChar(type);
            this.value = value;
        }

        /// <summary>
        /// Creates a new Field.
        /// </summary>
        /// <param name="field">The full field.</param>
        public Field(string field)
        {
            string[] parts = field.Split('=');
            if (parts.Length != 2) throw new ArgumentException("Invalid field");
            this.typechar = Convert.ToChar(parts[0]);
            this.value = parts[1].Trim();
        }

        /// <summary>
        /// Allows descendants to create a field without using one of the public constructors.
        /// </summary>
        protected Field() { }

        static Field()
        {
            fields.Add("v", typeof(VersionField));
            fields.Add("o", typeof(OriginField));
            fields.Add("i", typeof(InfoField));
            fields.Add("u", typeof(UriField));
            fields.Add("e", typeof(EMailField));
            fields.Add("p", typeof(PhoneField));
            fields.Add("c", typeof(ConnectionField));
            fields.Add("b", typeof(BandwidthField));
            fields.Add("z", typeof(TimeZoneAdjustmentField));
            fields.Add("k", typeof(KeyField));
            fields.Add("a", typeof(AttributeField));
            fields.Add("t", typeof(TimeField));
            fields.Add("r", typeof(TimeRepetitionField));
            fields.Add("m", typeof(MediaField));
        }

        /// <summary>
        /// Creates a new Field. This method determines which subclass of Field to instantiate.
        /// </summary>
        /// <param name="field">The full field, denoted [type]=[value]\r\n</param>
        /// <returns></returns>
        public static Field Create(string field)
        {
            string[] parts = field.Split('=');
            if (parts.Length != 2) throw new ArgumentException("Invalid field");
            if (!fields.ContainsKey(parts[0])) throw new ArgumentException();
            Type t = fields[parts[0]];
            return Activator.CreateInstance(t, parts[1].Trim()) as Field;
        }

        /// <summary>
        /// Converts a Field to it's string representation.
        /// </summary>
        /// <returns>A string.</returns>
        public override string ToString()
        {
            return String.Format("{0}={1}\r\n", this.TypeCharacter, this.Value);
        }
    }
}

⌨️ 快捷键说明

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