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


C# Variables.Get方法代码示例

本文整理汇总了C#中Variables.Get方法的典型用法代码示例。如果您正苦于以下问题:C# Variables.Get方法的具体用法?C# Variables.Get怎么用?C# Variables.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Variables的用法示例。


在下文中一共展示了Variables.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Constructor_DetectsAdjacentCyclicalReference

        public void Constructor_DetectsAdjacentCyclicalReference()
        {
            using (TestHostContext hc = new TestHostContext(this))
            {
                // Arrange.
                var copy = new Dictionary<string, string>
                {
                    { "variable1", "1_$(variable2)" },
                    { "variable2", "2_$(variable3)" },
                    { "variable3", "3_$(variable2)" },
                };

                // Act.
                List<string> warnings;
                var variables = new Variables(hc, copy, new List<MaskHint>(), out warnings);

                // Assert.
                Assert.Equal(3, warnings.Count);
                Assert.True(warnings.Any(x => string.Equals(x, StringUtil.Loc("Variable0ContainsCyclicalReference", "variable1"))));
                Assert.True(warnings.Any(x => string.Equals(x, StringUtil.Loc("Variable0ContainsCyclicalReference", "variable2"))));
                Assert.True(warnings.Any(x => string.Equals(x, StringUtil.Loc("Variable0ContainsCyclicalReference", "variable3"))));
                Assert.Equal("1_$(variable2)", variables.Get("variable1"));
                Assert.Equal("2_$(variable3)", variables.Get("variable2"));
                Assert.Equal("3_$(variable2)", variables.Get("variable3"));
            }
        }
开发者ID:codedebug,项目名称:vsts-agent,代码行数:26,代码来源:VariablesL0.cs

示例2: Constructor_AppliesMaskHints

        public void Constructor_AppliesMaskHints()
        {
            using (TestHostContext hc = new TestHostContext(this))
            {
                // Arrange.
                var copy = new Dictionary<string, string>
                {
                    { "MySecretName", "My secret value" },
                    { "MyPublicVariable", "My public value" },
                };
                var maskHints = new List<MaskHint>
                {
                    new MaskHint() { Type = MaskType.Variable, Value = "MySecretName" },
                };
                List<string> warnings;
                var variables = new Variables(hc, copy, maskHints, out warnings);

                // Act.
                KeyValuePair<string, string>[] publicVariables = variables.Public.ToArray();

                // Assert.
                Assert.Equal(0, warnings.Count);
                Assert.Equal(1, publicVariables.Length);
                Assert.Equal("MyPublicVariable", publicVariables[0].Key);
                Assert.Equal("My public value", publicVariables[0].Value);
                Assert.Equal("My secret value", variables.Get("MySecretName"));
            }
        }
开发者ID:codedebug,项目名称:vsts-agent,代码行数:28,代码来源:VariablesL0.cs

示例3: resolveName

        /// <summary>
        /// Resolves any variable names
        /// </summary>
        /// <param name="name">name of the variable</param>
        /// <returns>its value</returns>
        private String resolveName(Variables variables, String name)
        {
            var retVal = name;
            if (String.Compare(name, "@SelectedWidget", true) == 0)
            {
                var widget = (Widget)variables.Get(Variables.SelectedWidget);
                retVal = widget.Name;
            }

            return retVal;
        }
开发者ID:nbsrujan,项目名称:acat,代码行数:16,代码来源:Animation.cs

示例4: getContainerWidget

        /// <summary>
        /// Wild card names can be @variablename/* or widgetname/*. Parses
        /// the string and returns the name of the container widget
        /// </summary>
        /// <param name="rootWidget">root widget of the scanner</param>
        /// <param name="wildCard">wildcard to resolve</param>
        /// <returns>container widget</returns>
        private Widget getContainerWidget(Widget rootWidget, Variables variables, string wildCard)
        {
            Widget retVal = null;
            String[] wildCardPatterns =
            {
                "\\@[a-zA-Z0-9]*/\\*",      // @variablename/*
                "[a-zA-Z0-9]*/\\*",         // widgename/*"
                "\\*"                       // *
            };

            String[] extractPatterns =
            {
                "\\@[a-zA-Z0-9]*",
                "[a-zA-Z0-9]*",
                "\\*"
            };

            bool done = false;
            for (int ii = 0; !done && ii < wildCardPatterns.Length; ii++)
            {
                if (!Regex.IsMatch(wildCard, wildCardPatterns[ii]))
                {
                    continue;
                }

                Match match = Regex.Match(wildCard, extractPatterns[ii]);
                if (String.IsNullOrEmpty(match.Value))
                {
                    continue;
                }

                done = true;
                String widgetName;
                switch (ii)
                {
                    case 0:
                        widgetName = match.Value.Substring(1);
                        if (String.Compare(widgetName, Variables.SelectedWidget) == 0)
                        {
                            retVal = (Widget)variables.Get(Variables.SelectedWidget);
                        }

                        break;

                    case 1:
                        widgetName = match.Value;
                        if (String.Compare(widgetName, rootWidget.Name, true) == 0)
                        {
                            retVal = rootWidget;
                        }
                        else
                        {
                            retVal = rootWidget.Finder.FindChild(widgetName);
                        }

                        break;

                    case 2:
                        retVal = (Widget)variables.Get(Variables.SelectedWidget);
                        break;
                }
            }

            return retVal;
        }
