private static IEnumerable <ThemePart> LoadThemeParts(Assembly assembly) { if (assembly.HasAttribute <ThemeAssemblyAttribute>(false) == false) { yield break; } var themeParts = new Dictionary <string, Tuple <string, string> >(); foreach (var resourceUri in assembly.EnumerateEmbeddedResources()) { if (resourceUri.EndsWith(".themepart.xml", StringComparison.OrdinalIgnoreCase)) { var themePartName = resourceUri.LeftOf(".themepart", StringComparison.OrdinalIgnoreCase); var themePartTuple = themeParts.GetValueOrCreate(themePartName, n => new Tuple <string, string>(resourceUri, null)); themeParts[themePartName] = new Tuple <string, string>(resourceUri, themePartTuple.Item2); } else if (resourceUri.EndsWith(".themepart.zip", StringComparison.OrdinalIgnoreCase)) { var themePartName = resourceUri.LeftOf(".themepart", StringComparison.OrdinalIgnoreCase); var themePartTuple = themeParts.GetValueOrCreate(themePartName, n => new Tuple <string, string>(null, resourceUri)); themeParts[themePartName] = new Tuple <string, string>(themePartTuple.Item1, resourceUri); } } foreach (var kv in themeParts) { var themePart = new ThemePart(kv.Key, assembly, kv.Value.Item1, kv.Value.Item2); yield return(themePart); } }
public void GetValueOrCreate_ReturnsNewValue() { var s = new Dictionary<string, List<int>>(); Assert.AreEqual (new List<int>(), s.GetValueOrCreate ("foo")); List<int> v = null; var r = s.GetValueOrCreate ("bar", () => v = new List<int> ()); Assert.AreSame (r, v); }
public void GetValueOrCreate_ReturnsOldValue() { var s = new Dictionary<string, List<int>> () { { "foo", new List<int> {42} }, }; AssertAreSame (new[]{42}, s.GetValueOrCreate ("foo")); AssertAreSame (new[]{42}, s.GetValueOrCreate ("foo", () => new List<int> {1})); }
private LexerState GetLexerState(Grammar <TToken> .TokenRule tokenRule) { if (tokenRule.Name == null) { tokenRule.Name = GenerateLexerStateName(); } return(_lexerStateDictionary.GetValueOrCreate(tokenRule.Name, () => CreateLexerRuleState(tokenRule))); }
public void GetValueOrCreate_ReturnsNewValue() { var s = new Dictionary <string, List <int> >(); Assert.AreEqual(new List <int>(), s.GetValueOrCreate("foo")); List <int> v = null; var r = s.GetValueOrCreate("bar", () => v = new List <int> ()); Assert.AreSame(r, v); }
public void GetValueOrCreate_ReturnsOldValue() { var s = new Dictionary <string, List <int> > () { { "foo", new List <int> { 42 } }, }; AssertAreSame(new[] { 42 }, s.GetValueOrCreate("foo")); AssertAreSame(new[] { 42 }, s.GetValueOrCreate("foo", () => new List <int> { 1 })); }
void Add(int x, int y, Room rm) { var key = new RoomKey(x, y); var roomList = rooms.GetValueOrCreate(key, k => new HashSet <Room>()); roomList.Add(rm); }
internal static VisualStateGroup BuildVisualStateGroup(string groupName) { #if SILVERLIGHT var template = VisualStateGroupTemplates.GetValueOrCreate(groupName, CreateVisualStateTemplate); return(template == null ? null : XamlUtils.Load <VisualStateGroup>(template)); #else var groupKind = GetGroupKind(groupName); if (groupKind == VisualGroupKind.Unknown) { return(null); } var visualGroup = new VisualStateGroup { Name = groupName }; foreach (var state in GetStates(groupKind)) { visualGroup.States.Add(new VisualState { Name = state }); } return(visualGroup); #endif }
public TableSqlCache GetSqlCache(string providerId) { lock (_sync) { return(_cache.GetValueOrCreate(providerId, () => new TableSqlCache())); } }
public static DependencyPropertyInfo GetDependencyPropertyInfo(this DependencyProperty dependencyProperty) { #if SILVERLIGHT AppDomainObserver.Update(); return(DP2DPInfo.GetValueOrDefault(dependencyProperty)); #else return(DP2DPInfo.GetValueOrCreate(dependencyProperty, () => new DependencyPropertyInfo(dependencyProperty))); #endif }
public ThemeKey GetThemeKey(Type elementType) { var masterTheme = MasterTheme; if (ReferenceEquals(this, masterTheme) == false) { return(masterTheme.GetThemeKey(elementType)); } return(_themeKeys.GetValueOrCreate(elementType, CreateThemeKey)); }
internal PropertyDescriptorCollection GetPropertiesInternal(object propertyObject) { if (propertyObject == null) { return(null); } var propertiesGetter = PropertiesGetterDictionary.GetValueOrCreate(propertyObject.GetType(), CreatePropertiesGetter); return(propertiesGetter(propertyObject, this)); }
public Task Store(Snapshot snapshot) { lock (_sync) { var arr = _snapshots.GetValueOrCreate(snapshot.EntityId, () => new List <Snapshot>()); if (arr.Any(d => d.Version == snapshot.Version)) { arr.RemoveAll(d => d.Version == snapshot.Version); } arr.Add(snapshot); } return(Task.CompletedTask); }
public static void Run() { //初始化所有配置文件 ConfigReader.Read(); if (Config.BaseTypeDll != null) { var assembly = Assembly.ReflectionOnlyLoadFrom(Config.BaseTypeDll); //加载所有导入类型 ImportTypePool.Load(assembly); } var tableNameToTables = new Dictionary <string, List <VirtualDataTable> >(); foreach (var file in WalkAllExcelFiles(Config.InputFolder)) { var package = LoadExcelPackage(file.ToString()); foreach (var sheet in package.Workbook.Worksheets) { var table = new VirtualDataTable(file, sheet); tableNameToTables.GetValueOrCreate(table.TableName).Add(table); } } using (var writer = new FileWriter($"{Config.OutputFolder}/ConfigBase.cs")) { TemplateFile.Copy("ConfigBase", writer); } foreach (var kv in tableNameToTables) { var tables = kv.Value; var configType = TypeGenerator.GenerateType(tables); if (Config.OutputType == OutputType.CSharp) { CSharpOutput.Output(configType, tables); } } }
/// <summary> /// Get the localised string archive. /// </summary> /// <param name="archive"></param> /// <param name="language"></param> /// <returns></returns> public StringArchive GetLocalisedStringArchive(Engine.ItemArchiveId archive, Language language = Language.English) { if (archive == Engine.ItemArchiveId.None) { return(null); } Dictionary <Language, StringArchive> dictionary; Archive root = RootArchive; if (root == null) { return(null); } dictionary = StringArchives.GetValueOrCreate(archive); StringArchive stringArchive = dictionary.TryGetValue(language); if (stringArchive == null) { dictionary[language] = stringArchive = Engine.GetStringArchive(root, archive, language); } return(stringArchive); }
public void AddValueChanged(string propertyName, EventHandler <PropertyValueChangedEventArgs> handler) { _strProviders.GetValueOrCreate(propertyName, () => new PropertyChangeProvider(Target, propertyName, false)).PropertyChanged += handler; }
public static TValue GetValueOrCreate <TKey, TValue>(this Dictionary <TKey, TValue> dictionary, TKey key) where TValue : new() { return(dictionary.GetValueOrCreate(key, () => new TValue())); }
internal static IPrimitiveConverter <TFrom, TTo> GetWrappedConverter <TFrom, TTo>(IPrimitiveConverter converter) { return((IPrimitiveConverter <TFrom, TTo>)WrappedConverters.GetValueOrCreate(converter, () => new GenericConverterWrapper <TFrom, TTo>(converter))); }
public TableSqlCache GetSqlCache(string providerId) => _cache.GetValueOrCreate(providerId, () => new TableSqlCache());
private NativeStyle BuildNativeStyle() { var targetType = Style.TargetType ?? typeof(FrameworkElement); var nativeStyle = new NativeStyle { TargetType = targetType }; #if !SILVERLIGHT foreach (var baseStyle in Style.EnumerateBaseStylesAndSelf().OfType <Style>()) { if (baseStyle.Resources.Count == 0) { continue; } foreach (var resourceKey in baseStyle.Resources.Keys) { if (nativeStyle.Resources.Contains(resourceKey) == false) { nativeStyle.Resources.Add(resourceKey, baseStyle.Resources[resourceKey]); } } } #endif Triggers.AddRange(Style.ActualTriggers); var flatSetters = Style.ActualSetters.OfType <Setter>().Select(s => s.DeepClone <Setter>()).ToList(); Dictionary <DependencyProperty, DependencyProperty> dynamicProperties = null; foreach (var setter in flatSetters) { if (string.IsNullOrEmpty(setter.ExpandoProperty) == false || string.IsNullOrEmpty(setter.VisualState)) { continue; } var property = setter.ResolveProperty(targetType); if (property == null) { LogService.LogWarning($"Unable resolve property for setter: {setter}"); continue; } dynamicProperties ??= new Dictionary <DependencyProperty, DependencyProperty>(); dynamicProperties.GetValueOrCreate(property, GetDynamicProperty); } if (dynamicProperties != null) { foreach (var kv in dynamicProperties) { nativeStyle.Setters.Add(new NativeSetter { Property = kv.Key, Value = new Binding { Path = new PropertyPath(kv.Value), RelativeSource = XamlConstants.Self } }); } } foreach (var setter in flatSetters) { if (string.IsNullOrEmpty(setter.ExpandoProperty) == false) { Setters.Add(setter.Optimize()); continue; } var dependencyProperty = setter.ResolveProperty(targetType); var dynamicProperty = dependencyProperty != null?dynamicProperties?.GetValueOrDefault(dependencyProperty) : null; if (dynamicProperty != null) { setter.Property = dynamicProperty; Setters.Add(setter.Optimize()); continue; } var nativeSetter = setter.CreateNativeStyleSetter(targetType); if (nativeSetter != null) { nativeStyle.Setters.Add(nativeSetter); } else { Setters.Add(setter.Optimize()); } } nativeStyle.Setters.Add(new NativeSetter(InstanceProperty, this)); return(nativeStyle); }
public virtual PropertyDescriptorCollection GetPropertyDescriptors <T>(T propertyObject) { return(propertyObject == null ? null : _propertyDescriptorsDictionary.GetValueOrCreate(propertyObject.GetType(), CreatePropertyDescriptorCollection)); }
public static ITriggerValueComparer GetComparer(ComparerOperator comparerOperator) { return(Comparers.GetValueOrCreate(comparerOperator, () => new TriggerComparer(comparerOperator))); }
private static ResourceDictionary GetResourceDictionary(XName name) { return(ResourceDictionaryFactoryMap.GetValueOrCreate(name, CreateResourceDictionaryFactory)()); }
public ProcessedCommitsCount StartOrContinue(string name) { return(_batch.GetValueOrCreate(name, () => 0)); }
private static DependencyProperty GetExpandoPropertyImpl(string name) { return(ExpandoProperties.GetValueOrCreate(name, n => RegisterExpandoProperty(name))); }
public static TypeConverter GetTypeConverter(Type type) { return(ResolvedConverters.GetValueOrCreate(type, CreateTypeConverter)); }
public static SelectionScope GetOrCreateSelectionScopeByKey(object key) { return(key.Return(k => GeneratedScopes.GetValueOrCreate(k, () => new SelectionScope()))); }
private static DependencyProperty GetDynamicProperty(DependencyProperty property) { return(DynamicProperties.GetValueOrCreate(property, RegisterDynamicProperty)); }
private LightObjectPool <TObject> GetPool(TKey key) { return(_poolMap.GetValueOrCreate(key, CreatePool)); }
public List <TValue> GetOrCreateValues(TKey key) { return(_dictionary.GetValueOrCreate(key, () => new List <TValue>())); }
public static ResourceDictionary GetEmptyResourceDictionaryInstance(Uri uri) { return(EmptyResourceDictionaryCache.GetValueOrCreate(uri.OriginalString, () => UpdateActualUri(CreateEmptyResourceDictionaryInstance(uri), uri))); }
public static LayoutSerializer FromType(Type layoutType) { return(DefaultSerializers.GetValueOrCreate(layoutType, t => new DefaultLayoutSerializer(t))); }