本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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);
}