开发者ID:nbsrujan,项目名称:acat,代码行数:72,代码来源:Animation.cs

示例5: Constructor_DetectsExcessiveDepth

        public void Constructor_DetectsExcessiveDepth()
        {
            using (TestHostContext hc = new TestHostContext(this))
            {
                // Arrange.
                const int MaxDepth = 50;
                var copy = new Dictionary<string, string>();
                copy[$"variable{MaxDepth + 1}"] = "Final value"; // Variable 51.
                for (int i = 1 ; i <= MaxDepth ; i++)
                {
                    copy[$"variable{i}"] = $"$(variable{i + 1})"; // Variables 1-50.
                }

                // Act.
                List<string> warnings;
                var variables = new Variables(hc, copy, new List<MaskHint>(), out warnings);

                // Assert.
                Assert.Equal(1, warnings.Count);
                Assert.Equal(warnings[0], StringUtil.Loc("Variable0ExceedsMaxDepth1", "variable1", MaxDepth));
                Assert.Equal("$(variable2)", variables.Get("variable1")); // Variable 1.
                for (int i = 2; i <= MaxDepth + 1; i++)
                {
                    Assert.Equal("Final value", variables.Get($"variable{i}")); // Variables 2-51.
                }
            }
        }
开发者ID:codedebug,项目名称:vsts-agent,代码行数:27,代码来源:VariablesL0.cs

示例6: Set_StoresValue

        public void Set_StoresValue()
        {
            using (TestHostContext hc = new TestHostContext(this))
            {
                // Arrange.
                List<string> warnings;
                var variables = new Variables(hc, new Dictionary<string, string>(), new List<MaskHint>(), out warnings);

                // Act.
                variables.Set("foo", "bar");

                // Assert.
                Assert.Equal("bar", variables.Get("foo"));
            }
        }
开发者ID:codedebug,项目名称:vsts-agent,代码行数:15,代码来源:VariablesL0.cs

示例7: Set_StoresNullAsEmpty

        public void Set_StoresNullAsEmpty()
        {
            using (TestHostContext hc = new TestHostContext(this))
            {
                // Arrange.
                List<string> warnings;
                var variables = new Variables(hc, new Dictionary<string, string>(), new List<MaskHint>(), out warnings);

                // Act.
                variables.Set("variable1", null);

                // Assert.
                Assert.Equal(0, warnings.Count);
                Assert.Equal(string.Empty, variables.Get("variable1"));
            }
        }
开发者ID:codedebug,项目名称:vsts-agent,代码行数:16,代码来源:VariablesL0.cs

示例8: Set_CanUpdateASecret

        public void Set_CanUpdateASecret()
        {
            using (TestHostContext hc = new TestHostContext(this))
            {
                // Arrange.
                List<string> warnings;
                var variables = new Variables(hc, new Dictionary<string, string>(), new List<MaskHint>(), out warnings);

                // Act.
                variables.Set("foo", "bar", secret: true);
                variables.Set("foo", "baz", secret: true);

                // Assert.
                Assert.Equal(0, variables.Public.Count());
                Assert.Equal("baz", variables.Get("foo"));
            }
        }
开发者ID:codedebug,项目名称:vsts-agent,代码行数:17,代码来源:VariablesL0.cs

示例9: RecalculateExpanded_RetainsUpdatedSecretness

        public void RecalculateExpanded_RetainsUpdatedSecretness()
        {
            using (TestHostContext hc = new TestHostContext(this))
            {
                // Arrange.
                List<string> warnings;
                var variables = new Variables(hc, new Dictionary<string, string>(), new List<MaskHint>(), out warnings);
                Assert.Equal(0, warnings.Count);
                variables.Set("foo", "bar");
                Assert.Equal(1, variables.Public.Count());

                // Act.
                variables.Set("foo", "baz", secret: true);
                variables.RecalculateExpanded(out warnings);

                // Assert.
                Assert.Equal(0, warnings.Count);
                Assert.Equal(0, variables.Public.Count());
                Assert.Equal("baz", variables.Get("foo"));
            }
        }
开发者ID:codedebug,项目名称:vsts-agent,代码行数:21,代码来源:VariablesL0.cs

