本文整理汇总了C#中Collection.OfType方法的典型用法代码示例。如果您正苦于以下问题:C# Collection.OfType方法的具体用法?C# Collection.OfType怎么用?C# Collection.OfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collection
的用法示例。
在下文中一共展示了Collection.OfType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetFilterAttributeFilterProvider
private static void SetFilterAttributeFilterProvider(this IContainer container, Collection<IFilterProvider> filterProviders = null)
{
filterProviders = filterProviders ?? FilterProviders.Providers;
var filterAttributeFilterProviders = filterProviders.OfType<FilterAttributeFilterProvider>().ToArray();
for (var i = filterAttributeFilterProviders.Length - 1; i >= 0; --i)
{
filterProviders.RemoveAt(i);
}
var filterProvider = new DryIocFilterAttributeFilterProvider(container);
filterProviders.Add(filterProvider);
container.RegisterInstance<IFilterProvider>(filterProvider);
}
示例2: ChangeTheme
private static void ChangeTheme(Collection<ResourceDictionary> mergedDictionaries, ThemeTones tone, Color accentColor)
{
var metroDictionaries = mergedDictionaries.OfType<MetroDictionary>().ToArray();
foreach (var d in metroDictionaries)
mergedDictionaries.Remove(d);
if (tone == ThemeTones.None)
return;
ResourceDictionary toneDictionary = null;
switch (tone)
{
case ThemeTones.Light:
toneDictionary = GetThemeResourceDictionary("StyleLight");
break;
case ThemeTones.Dark:
toneDictionary = GetThemeResourceDictionary("StyleDark");
break;
}
var accentDictionary = CreateAccentDictionary(accentColor);
mergedDictionaries.Add(toneDictionary);
mergedDictionaries.Add(accentDictionary);
foreach (var s in StyleFiles)
{
var dict = GetThemeResourceDictionary(s);
dict.MergedDictionaries.Add(toneDictionary);
dict.MergedDictionaries.Add(accentDictionary);
mergedDictionaries.Add(dict);
}
}
示例3: MapConfigurationSets
public static IList<MCM.ConfigurationSet> MapConfigurationSets(Collection<ConfigurationSet> configurationSets)
{
var result = new Collection<Management.Compute.Models.ConfigurationSet>();
foreach (var networkConfig in configurationSets.OfType<NetworkConfigurationSet>())
{
result.Add(Mapper.Map<Management.Compute.Models.ConfigurationSet>(networkConfig));
}
foreach (var windowsConfig in configurationSets.OfType<WindowsProvisioningConfigurationSet>())
{
var newWinCfg = Mapper.Map<Management.Compute.Models.ConfigurationSet>(windowsConfig);
if (windowsConfig.WinRM != null)
{
newWinCfg.WindowsRemoteManagement = new WindowsRemoteManagementSettings();
// AutoMapper doesn't work for WinRM.Listeners -> WindowsRemoteManagement.Listeners
if (windowsConfig.WinRM.Listeners != null)
{
foreach (var s in windowsConfig.WinRM.Listeners)
{
newWinCfg.WindowsRemoteManagement.Listeners.Add(new WindowsRemoteManagementListener
{
ListenerType = (VirtualMachineWindowsRemoteManagementListenerType)Enum.Parse(typeof(VirtualMachineWindowsRemoteManagementListenerType), s.Protocol, true),
CertificateThumbprint = s.CertificateThumbprint
});
}
}
}
result.Add(newWinCfg);
}
foreach (var linuxConfig in configurationSets.OfType<LinuxProvisioningConfigurationSet>())
{
result.Add(Mapper.Map<Management.Compute.Models.ConfigurationSet>(linuxConfig));
}
return result;
}
示例4: ApplyTheme
private static void ApplyTheme(Collection<ResourceDictionary> mergedDictionaries, Uri dictionaryUri)
{
if (mergedDictionaries == null) return;
using (var d = Application.Current.Dispatcher.DisableProcessing())
{
try
{
ThemeResourceDictionary themeDictionary = null;
if (dictionaryUri != null)
{
themeDictionary = new ThemeResourceDictionary();
themeDictionary.Source = dictionaryUri;
}
// Find if the target element already has a theme applied
// we always want to remove them in case 'None' was selected.
var existingDictionaries = mergedDictionaries
.OfType<ThemeResourceDictionary>()
.ToList();
// Remove the existing dictionaries
foreach (ThemeResourceDictionary thDictionary in existingDictionaries)
{
mergedDictionaries.Remove(thDictionary);
}
if (themeDictionary != null)
{
// Add the new dictionary to the collection of merged dictionaries of the target object
mergedDictionaries.Insert(0, themeDictionary);
}
}
finally { }
}
}