当前位置: 首页>>代码示例>>C#>>正文


C# Enum.TryGetAttribute方法代码示例

本文整理汇总了C#中System.Enum.TryGetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# Enum.TryGetAttribute方法的具体用法?C# Enum.TryGetAttribute怎么用?C# Enum.TryGetAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Enum的用法示例。


在下文中一共展示了Enum.TryGetAttribute方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Add

        public void Add(Enum key)
        {
            var logger = ObjectFactory.GetInstance<Logger>();

            if (key == null)
            {
                logger.Error("[ViewModels].[Application].[NotificationSet].[Add] throwing exception ([key] == null).");
                throw new ArgumentNullException("key");
            }

            if (notifications.Contains(key))
            {
                logger.Error("[ViewModels].[Application].[NotificationSet].[Add] throwing exception ([notifications] already contains [key]).");
                throw new ArgumentException("NotificationSet already contains this notification.", "key");
            }

            var attribute = key.TryGetAttribute<NotificationAttribute>();
            if (attribute == null)
            {
                logger.Error("[ViewModels].[Application].[NotificationSet].[Add] throwing exception ([attribute] == null).");
                throw new ArgumentException("Item does not has NotificationAttribute.", "key");
            }

            notifications.Add(key);
        }
开发者ID:vitalyobukhov,项目名称:SmsToMail,代码行数:25,代码来源:NotificationSet.cs

示例2: TryAdd

        public bool TryAdd(Enum key)
        {
            var result = false;

            if (key != null && !notifications.Contains(key))
            {
                var attribute = key.TryGetAttribute<NotificationAttribute>();

                if (attribute != null)
                {
                    notifications.Add(key);
                    result = true;
                }
            }

            return result;
        }
开发者ID:vitalyobukhov,项目名称:SmsToMail,代码行数:17,代码来源:NotificationSet.cs

示例3: TryGet

        public NotificationItem TryGet(Enum key)
        {
            NotificationItem result = null;

            if (key != null && notifications.Contains(key))
            {
                var attribute = key.TryGetAttribute<NotificationAttribute>();
                if (attribute != null)
                {
                    result = new NotificationItem(attribute.Message, attribute.Type);
                }
            }

            return result;
        }
开发者ID:vitalyobukhov,项目名称:SmsToMail,代码行数:15,代码来源:NotificationSet.cs

示例4: Get

        public NotificationItem Get(Enum key)
        {
            var logger = ObjectFactory.GetInstance<Logger>();

            if (key == null)
            {
                logger.Error("[ViewModels].[Application].[NotificationSet].[Get] throwing exception ([key] == null).");
                throw new ArgumentNullException("key");
            }

            if (!notifications.Contains(key))
            {
                logger.Error("[ViewModels].[Application].[NotificationSet].[Get] throwing exception ([notifications] does not contains [key]).");
                throw new ArgumentException("NotificationSet does not contains this notification.", "key");
            }

            var attribute = key.TryGetAttribute<NotificationAttribute>();
            if (attribute == null)
            {
                logger.Error("[ViewModels].[Application].[NotificationSet].[Get] throwing exception ([attribute] == null).");
                throw new ArgumentException("Item does not has NotificationAttribute.", "key");
            }

            return new NotificationItem(attribute.Message, attribute.Type);
        }
开发者ID:vitalyobukhov,项目名称:SmsToMail,代码行数:25,代码来源:NotificationSet.cs


注:本文中的System.Enum.TryGetAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。