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


C# Parameter.WithValue方法代码示例

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


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

示例1: CanBuildWithOverridingParameters

        public void CanBuildWithOverridingParameters()
        {
            var args = new RemoteBounceArguments() {Targets = new [] {"One"}};
            var param1 = new Parameter<string> {Name = "name1"};
            var param2 = new Parameter<string> { Name = "name2" };

            var argsWithParam1 = args.WithParameter(param1.WithValue("value1"));
            var argsWithParam2 = args.WithParameter(param2.WithValue("value2"));
            Assert.That(argsWithParam1.Parameters.Count(), Is.EqualTo(1));
            Assert.That(argsWithParam1.Parameters.ElementAt(0).Name, Is.EqualTo("name1"));
            Assert.That(((Parameter<string>) argsWithParam1.Parameters.ElementAt(0)).Value, Is.EqualTo("value1"));

            Assert.That(argsWithParam2.Parameters.Count(), Is.EqualTo(1));
            Assert.That(argsWithParam2.Parameters.ElementAt(0).Name, Is.EqualTo("name2"));
            Assert.That(((Parameter<string>) argsWithParam2.Parameters.ElementAt(0)).Value, Is.EqualTo("value2"));

            Assert.That(args.Parameters, Is.Empty);
        }
开发者ID:haos11,项目名称:bounce,代码行数:18,代码来源:RemoteBounceArgumentsTest.cs

示例2: RenderValue

    private Parameter RenderValue(string context, string content)
    {
      object value;
      var param = new Parameter();
      if (content.IsNullOrWhitespace())
      {
        return param.WithValue(content);
      }
      else if (TryFillParameter(content, param) && TryGetParamValue(param.Name, out value))
      {
        if (param.IsRaw) return param.WithValue((value ?? "").ToString());

        switch (context)
        {
          case "idlist":
            return param.WithValue(RenderSqlEnum(value, false, o => _context.Format(o)));
          case "in":
          case "not in":
            return param.WithValue(RenderSqlEnum(value, true, o => _context.Format(o)));
          case "like":
          case "not like":
            // Do something useful with context
            return param.WithValue(RenderSqlEnum(value, false, o => _context.Format(o)));
          default:
            return param.WithValue(RenderSqlEnum(value, false, o => _context.Format(o)));
        }
      }
      else if (context == "between" || context == "not between")
      {
        // Do something useful here
        return param.WithValue(content);
      }
      else if (context == "sql"
        || context == "where")
      {
        return param.WithValue(SqlReplace(content));
      }
      else if ((context == "in" || context == "not in")
            && content.TrimStart()[0] == '(')
      {
        content = content.Trim();
        if (content.Length > 2 && content[1] == '@')
        {
          // Dapper is trying to be too helpful with parameter expansion
          return param.WithValue(SqlReplace(content.TrimStart('(').TrimEnd(')')));
        }
        else
        {
          return param.WithValue(SqlReplace(content));
        }
      }
      else
      {
        return param.WithValue(content);
      }
    }
开发者ID:rneuber1,项目名称:InnovatorAdmin,代码行数:56,代码来源:ParameterSubstitution.cs

示例3: Main

        static void Main(string[] args)
        {
            var inputFile = new Parameter<FileInfo>
            {
                ShortName = "i",
                LongName = "input",
                ValueName = "filename",
                Description = "The path of the input file.",
            };

            var outputFile = new Parameter<FileInfo>()
            {
                ShortName = "o",
                LongName = "output",
                ValueName = "filename",
                Description = "The path of the output file.",
            };

            var playingOption = new Parameter<PlayingOption>()
            {
                ShortName = "p",
                LongName = "playing-option",
                Description = "The options for playing.",
            };

            var randomNumbers = new ParameterList<double>
            {
                ShortName = "r",
                LongName = "random",
                Description = "Random numbers.",
            };

            var fast = new Parameter<bool>
            {
                ShortName = "f",
                LongName = "fast",
                Description = "Make it fast.",
            };

            var culture = new Parameter<CultureInfo>
            {
                ShortName = "cu",
                LongName = "culture",
                Description = "The culture.",
                IsOptional = true,
                DefaultValue = CultureInfo.InvariantCulture
            };

            var count = new Parameter<int>()
            {
                ShortName = "c",
                LongName = "count",
                Description = "Count of something.",
                IsOptional = true,
                DefaultValue = 1,
                PossibleValues = { 1, 2, 3, 4, 5 },
                StaticContextParameters =
                {
                    randomNumbers
                }
            };

            var commandLine = new CommandLine
            {
                ProgramName = "sarcasmizer",

                Description = "This is a good program.",

                Parameters =
                {
                    inputFile,
                    outputFile,
                    playingOption,
                    count,
                    fast,
                    culture
                },

                Examples =
                {
                    new Example
                    {
                        Parameters =
                        {
                            inputFile.WithValue(new FileInfo("foo.txt")),
                            outputFile.WithValue(new FileInfo("bar.txt"))
                        },
                        Description = "Simple example."
                    },
                    new Example
                    {
                        Parameters =
                        {
                            inputFile.WithValue(new FileInfo("foo.txt")),
                            outputFile.WithValue(new FileInfo("bar.txt")),
                            count.WithValue(8)
                        },
                        Description = "Example."
                    },
                    new Example
//.........这里部分代码省略.........
开发者ID:davidnemeti,项目名称:Sarcasm,代码行数:101,代码来源:Program.cs


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