HamBook – Rev 46

Subversion Repositories:
Rev:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace HamBook.Radios.Generic
{
    [XmlRoot(Namespace = "Generic")]
    public abstract class MemoryChannel : IEquatable<MemoryChannel>
    {
        [XmlIgnore]
        public abstract string CurrentLocation { get; set; }
        [XmlIgnore]
        public abstract int Frequency { get; set; }
        [XmlIgnore]
        public abstract string Text { get; set; }
        [XmlIgnore]
        public abstract MemoryRadioMode MemoryRadioMode { get; set; }
        [XmlIgnore]
        public abstract bool Tag { get; set; }

        public MemoryChannel()
        {
        }

        public static MemoryChannel Create(string radio, params object[] param)
        {
            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (var type in assembly.GetTypes())
                {
                    if (typeof(MemoryChannel).IsAssignableFrom(type))
                    {
                        var radioAttribute = type.GetCustomAttribute<RadioAttribute>();

                        if (radioAttribute != null && radioAttribute.Radio == radio)
                        {
                            return (MemoryChannel)Activator.CreateInstance(type, param);
                        }
                    }
                }
            }

            return null;
        }

        public abstract bool Equals(MemoryChannel other);
    }
}