• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# OptionKey类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中OptionKey的典型用法代码示例。如果您正苦于以下问题:C# OptionKey类的具体用法?C# OptionKey怎么用?C# OptionKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



OptionKey类属于命名空间,在下文中一共展示了OptionKey类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: WithChangedOption

        public override OptionSet WithChangedOption(OptionKey optionAndLanguage, object value)
        {
            // make sure we first load this in current optionset
            this.GetOption(optionAndLanguage);

            return new WorkspaceOptionSet(_service, _values.SetItem(optionAndLanguage, value));
        }
开发者ID:TyOverby,项目名称:roslyn,代码行数:7,代码来源:WorkspaceOptionSet.cs


示例2: GetCollectionPathForOption

        bool IOptionSerializer.TryFetch(OptionKey optionKey, out object value)
        {
            var collectionPath = GetCollectionPathForOption(optionKey);
            if (collectionPath == null)
            {
                value = null;
                return false;
            }

            lock (_gate)
            {
                using (var subKey = this._registryKey.OpenSubKey(collectionPath))
                {
                    if (subKey == null)
                    {
                        value = null;
                        return false;
                    }

                    // Options that are of type bool have to be serialized as integers
                    if (optionKey.Option.Type == typeof(bool))
                    {
                        value = subKey.GetValue(optionKey.Option.Name, defaultValue: (bool)optionKey.Option.DefaultValue ? 1 : 0).Equals(1);
                        return true;
                    }
                    else
                    {
                        // Otherwise we can just store normally
                        value = subKey.GetValue(optionKey.Option.Name, defaultValue: optionKey.Option.DefaultValue);
                        return true;
                    }
                }
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:34,代码来源:AbstractLocalUserRegistryOptionSerializer.cs


示例3: TryPersist

        public virtual bool TryPersist(OptionKey optionKey, object value)
        {
            // We ignore languageName, since the current use of this class is only for
            // language-specific options that apply to a single language. The underlying option
            // service has already ensured the languageName is right, so we'll drop it on the floor.
            if (this.RegistryKey == null)
            {
                throw new InvalidOperationException();
            }

            var collectionPathAndPropertyName = GetCollectionPathAndPropertyNameForOption(optionKey.Option, optionKey.Language);
            if (collectionPathAndPropertyName == null)
            {
                return false;
            }

            lock (Gate)
            {
                using (var subKey = this.RegistryKey.CreateSubKey(collectionPathAndPropertyName.Item1))
                {
                    subKey.SetValue(collectionPathAndPropertyName.Item2, (bool)value ? 1 : 0, RegistryValueKind.DWord);
                }

                return true;
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:26,代码来源:AbstractSettingStoreOptionSerializer.cs


示例4: TryFetch

        public virtual bool TryFetch(OptionKey optionKey, out object value)
        {
            if (this.RegistryKey == null)
            {
                throw new InvalidOperationException();
            }

            var collectionPathAndPropertyName = GetCollectionPathAndPropertyNameForOption(optionKey.Option, optionKey.Language);
            if (collectionPathAndPropertyName == null)
            {
                value = null;
                return false;
            }

            lock (Gate)
            {
                using (var openSubKey = this.RegistryKey.OpenSubKey(collectionPathAndPropertyName.Item1))
                {
                    if (openSubKey == null)
                    {
                        value = null;
                        return false;
                    }

                    value = openSubKey.GetValue(collectionPathAndPropertyName.Item2, defaultValue: (bool)optionKey.Option.DefaultValue ? 1 : 0).Equals(1);
                    return true;
                }
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:29,代码来源:AbstractSettingStoreOptionSerializer.cs


示例5: GetCollectionPathForOption

        protected override string GetCollectionPathForOption(OptionKey key)
        {
            if (key.Option.Feature == EditorComponentOnOffOptions.OptionName)
            {
                return @"Roslyn\Internal\OnOff\Components";
            }
            else if (key.Option.Feature == InternalFeatureOnOffOptions.OptionName)
            {
                return @"Roslyn\Internal\OnOff\Features";
            }
            else if (key.Option.Feature == PerformanceFunctionIdOptionsProvider.Name)
            {
                return @"Roslyn\Internal\Performance\FunctionId";
            }
            else if (key.Option.Feature == LoggerOptions.FeatureName)
            {
                return @"Roslyn\Internal\Performance\Logger";
            }
            else if (key.Option.Feature == InternalDiagnosticsOptions.OptionName)
            {
                return @"Roslyn\Internal\Diagnostics";
            }
            else if (key.Option.Feature == InternalSolutionCrawlerOptions.OptionName)
            {
                return @"Roslyn\Internal\SolutionCrawler";
            }
            else if (key.Option.Feature == CacheOptions.FeatureName)
            {
                return @"Roslyn\Internal\Performance\Cache";
            }

            throw ExceptionUtilities.Unreachable;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:33,代码来源:InternalOptionSerializer.cs


示例6: InvalidOperationException

        bool IOptionSerializer.TryPersist(OptionKey optionKey, object value)
        {
            if (this._registryKey == null)
            {
                throw new InvalidOperationException();
            }

            var collectionPath = GetCollectionPathForOption(optionKey);
            if (collectionPath == null)
            {
                return false;
            }

            lock (_gate)
            {
                using (var subKey = this._registryKey.CreateSubKey(collectionPath))
                {
                    // Options that are of type bool have to be serialized as integers
                    if (optionKey.Option.Type == typeof(bool))
                    {
                        subKey.SetValue(optionKey.Option.Name, (bool)value ? 1 : 0, RegistryValueKind.DWord);
                        return true;
                    }
                    else
                    {
                        subKey.SetValue(optionKey.Option.Name, value);
                        return true;
                    }
                }
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:31,代码来源:AbstractLocalUserRegistryOptionSerializer.cs


示例7: TryPersist

        protected bool TryPersist(OptionKey optionKey, object value, Action<RegistryKey, string, IOption, object> valueSetter)
        {
            // We ignore languageName, since the current use of this class is only for
            // language-specific options that apply to a single language. The underlying option
            // service has already ensured the languageName is right, so we'll drop it on the floor.
            if (this.RegistryKey == null)
            {
                throw new InvalidOperationException();
            }

            var collectionPathAndPropertyName = GetCollectionPathAndPropertyNameForOption(optionKey.Option, optionKey.Language);
            if (collectionPathAndPropertyName == null)
            {
                return false;
            }

            lock (Gate)
            {
                using (var subKey = this.RegistryKey.CreateSubKey(collectionPathAndPropertyName.Item1))
                {
                    valueSetter(subKey, collectionPathAndPropertyName.Item2, optionKey.Option, value);
                    return true;
                }
            }
        }
开发者ID:RoryVL,项目名称:roslyn,代码行数:25,代码来源:AbstractSettingStoreOptionSerializer.cs


示例8: TryGetDocumentOption

            public bool TryGetDocumentOption(Document document, OptionKey option, out object value)
            {
                var editorConfigPersistence = option.Option.StorageLocations.OfType<EditorConfigStorageLocation>().SingleOrDefault();

                if (editorConfigPersistence == null)
                {
                    value = null;
                    return false;
                }

                if (_codingConventionSnapshot.TryGetConventionValue(editorConfigPersistence.KeyName, out value))
                {
                    try
                    {
                        value = editorConfigPersistence.ParseValue(value.ToString(), option.Option.Type);
                        return true;
                    }
                    catch (Exception)
                    {
                        // TODO: report this somewhere?
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:28,代码来源:EditorConfigDocumentOptionsProvider.DocumentOptions.cs


示例9: TryFetch

        protected bool TryFetch(OptionKey optionKey, Func<RegistryKey, string, IOption, object> valueGetter, out object value)
        {
            if (this.RegistryKey == null)
            {
                throw new InvalidOperationException();
            }

            var collectionPathAndPropertyName = GetCollectionPathAndPropertyNameForOption(optionKey.Option, optionKey.Language);
            if (collectionPathAndPropertyName == null)
            {
                value = null;
                return false;
            }

            lock (Gate)
            {
                using (var subKey = this.RegistryKey.OpenSubKey(collectionPathAndPropertyName.Item1))
                {
                    if (subKey == null)
                    {
                        value = null;
                        return false;
                    }

                    value = valueGetter(subKey, collectionPathAndPropertyName.Item2, optionKey.Option);
                    return true;
                }
            }
        }
开发者ID:RoryVL,项目名称:roslyn,代码行数:29,代码来源:AbstractSettingStoreOptionSerializer.cs


示例10: TryFetch

        public bool TryFetch(OptionKey optionKey, out object value)
        {
            if (this._settingManager == null)
            {
                Debug.Fail("Manager field is unexpectedly null.");
                value = null;
                return false;
            }

            // Do we roam this at all?
            var roamingSerialization = optionKey.Option.StorageLocations.OfType<RoamingProfileStorageLocation>().SingleOrDefault();

            if (roamingSerialization == null)
            {
                value = null;
                return false;
            }

            var storageKey = roamingSerialization.GetKeyNameForLanguage(optionKey.Language);

            RecordObservedValueToWatchForChanges(optionKey, storageKey);

            value = this._settingManager.GetValueOrDefault(storageKey, optionKey.Option.DefaultValue);

            // VS's ISettingsManager has some quirks around storing enums.  Specifically,
            // it *can* persist and retrieve enums, but only if you properly call 
            // GetValueOrDefault<EnumType>.  This is because it actually stores enums just
            // as ints and depends on the type parameter passed in to convert the integral
            // value back to an enum value.  Unfortunately, we call GetValueOrDefault<object>
            // and so we get the value back as boxed integer.
            //
            // Because of that, manually convert the integer to an enum here so we don't
            // crash later trying to cast a boxed integer to an enum value.
            if (optionKey.Option.Type.IsEnum)
            {
                if (value != null)
                {
                    value = Enum.ToObject(optionKey.Option.Type, value);
                }
            }
            else if (optionKey.Option.Type == typeof(CodeStyleOption<bool>))
            {
                // We store these as strings, so deserialize
                var serializedValue = value as string;

                if (serializedValue != null)
                {
                    value = CodeStyleOption<bool>.FromXElement(XElement.Parse(serializedValue));
                }
                else
                {
                    value = optionKey.Option.DefaultValue;
                }
            }

            return true;
        }
开发者ID:jkotas,项目名称:roslyn,代码行数:57,代码来源:RoamingVisualStudioProfileOptionPersister.cs


示例11: Create

 private static KeyValueLogMessage Create(OptionKey optionKey, object oldValue, object currentValue)
 {
     return KeyValueLogMessage.Create(m =>
     {
         m[Name] = optionKey.Option.Name;
         m[Language] = optionKey.Language ?? All;
         m[Change] = CreateOptionValue(oldValue, currentValue);
     });
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:9,代码来源:OptionLogger.cs


示例12: GettingOptionWithChangedOption

 public void GettingOptionWithChangedOption()
 {
     var optionService = TestOptionService.GetService();
     var optionSet = optionService.GetOptions();
     var option = new Option<bool>("Test Feature", "Test Name", false);
     var key = new OptionKey(option);
     Assert.False(optionSet.GetOption(option));
     optionSet = optionSet.WithChangedOption(key, true);
     Assert.True((bool)optionSet.GetOption(key));
 }
开发者ID:GloryChou,项目名称:roslyn,代码行数:10,代码来源:OptionServiceTests.cs


示例13: TryFetch

        public override bool TryFetch(OptionKey optionKey, out object value)
        {
            switch (optionKey.Option.Feature)
            {
                case CacheOptions.FeatureName:
                case InternalSolutionCrawlerOptions.OptionName:
                    return TryFetch(optionKey, (r, k, o) => r.GetValue(k, defaultValue: o.DefaultValue), out value);
            }

            return base.TryFetch(optionKey, out value);
        }
开发者ID:RoryVL,项目名称:roslyn,代码行数:11,代码来源:InternalOptionSerializer.cs


示例14: TryPersist

        public override bool TryPersist(OptionKey optionKey, object value)
        {
            switch (optionKey.Option.Feature)
            {
                case CacheOptions.FeatureName:
                case InternalSolutionCrawlerOptions.OptionName:
                    return TryPersist(optionKey, value, (r, k, o, v) => r.SetValue(k, v, o.Type == typeof(int) ? RegistryValueKind.DWord : RegistryValueKind.QWord));
            }

            return base.TryPersist(optionKey, value);
        }
开发者ID:RoryVL,项目名称:roslyn,代码行数:11,代码来源:InternalOptionSerializer.cs


示例15: TryFetch

        public bool TryFetch(OptionKey optionKey, out object value)
        {
            value = string.Empty;
            if (optionKey != TodoCommentOptions.TokenList)
            {
                return false;
            }

            value = _taskTokenList;
            return true;
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:11,代码来源:CommentTaskTokenSerializer.cs


示例16: GetOption

        public override object GetOption(OptionKey optionKey)
        {
            lock (_gate)
            {
                if (!_values.TryGetValue(optionKey, out var value))
                {
                    value = _service != null ? _service.GetOption(optionKey) : optionKey.Option.DefaultValue;
                    _values = _values.Add(optionKey, value);
                }

                return value;
            }
        }
开发者ID:TyOverby,项目名称:roslyn,代码行数:13,代码来源:WorkspaceOptionSet.cs


示例17: SetChangedOption

        private void SetChangedOption(IOptionService optionService, IOption option, string languageName)
        {
            OptionKey key = new OptionKey(option, languageName);

            object currentValue;
            if (this.TryFetch(key, out currentValue))
            {
                OptionSet optionSet = optionService.GetOptions();
                optionSet = optionSet.WithChangedOption(key, currentValue);

                optionService.SetOptions(optionSet);
            }
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:13,代码来源:AbstractSettingsManagerOptionSerializer.cs


示例18: TryPersist

        public override bool TryPersist(OptionKey optionKey, object value)
        {
            if (optionKey.Option.Feature == CacheOptions.FeatureName)
            {
                lock (Gate)
                {
                    using (var subKey = this.RegistryKey.CreateSubKey(CachePath))
                    {
                        subKey.SetValue(optionKey.Option.Name, value, optionKey.Option.Type == typeof(int) ? RegistryValueKind.DWord : RegistryValueKind.QWord);
                        return true;
                    }
                }
            }

            return base.TryPersist(optionKey, value);
        }
开发者ID:JinGuoGe,项目名称:roslyn,代码行数:16,代码来源:InternalOptionSerializer.cs


示例19: TryFetch

        public override bool TryFetch(OptionKey optionKey, out object value)
        {
            if (optionKey.Option.Feature == CacheOptions.FeatureName)
            {
                lock (Gate)
                {
                    using (var openSubKey = this.RegistryKey.OpenSubKey(CachePath))
                    {
                        if (openSubKey == null)
                        {
                            value = null;
                            return false;
                        }

                        value = openSubKey.GetValue(optionKey.Option.Name, defaultValue: optionKey.Option.DefaultValue);
                        return true;
                    }
                }
            }

            return base.TryFetch(optionKey, out value);
        }
开发者ID:JinGuoGe,项目名称:roslyn,代码行数:22,代码来源:InternalOptionSerializer.cs


示例20: lock

        bool IOptionPersister.TryFetch(OptionKey optionKey, out object value)
        {
            string path;
            string key;

            if (!TryGetKeyPathAndName(optionKey.Option, out path, out key))
            {
                value = null;
                return false;
            }

            lock (_gate)
            {
                using (var subKey = this._registryKey.OpenSubKey(path))
                {
                    if (subKey == null)
                    {
                        value = null;
                        return false;
                    }

                    // Options that are of type bool have to be serialized as integers
                    if (optionKey.Option.Type == typeof(bool))
                    {
                        value = subKey.GetValue(key, defaultValue: (bool)optionKey.Option.DefaultValue ? 1 : 0).Equals(1);
                        return true;
                    }
                    else
                    {
                        // Otherwise we can just store normally
                        value = subKey.GetValue(key, defaultValue: optionKey.Option.DefaultValue);
                        return true;
                    }
                }
            }
        }
开发者ID:jkotas,项目名称:roslyn,代码行数:36,代码来源:LocalUserRegistryOptionPersister.cs



注:本文中的OptionKey类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# OptionSet类代码示例发布时间:2022-05-24
下一篇:
C# Option类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap