Format() публичный Метод

Formats a string, see class description for formatting instructions
public Format ( string format ) : string
format string
Результат string
Пример #1
0
        /// <summary>
        /// Looks for {[..]} constructions in the specified expression,
        /// and calls the callback for each of them replacing its occurance with the
        /// return value of the callback
        /// </summary>
        /// <param name="expression"></param>
        /// <param name="cb"></param>
        /// <returns></returns>
        public static string ReplaceVariables(string expression, VariableDetectedCB cb)
        {
            SimpleFormatter f = new SimpleFormatter ();
            f.OnGetParameter += delegate(string parameterName) {
                return cb (parameterName);
            };

            return f.Format (expression);
        }
        public void SendCommand(RemoteControlProtocol r)
        {
            RemoteProcessInfo[] processes = null;
            ManualResetEvent evt = new ManualResetEvent (false);

            r.RemoteProcessInfo += delegate(RemoteProcessInfo[] lProcesses) {
                processes = lProcesses;
                evt.Set ();
            };

            SimpleFormatter f = new SimpleFormatter ();
            f.OnGetParameter += delegate(string parameterName) {
                KeyValuePair<string, string>? keyP = StringHelper.SplitToKeyValue (parameterName, "|");
                if (keyP == null)
                    throw new ArgumentException ("Invalid variable speciication");

                switch (keyP.Value.Key)
                {
                case "remote-pid":
                    if (processes == null)
                    {
                        r.RemoteProcesses ();
                        evt.WaitOne ();
                    }
                    RemoteProcessInfo procInfo = FindProcess (processes, keyP.Value.Value);
                    if (procInfo == null)
                        throw new ArgumentException (string.Format ("Could not find process '{0}'", keyP.Value.Value));
                    return procInfo.Pid.ToString ();

                default:
                    throw new NotSupportedException ("The specified variable is not supported");
                }
            };

            string newCmd = f.Format (_cmd.Path);
            List<string> newArgs = new List<string> ();
            foreach (string arg in _cmd.Args)
                newArgs.Add (f.Format (arg));

            List<string> newEnv = new List<string> ();
            foreach (String env in _cmd.EnvP)
                newEnv.Add (f.Format (env));

            r.SendCommand (new RemoteExecCommand (_cmd.Name, newCmd, newArgs, newEnv));
        }
Пример #3
0
        public static string StaticFormat(string format, params object[] args)
        {
            SimpleFormatter formatter = new SimpleFormatter ();

            return formatter.Format (format, args);
        }