コード例 #1
0
        static PrintContext WriteVars(PrintContext ctx)
        {
            var info = ctx.Info;
            var vars = new string[info.Arguments.Length];

            for (int index = 0; index < info.Arguments.Length; index++)
            {
                var arg = info.Arguments[index];
                if (arg == null)
                {
                    continue;      // nulls are handled by NullFormatter
                }
                if (arg is OwnFormatter)
                {
                    continue;              // check if it can format itself
                }
                if (ctx.CustomFormatters.Any(f => f.CanFormat(arg)))
                {
                    continue;                                          // check with out formatters
                }
                // get a new variable name (it might be taken already!)
                var methodParamName = ctx.ForBaseName(info.Method.GetParameters()[index].Name).Next();
                vars[index] = methodParamName;

                ctx.Builder.AppendLine(
                    new string(' ', ctx.SpaceIndentation)
                    + ctx.VariableFormatter.Format(arg, methodParamName));
            }
            return(ctx.SetWrittenVars(vars));
        }
コード例 #2
0
    static PrintContext WriteVars(PrintContext ctx) {
      var info = ctx.Info;
      var vars = new string[info.Arguments.Length];
      for (int index = 0; index < info.Arguments.Length; index++) {
        var arg = info.Arguments[index];
        if (arg == null) continue; // nulls are handled by NullFormatter
        if (arg is OwnFormatter) continue; // check if it can format itself
        if (ctx.CustomFormatters.Any(f => f.CanFormat(arg))) continue; // check with out formatters

        // get a new variable name (it might be taken already!)
        var methodParamName = ctx.ForBaseName(info.Method.GetParameters()[index].Name).Next();
        vars[index] = methodParamName;

        ctx.Builder.AppendLine(
          new string(' ', ctx.SpaceIndentation)
          + ctx.VariableFormatter.Format(arg, methodParamName));
      }
      return ctx.SetWrittenVars(vars);
    }