コード例 #1
0
        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);
            }
        }
コード例 #2
0
ファイル: DictionaryCodaTest.cs プロジェクト: rikkus/cadenza
 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);
 }
コード例 #3
0
ファイル: DictionaryCodaTest.cs プロジェクト: rikkus/cadenza
 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}));
 }
コード例 #4
0
            private LexerState GetLexerState(Grammar <TToken> .TokenRule tokenRule)
            {
                if (tokenRule.Name == null)
                {
                    tokenRule.Name = GenerateLexerStateName();
                }

                return(_lexerStateDictionary.GetValueOrCreate(tokenRule.Name, () => CreateLexerRuleState(tokenRule)));
            }
コード例 #5
0
ファイル: DictionaryCodaTest.cs プロジェクト: rikkus/cadenza
        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);
        }
コード例 #6
0
ファイル: DictionaryCodaTest.cs プロジェクト: rikkus/cadenza
        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
            }));
        }
コード例 #7
0
ファイル: RoomCollision.cs プロジェクト: Bog624s/Rotux
        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);
        }
コード例 #8
0
ファイル: VisualGroups.cs プロジェクト: Egaros/lib
        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
        }
コード例 #9
0
ファイル: TableInfo.cs プロジェクト: raihansazal/SqlFu
 public TableSqlCache GetSqlCache(string providerId)
 {
     lock (_sync)
     {
         return(_cache.GetValueOrCreate(providerId, () => new TableSqlCache()));
     }
 }
コード例 #10
0
        public static DependencyPropertyInfo GetDependencyPropertyInfo(this DependencyProperty dependencyProperty)
        {
#if SILVERLIGHT
            AppDomainObserver.Update();
            return(DP2DPInfo.GetValueOrDefault(dependencyProperty));
#else
            return(DP2DPInfo.GetValueOrCreate(dependencyProperty, () => new DependencyPropertyInfo(dependencyProperty)));
#endif
        }
コード例 #11
0
        public ThemeKey GetThemeKey(Type elementType)
        {
            var masterTheme = MasterTheme;

            if (ReferenceEquals(this, masterTheme) == false)
            {
                return(masterTheme.GetThemeKey(elementType));
            }

            return(_themeKeys.GetValueOrCreate(elementType, CreateThemeKey));
        }
コード例 #12
0
        internal PropertyDescriptorCollection GetPropertiesInternal(object propertyObject)
        {
            if (propertyObject == null)
            {
                return(null);
            }

            var propertiesGetter = PropertiesGetterDictionary.GetValueOrCreate(propertyObject.GetType(), CreatePropertiesGetter);

            return(propertiesGetter(propertyObject, this));
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
                }
            }
        }
コード例 #15
0
ファイル: TableArchive.cs プロジェクト: layshua/Alexandria
        /// <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);
        }
コード例 #16
0
 public void AddValueChanged(string propertyName, EventHandler <PropertyValueChangedEventArgs> handler)
 {
     _strProviders.GetValueOrCreate(propertyName, () => new PropertyChangeProvider(Target, propertyName, false)).PropertyChanged += handler;
 }
コード例 #17
0
 public static TValue GetValueOrCreate <TKey, TValue>(this Dictionary <TKey, TValue> dictionary, TKey key) where TValue : new()
 {
     return(dictionary.GetValueOrCreate(key, () => new TValue()));
 }
コード例 #18
0
 internal static IPrimitiveConverter <TFrom, TTo> GetWrappedConverter <TFrom, TTo>(IPrimitiveConverter converter)
 {
     return((IPrimitiveConverter <TFrom, TTo>)WrappedConverters.GetValueOrCreate(converter, () => new GenericConverterWrapper <TFrom, TTo>(converter)));
 }
コード例 #19
0
 public TableSqlCache GetSqlCache(string providerId)
 => _cache.GetValueOrCreate(providerId, () => new TableSqlCache());
コード例 #20
0
ファイル: StyleService.cs プロジェクト: Egaros/lib
        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);
        }
コード例 #21
0
 public virtual PropertyDescriptorCollection GetPropertyDescriptors <T>(T propertyObject)
 {
     return(propertyObject == null ? null : _propertyDescriptorsDictionary.GetValueOrCreate(propertyObject.GetType(), CreatePropertyDescriptorCollection));
 }
コード例 #22
0
ファイル: TriggerComparer.cs プロジェクト: Egaros/lib
 public static ITriggerValueComparer GetComparer(ComparerOperator comparerOperator)
 {
     return(Comparers.GetValueOrCreate(comparerOperator, () => new TriggerComparer(comparerOperator)));
 }
コード例 #23
0
 private static ResourceDictionary GetResourceDictionary(XName name)
 {
     return(ResourceDictionaryFactoryMap.GetValueOrCreate(name, CreateResourceDictionaryFactory)());
 }
コード例 #24
0
 public ProcessedCommitsCount StartOrContinue(string name)
 {
     return(_batch.GetValueOrCreate(name, () => 0));
 }
コード例 #25
0
 private static DependencyProperty GetExpandoPropertyImpl(string name)
 {
     return(ExpandoProperties.GetValueOrCreate(name, n => RegisterExpandoProperty(name)));
 }
コード例 #26
0
ファイル: TypeConversionUtil.cs プロジェクト: Egaros/lib
 public static TypeConverter GetTypeConverter(Type type)
 {
     return(ResolvedConverters.GetValueOrCreate(type, CreateTypeConverter));
 }
コード例 #27
0
ファイル: SelectableBehavior.cs プロジェクト: Egaros/lib
 public static SelectionScope GetOrCreateSelectionScopeByKey(object key)
 {
     return(key.Return(k => GeneratedScopes.GetValueOrCreate(k, () => new SelectionScope())));
 }
コード例 #28
0
ファイル: StyleService.cs プロジェクト: Egaros/lib
 private static DependencyProperty GetDynamicProperty(DependencyProperty property)
 {
     return(DynamicProperties.GetValueOrCreate(property, RegisterDynamicProperty));
 }
コード例 #29
0
 private LightObjectPool <TObject> GetPool(TKey key)
 {
     return(_poolMap.GetValueOrCreate(key, CreatePool));
 }
コード例 #30
0
 public List <TValue> GetOrCreateValues(TKey key)
 {
     return(_dictionary.GetValueOrCreate(key, () => new List <TValue>()));
 }
コード例 #31
0
 public static ResourceDictionary GetEmptyResourceDictionaryInstance(Uri uri)
 {
     return(EmptyResourceDictionaryCache.GetValueOrCreate(uri.OriginalString, () => UpdateActualUri(CreateEmptyResourceDictionaryInstance(uri), uri)));
 }
コード例 #32
0
 public static LayoutSerializer FromType(Type layoutType)
 {
     return(DefaultSerializers.GetValueOrCreate(layoutType, t => new DefaultLayoutSerializer(t)));
 }