?? field.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 + -