当前位置: 首页>>代码示例>>C#>>正文


C# OptionKey类代码示例

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


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


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