示例10: RecalculateExpanded_PerformsRecalculation

        public void RecalculateExpanded_PerformsRecalculation()
        {
            using (TestHostContext hc = new TestHostContext(this))
            {
                // Arrange.
                List<string> warnings;
                var original = new Dictionary<string, string>
                {
                    { "topLevelVariable", "$(nestedVariable1) $(nestedVariable2)" },
                    { "nestedVariable1", "Some nested value 1" },
                };
                var variables = new Variables(hc, original, new List<MaskHint>(), out warnings);
                Assert.Equal(0, warnings.Count);
                Assert.Equal(2, variables.Public.Count());
                Assert.Equal("Some nested value 1 $(nestedVariable2)", variables.Get("topLevelVariable"));
                Assert.Equal("Some nested value 1", variables.Get("nestedVariable1"));

                // Act.
                variables.Set("nestedVariable2", "Some nested value 2", secret: false);
                variables.RecalculateExpanded(out warnings);

                // Assert.
                Assert.Equal(0, warnings.Count);
                Assert.Equal(3, variables.Public.Count());
                Assert.Equal("Some nested value 1 Some nested value 2", variables.Get("topLevelVariable"));
                Assert.Equal("Some nested value 1", variables.Get("nestedVariable1"));
                Assert.Equal("Some nested value 2", variables.Get("nestedVariable2"));
            }
        }
开发者ID:codedebug,项目名称:vsts-agent,代码行数:29,代码来源:VariablesL0.cs

示例11: Get_ReturnsNullIfNotFound

        public void Get_ReturnsNullIfNotFound()
        {
            using (TestHostContext hc = new TestHostContext(this))
            {
                // Arrange.
                List<string> warnings;
                var variables = new Variables(hc, new Dictionary<string, string>(), new List<MaskHint>(), out warnings);

                // Act.
                string actual = variables.Get("no such");

                // Assert.
                Assert.Equal(null, actual);
            }
        }
开发者ID:codedebug,项目名称:vsts-agent,代码行数:15,代码来源:VariablesL0.cs

示例12: Constructor_HandlesNullValue

        public void Constructor_HandlesNullValue()
        {
            using (TestHostContext hc = new TestHostContext(this))
            {
                // Arrange.
                var copy = new Dictionary<string, string>
                {
                    { "variable1", null },
                    { "variable2", "some variable 2 value" },
                };

                // Act.
                List<string> warnings;
                var variables = new Variables(hc, copy, new List<MaskHint>(), out warnings);

                // Assert.
                Assert.Equal(0, warnings.Count);
                Assert.Equal(string.Empty, variables.Get("variable1"));
                Assert.Equal("some variable 2 value", variables.Get("variable2"));
            }
        }
开发者ID:codedebug,项目名称:vsts-agent,代码行数:21,代码来源:VariablesL0.cs

示例13: Constructor_ExpandsValueWithPreceedingPrefix

        public void Constructor_ExpandsValueWithPreceedingPrefix()
        {
            using (TestHostContext hc = new TestHostContext(this))
            {
                // Arrange.
                var copy = new Dictionary<string, string>
                {
                    { "variable1", "before$($(variable2)after" },
                    { "variable2", "hello" },
                };

                // Act.
                List<string> warnings;
                var variables = new Variables(hc, copy, new List<MaskHint>(), out warnings);

                // Assert.
                Assert.Equal(0, warnings.Count);
                Assert.Equal("before$(helloafter", variables.Get("variable1"));
                Assert.Equal("hello", variables.Get("variable2"));
            }
        }
开发者ID:codedebug,项目名称:vsts-agent,代码行数:21,代码来源:VariablesL0.cs

示例14: Constructor_ExpandsValueWithConsecutiveMacros

        public void Constructor_ExpandsValueWithConsecutiveMacros()
        {
            using (TestHostContext hc = new TestHostContext(this))
            {
                // Arrange.
                var copy = new Dictionary<string, string>
                {
                    { "variable1", "before$(variable2)$(variable2)after" },
                    { "variable2", "some variable 2 value" },
                };

                // Act.
                List<string> warnings;
                var variables = new Variables(hc, copy, new List<MaskHint>(), out warnings);

                // Assert.
                Assert.Equal(0, warnings.Count);
                Assert.Equal("beforesome variable 2 valuesome variable 2 valueafter", variables.Get("variable1"));
                Assert.Equal("some variable 2 value", variables.Get("variable2"));
            }
        }
开发者ID:codedebug,项目名称:vsts-agent,代码行数:21,代码来源:VariablesL0.cs

示例15: Constructor_InheritsSecretFlagFromRecursion

        public void Constructor_InheritsSecretFlagFromRecursion()
        {
            using (TestHostContext hc = new TestHostContext(this))
            {
                // Arrange.
                var copy = new Dictionary<string, string>
                {
                    { "variable1", "before $(variable2) after" },
                    { "variable2", "some variable 2 value" },
                };
                var maskHints = new List<MaskHint>
                {
                    new MaskHint() { Type = MaskType.Variable, Value = "variable2" },
                };

                // Act.
                List<string> warnings;
                var variables = new Variables(hc, copy, maskHints, out warnings);

                // Assert.
                Assert.Equal(0, warnings.Count);
                Assert.Equal(0, variables.Public.Count());
                Assert.Equal("before some variable 2 value after", variables.Get("variable1"));
                Assert.Equal("some variable 2 value", variables.Get("variable2"));
            }
        }
开发者ID:codedebug,项目名称:vsts-agent,代码行数:26,代码来源:VariablesL0.cs


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