Exemplo n.º 1
0
        /// <summary>
        /// 获取事件名称
        /// </summary>
        public virtual string GetEventName()
        {
            var eventName = _eventName;

            if (eventName.IsEmpty())
            {
                var eventType = base.GetType();
                if (!eventType.IsGenericType)
                {
                    eventName = EventNameAttribute.GetNameOrDefault(eventType);
                }
                else
                {
                    var eventNameAttribute = GetType().GetAttribute <GenericEventNameAttribute>();
                    eventName = eventNameAttribute.GetName(eventType);
                }
            }
            return(eventName);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取名称
        /// </summary>
        /// <param name="eventType">事件类型</param>
        public virtual string GetName(Type eventType)
        {
            if (!eventType.IsGenericType)
            {
                throw new Warning($"给定类型不是泛型: {eventType.AssemblyQualifiedName}");
            }
            var genericArguments = eventType.GetGenericArguments();

            if (genericArguments.Length > 1)
            {
                throw new Warning($"给定类型具有多个泛型参数: {eventType.AssemblyQualifiedName}");
            }
            var eventName = EventNameAttribute.GetNameOrDefault(genericArguments[0]);

            if (!Prefix.IsEmpty())
            {
                eventName = $"{Prefix}{eventName}";
            }
            if (!Postfix.IsEmpty())
            {
                eventName = $"{eventName}{Postfix}";
            }
            return(eventName);
        }