예제 #1
0
        protected override void ProcessRecord()
        {
            if (InputObject == null || InputObject.Length == 0)
            {
                return;
            }

            foreach (var obj in InputObject)
            {
                if (notFirst)
                {
                    if (Stream)
                    {
                        WriteObject("");
                    }
                    else
                    {
                        _lines.Add("");
                    }
                }
                notFirst = true;

                foreach (var line in FormatEngine.Format(obj))
                {
                    if (Stream)
                    {
                        WriteObject(line);
                    }
                    else
                    {
                        _lines.Add(line);
                    }
                }
            }
        }
예제 #2
0
        public void TestMethod1()
        {
            var result = FormatEngine.Format(typeof(string)).ToArray();

            Assert.AreEqual(1, result.Length);
            Assert.AreEqual(typeof(string).ToString(), result[0]);
        }
예제 #3
0
        public void TestListFormat()
        {
            var     currentProcess = Process.GetCurrentProcess();
            dynamic p = new PSObject(currentProcess);

            var properties         = new [] { "ProcessName", "MachineName", "Company" };
            var l                  = new ListFormat(ListEntries(properties));
            IEnumerable <string> r = FormatEngine.Format(p, l);
            var result             = r.ToArray();

            Assert.AreEqual(3, result.Length);
            var fmt = "{0,-" + properties.Max(prop => prop.Length) + "} : {1}";

            Assert.AreEqual(string.Format(fmt, "ProcessName", currentProcess.ProcessName), result[0]);
            Assert.AreEqual(string.Format(fmt, "MachineName", currentProcess.MachineName), result[1]);
            Assert.AreEqual(string.Format(fmt, "Company", p.Company), result[2]);
        }
예제 #4
0
파일: PSMore.cs 프로젝트: daxian-dbw/PSMore
        protected override void ProcessRecord()
        {
            if (InputObject == null || InputObject.Length == 0)
            {
                return;
            }

            bool first = true;

            _objects.AddRange(InputObject);
            foreach (var obj in InputObject)
            {
                foreach (var line in FormatEngine.Format(obj))
                {
                    if (!first)
                    {
                        Console.WriteLine();
                    }
                    first = false;
                    Console.WriteLine(line);
                }
            }
        }