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

📄 gpmessagemethodattribute.cs

📁 Gibphone is CSharp Program, it can tell you how to design p2p chat.
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using GPCore.Args;
using GPCore.Protocols;

namespace GPCore
{
    [global::System.AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
    sealed class GPMessageMethodAttribute : Attribute , IGPMethodAttribute
    {
        // See the attribute guidelines at 
        //  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconusingattributeclasses.asp
    
        public GPMessageMethodAttribute()
        {
        }
        #region IGPMethodAttribute Members

        public bool Show(object target, GPCore.Protocols.IProtocol caller)
        {
            Type t = target.GetType();
            return t == typeof(User) || typeof(IIdable).IsAssignableFrom(t);
        }

        public void PerformAction(object target, GPCore.Protocols.IProtocol caller, System.Reflection.MethodInfo method)
        {
            if (target is User)
            {
                Form f;
                Dictionary<string, Type> d = new Dictionary<string, Type>();
                d.Add("Screen name", typeof(String));
                f = GPArgumentMethodAttribute.CreateForm(d);
                if (f.ShowDialog() == DialogResult.OK)
                {
                    string s = f.GetType().GetField("Screen_name").GetValue(f) as string;
                    Protocols.Message.MessageRecieved.Fire(caller as IMessage, new MessageArgs("", s));
                }
            }
            else if (target is SqlGroup)
            {
                SqlGroup g = (SqlGroup)target;
                foreach (IIdable id in g)
                {
                    PerformAction(id, caller, method);
                }
            }
            else if (target is SqlGib)
            {
                SqlGib g = (SqlGib)target;
                SqlAccount a = g.DefaultAccount;
                Protocols.Message.MessageRecieved.Fire(caller as IMessage, new MessageArgs("", a.Username));
            }
            else if (target is SqlAccount)
            {
                SqlAccount a = (SqlAccount)target;
                Protocols.Message.MessageRecieved.Fire(caller as IMessage, new MessageArgs("", a.Username));
            }
        }

        public string Name
        {
            get { return "Send Message"; }
        }

        public Type Action
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }

        #endregion
    }

}

⌨️ 快捷键说明

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