本文整理汇总了C#中Registry.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# Registry.FirstOrDefault方法的具体用法?C# Registry.FirstOrDefault怎么用?C# Registry.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Registry
的用法示例。
在下文中一共展示了Registry.FirstOrDefault方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Portal
/// <summary>
/// Makes portal from config.
/// Due to the nature of Portal object there is no need to create other parametrized ctors
/// </summary>
protected Portal(IConfigSectionNode conf)
{
const string PORTAL = "portal";
m_Name = conf.AttrByName(Configuration.CONFIG_NAME_ATTR).Value;
if (m_Name.IsNullOrWhiteSpace())
{
m_Name = this.GetType().Name;
if (m_Name.EndsWith(PORTAL, StringComparison.OrdinalIgnoreCase) && m_Name.Length>PORTAL.Length)
m_Name = m_Name.Substring(0, m_Name.Length-PORTAL.Length);
}
m_Description = conf.AttrByName(CONFIG_DESCR_ATTR).ValueAsString(m_Name);
m_Offline = conf.AttrByName(CONFIG_OFFLINE_ATTR).ValueAsBool(false);
m_Default = conf.AttrByName(CONFIG_DEFAULT_ATTR).ValueAsBool(false);
var puri = conf.AttrByName(CONFIG_PRIMARY_ROOT_URI_ATTR).Value;
try{ m_PrimaryRootUri = new Uri(puri, UriKind.Absolute); }
catch(Exception error)
{
throw new WaveException(StringConsts.CONFIG_PORTAL_ROOT_URI_ERROR.Args(m_Name, error.ToMessageWithType()), error);
}
m_Themes = new Registry<Theme>();
var nthemes = conf.Children.Where(c => c.IsSameName(CONFIG_THEME_SECTION));
foreach(var ntheme in nthemes)
{
var theme = FactoryUtils.Make<Theme>(ntheme, args: new object[]{this, ntheme});
if(!m_Themes.Register(theme))
throw new WaveException(StringConsts.CONFIG_PORTAL_DUPLICATE_THEME_NAME_ERROR.Args(theme.Name, m_Name));
}
if (m_Themes.Count==0)
throw new WaveException(StringConsts.CONFIG_PORTAL_NO_THEMES_ERROR.Args(m_Name));
m_DefaultTheme = m_Themes.FirstOrDefault(t => t.Default);
if (m_DefaultTheme==null)
throw new WaveException(StringConsts.CONFIG_PORTAL_NO_DEFAULT_THEME_ERROR.Args(m_Name));
ConfigAttribute.Apply(this, conf);
}//.ctor
示例2: Portal
/// <summary>
/// Makes portal from config.
/// Due to the nature of Portal object there is no need to create other parametrized ctors
/// </summary>
protected Portal(IConfigSectionNode conf)
: base(PortalHub.Instance)
{
const string PORTAL = "portal";
m_Name = conf.AttrByName(Configuration.CONFIG_NAME_ATTR).Value;
if (m_Name.IsNullOrWhiteSpace())
{
m_Name = this.GetType().Name;
if (m_Name.EndsWith(PORTAL, StringComparison.OrdinalIgnoreCase) && m_Name.Length>PORTAL.Length)
m_Name = m_Name.Substring(0, m_Name.Length-PORTAL.Length);
}
//Register with the Hub
if (!PortalHub.Instance.m_Portals.Register( this ))
throw new WaveException(StringConsts.PORTAL_HUB_INSTANCE_ALREADY_CONTAINS_PORTAL_ERROR.Args(m_Name));
m_Description = conf.AttrByName(CONFIG_DESCR_ATTR).ValueAsString(m_Name);
m_Offline = conf.AttrByName(CONFIG_OFFLINE_ATTR).ValueAsBool(false);
m_Default = conf.AttrByName(CONFIG_DEFAULT_ATTR).ValueAsBool(false);
var puri = conf.AttrByName(CONFIG_PRIMARY_ROOT_URI_ATTR).Value;
try{ m_PrimaryRootUri = new Uri(puri, UriKind.Absolute); }
catch(Exception error)
{
throw new WaveException(StringConsts.CONFIG_PORTAL_ROOT_URI_ERROR.Args(m_Name, error.ToMessageWithType()), error);
}
m_DisplayName = conf.AttrByName(CONFIG_DISPLAY_NAME_ATTR).Value;
if (m_DisplayName.IsNullOrWhiteSpace())
m_DisplayName = m_PrimaryRootUri.ToString();
m_Themes = new Registry<Theme>();
var nthemes = conf.Children.Where(c => c.IsSameName(CONFIG_THEME_SECTION));
foreach(var ntheme in nthemes)
{
var theme = FactoryUtils.Make<Theme>(ntheme, args: new object[]{this, ntheme});
if(!m_Themes.Register(theme))
throw new WaveException(StringConsts.CONFIG_PORTAL_DUPLICATE_THEME_NAME_ERROR.Args(theme.Name, m_Name));
}
if (m_Themes.Count==0)
throw new WaveException(StringConsts.CONFIG_PORTAL_NO_THEMES_ERROR.Args(m_Name));
m_DefaultTheme = m_Themes.FirstOrDefault(t => t.Default);
if (m_DefaultTheme==null)
throw new WaveException(StringConsts.CONFIG_PORTAL_NO_DEFAULT_THEME_ERROR.Args(m_Name));
m_ParentName = conf.AttrByName(CONFIG_PARENT_NAME_ATTR).Value;
ConfigAttribute.Apply(this, conf);
m_LocalizableContent = new Dictionary<string,string>(GetLocalizableContent(), StringComparer.InvariantCultureIgnoreCase);
foreach(var atr in conf[CONFIG_LOCALIZATION_SECTION][CONFIG_CONTENT_SECTION].Attributes)
m_LocalizableContent[atr.Name] = atr.Value;
var gen = conf[CONFIG_RECORD_MODEL_SECTION];
m_RecordModelGenerator = FactoryUtils.Make<Client.RecordModelGenerator>(gen,
typeof(Client.RecordModelGenerator),
new object[]{gen});
m_RecordModelGenerator.ModelLocalization += recGeneratorLocalization;
m_LocalizationData = conf[CONFIG_LOCALIZATION_SECTION];
var msgFile = m_LocalizationData.AttrByName(CONFIG_MSG_FILE_ATTR).Value;
if (msgFile.IsNotNullOrWhiteSpace())
try
{
m_LocalizationData = Configuration.ProviderLoadFromFile(msgFile).Root;
}
catch(Exception fileError)
{
throw new WaveException(StringConsts.CONFIG_PORTAL_LOCALIZATION_FILE_ERROR.Args(m_Name, msgFile, fileError.ToMessageWithType()), fileError);
}
}