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


C# StringWriter.GetStringBuilder方法代码示例

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


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

示例1: GenerateCS

        private void GenerateCS()
        {
            using (Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider())
            {
                CodeGeneratorOptions opts = new CodeGeneratorOptions();
                StringWriter sw = new StringWriter();
                provider.GenerateCodeFromMember(_method, sw, opts);
                StringReader sr = new StringReader(sw.GetStringBuilder().ToString());
                string line = sr.ReadLine();
                while (string.IsNullOrEmpty(line))
                    line = sr.ReadLine();
                int idx = line.IndexOf(" " + _method.Name + "(");
                idx = line.LastIndexOf(' ', idx - 1);

                if (_method.Statements.Count > 0)
                {
                    Text = "partial" + line.Remove(0, idx);
                    Text = sw.GetStringBuilder().Replace(line, Text).ToString();
                }
                else
                {
                    line = "partial" + line.Remove(0, idx);
                    idx = line.LastIndexOf(')');
                    Text = line.Remove(idx + 1) + ";" + Environment.NewLine;
                }
            }
        }
开发者ID:laymain,项目名称:CodeDomUtils,代码行数:27,代码来源:CodePartialMethod.cs

示例2: Create

 public static T_ShiftArrangeTemplate Create(ShiftTemplate item)
 {
     T_ShiftArrangeTemplate tst = new T_ShiftArrangeTemplate();
     tst.ID = item.ID;
     tst.Name = item.Name;
     tst.Options = item.Options;
     tst.Memo = item.Memo;
     if (item.Items != null && item.Items.Count > 0)
     {
         try
         {
             using (StringWriter writer = new StringWriter())
             {
                 XmlSerializer ser = new XmlSerializer(typeof(List<TemplateItem>));
                 ser.Serialize(writer, item.Items);
                 if (writer.GetStringBuilder() != null)
                 {
                     tst.Value = writer.GetStringBuilder().ToString();
                 }
             }
         }
         catch (Exception ex)
         {
             LJH.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
         }
     }
     return tst;
 }
开发者ID:chendeben,项目名称:508-Attendance,代码行数:28,代码来源:T_ShiftArrangeTemplate.cs

示例3: ConvertMethod

        public static string ConvertMethod(string input, out string name)
        {
            input = StripUnnecessarySymbols(input);
            var splitBySpace = input.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);

            var returnValue = splitBySpace.First();
            name = splitBySpace[1];
            var args = new List<string>();

            if (splitBySpace.Length > 2) {
                for (var i = 2; i < splitBySpace.Length; i++) {
                    var argumentType = ConvertType(splitBySpace[i++]);
                    var argument = ConvertType(splitBySpace[i], true);
                    args.Add(argumentType + " " + AdjustArgumentName(argument));
                }
            }

            using (var sw = new StringWriter()) {
                sw.Write("public static extern ");
                sw.Write(ConvertType(returnValue));
                sw.Write(" ");
                sw.Write(ConvertTypeName(name));
                sw.Write("(");
                foreach (var arg in args) {
                    sw.Write(arg);
                    sw.Write(", ");
                }
                if (args.Count > 0) {
                    sw.GetStringBuilder().Remove(sw.GetStringBuilder().Length - 2, 2);
                }
                sw.Write(")");
                sw.Write(";");
                return sw.ToString();
            }
        }
开发者ID:kaagati,项目名称:spectre,代码行数:35,代码来源:CSharpCodeConverter.cs

示例4: Window_Loaded

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ndc = new NorthwindDataContext();
            StringWriter sw = new StringWriter();
            ndc.Log = sw;

            Employee employee = ndc.Employees.Where(emp => emp.LastName.StartsWith("Davolio"))
                .Select(emp => emp).FirstOrDefault();

            MessageBox.Show(sw.GetStringBuilder().ToString());

            photo = new MemoryStream(employee.Photo.ToArray());
            MessageBox.Show(sw.GetStringBuilder().ToString());

            var empListing = ndc.Employees
                .Select(emp => new {
                    name = emp.FirstName + " " + emp.LastName,
                    adress = emp.Address,
                    city = emp.City,
                    postcode = emp.PostalCode,
                    country = emp.Country,
                    phone = emp.HomePhone
                }).AsQueryable();

            dgEmployees.ItemsSource = empListing;
            MessageBox.Show(sw.GetStringBuilder().ToString());
        }
开发者ID:ZipionLive,项目名称:MCTS-70-516-Training,代码行数:27,代码来源:MainWindow.xaml.cs

示例5: Main

        private static void Main(string[] args)
        {
            AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var configFileName = string.Empty;
            var unattendedMode = false;
            int numThreads = -1;

            var options = new CommandLineOptions();
            ICommandLineParser parser = new CommandLineParser();
            var writer = new StringWriter();
            if (parser.ParseArguments(args, options, writer))
            {
                configFileName = options.SessionFile;
                unattendedMode = options.Unattended;
                numThreads = options.NumberOfThreads;
            }
            if (writer.GetStringBuilder().Length > 0)
            {
                MessageBox.Show(writer.GetStringBuilder().ToString());
            }
            else
            {
                var f = new Form1(configFileName, unattendedMode, numThreads)
                {
                    StartPosition = FormStartPosition.CenterScreen
                };
                Application.Run(f);
            }
        }
开发者ID:ErikEJ,项目名称:SqlQueryStress,代码行数:32,代码来源:Program.cs

示例6: WithinAppDomain

 public static void WithinAppDomain(string expectedFile, string createdFile, IEnumerable<string> args)
 {
     var bd = AppDomain.CurrentDomain.BaseDirectory;
     var info = new AppDomainSetup()
     {
         ApplicationBase     = bd,
         ApplicationName     = Program + ".exe",
         ConfigurationFile   = Program + ".exe.config",
     };
     AppDomain ad = AppDomain.CreateDomain("DbMetal Sqlite Test", null, info);
     var t = typeof(DbMetalAppDomainSetup);
     var s = (DbMetalAppDomainSetup)ad.CreateInstanceAndUnwrap(t.Assembly.GetName().Name, t.FullName);
     var stderr = new StringWriter();
     s.SetStandardError(stderr);
     var testdir = Path.Combine(bd, Path.Combine("..", "tests"));
     var expectedDir = Path.Combine(testdir, "expected");
     s.Run(new []{
         "/provider:Sqlite",
         "/conn:Data Source=" + Path.Combine(testdir, "Northwind.db3"),
     }.Concat(args).ToArray());
     AppDomain.Unload(ad);
     if (stderr.GetStringBuilder().Length != 0)
         Console.Error.Write(stderr.GetStringBuilder().ToString());
     Assert.AreEqual(0, stderr.GetStringBuilder().Length);
     FileAssert.AreEqual(Path.Combine(expectedDir, string.Format (expectedFile, Program)), createdFile);
     File.Delete(createdFile);
 }
开发者ID:nlhepler,项目名称:mono,代码行数:27,代码来源:AppRunner.cs

示例7: Format

        public static string Format(HttpContext context, string pattern, VelocityContext velocitycontext)
        {
                using (var writer = new StringWriter())
                {
                    try
                    {
                        if (!_isInitialized)
                        {
                            var props = new ExtendedProperties();
                            props.AddProperty("file.resource.loader.path",
                                              new ArrayList(new[]
                                                                {
                                                                    ".",
                                                                    Path.Combine(
                                                                        context.Server.MapPath(feed.HandlerBasePath),
                                                                        "Patterns")
                                                                }));
                            Velocity.Init(props);
                            _isInitialized = true;
                        }
                        //Load patterns
                        var template = Patterns.Get(pattern, () => LoadTemplate(pattern));

                        template.Merge(velocitycontext, writer);
                        return writer.GetStringBuilder().ToString();

                    }
                    catch (Exception)
                    {
                        //Format failed some way
                        return writer.GetStringBuilder().ToString();
                    }
                }
        }
开发者ID:ridhouan,项目名称:teamlab.v6.5,代码行数:34,代码来源:Formatter.cs

示例8: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            var serializer = new Serializer();
            var writer = new StringWriter();

            // Additional Ip subnets
            var addSubnets = osm.ListSubnets()
                .Where<Subnet>(s => s.IpVersion == 4 && s.Name.StartsWith("add"));
            foreach (var s in addSubnets)
            {
                writer.Write("===================================\n");
                var subnet = osm.GetSubnet(s.Id);
                serializer.Serialize(writer, subnet);
            }

            ltAddSubnets.Text = writer.ToString();
            writer.GetStringBuilder().Clear();

            // Local Network subnets
            var localSubnets = osm.ListSubnets()
                .Where<Subnet>(s => s.IpVersion == 4 && s.Name.StartsWith("local-"));

            foreach (var s in localSubnets)
            {
                writer.Write("===================================\n");
                var subnet = osm.GetSubnet(s.Id);
                serializer.Serialize(writer, subnet);
            }

            ltLocalSubnets.Text = writer.ToString();
            writer.GetStringBuilder().Clear();

            // Ports
            var ports = osm.ListPorts();
            foreach (var p in ports)
            {
                writer.Write("===================================\n");
                var subnet = osm.GetPort(p.Id);
                serializer.Serialize(writer, subnet);
            }

            ltPorts.Text = writer.ToString();
            writer.GetStringBuilder().Clear();

            // Security Groups
            var groups = osm.ListNetworkSecurityGroups();
            foreach (var g in groups)
            {
                writer.Write("===================================\n");
                var group = osm.GetNetworkSecurityGroup(g.Id);
                serializer.Serialize(writer, group);
            }

            ltSecurityGroups.Text = writer.ToString();
            writer.GetStringBuilder().Clear();

        }
开发者ID:crowdy,项目名称:OpenStack-ConoHa,代码行数:57,代码来源:Network.aspx.cs

示例9: FolderPollInitTest

        public void FolderPollInitTest()
        {
            FolderPollConfig testConfig = new FolderPollConfig
            {
                Poll = new Poll[]
                {
                    new Poll
                    {
                        Domain = "domain",
                        Folder = @"C:\FolderPoll",
                        Impersonation = true,
                        Username = "username",
                        Password = "password",
                        NewFile = new NewFile
                        {
                            Filter = "*.txt",
                            Copy = new NewFileCopy
                            {
                                TargetFolder = @"C:\FolderPoll"
                            },
                            Move = new NewFileMove
                            {
                                TargetFolder = @"C:\FolderPoll"
                            },
                            Launch = new NewFileLaunch
                            {
                                Application = @"C:\Windows\notepad.exe",
                                Arguments = "{0}"
                            }
                        }
                    }
                }
            };

            var serializer = new XmlSerializer(typeof(FolderPollConfig));
            TextWriter streamWriter = new StreamWriter(@"C:\FolderPoll\testConfig.xml");
            serializer.Serialize(streamWriter, testConfig);
            streamWriter.Close();

            XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
            ns.Add(string.Empty, string.Empty);
            StringWriter stringWriter = new StringWriter();
            serializer.Serialize(stringWriter, testConfig, ns);
            stringWriter.GetStringBuilder().ToString();

            var fileInitObject = new FolderPollService();
            fileInitObject.Init(@"C:\FolderPoll\testConfig.xml", true);
            var stringInitObject = new FolderPollService();
            stringInitObject.Init(stringWriter.GetStringBuilder().ToString(), false);

            var privateFileInit = new PrivateObject(fileInitObject);
            var privateStringInit = new PrivateObject(stringInitObject);

            Assert.IsNotNull(privateFileInit.GetField("folderPoll"));
            Assert.IsNotNull(privateStringInit.GetField("folderPoll"));
        }
开发者ID:nickvil,项目名称:FolderPoll,代码行数:56,代码来源:source1.cs

示例10: DumpBuffer

 public static void DumpBuffer(byte[] buffer, int p, uint op, uint lng)
 {
     StringWriter sw = new StringWriter();
     sw = DumpBuffer(buffer, buffer.Length);
     Console.WriteLine("---------------------------------------------------");
     Console.WriteLine("Packet: {0} Opcode:{1} LngP:{2} LengB:{3}", p == 1 ? "C->" : "S->", op, lng, buffer.Length);
     Console.WriteLine("{0}", sw.GetStringBuilder());
     Console.WriteLine("---------------------------------------------------");
     tw.WriteLine("Packet: {0} Opcode:{1} LngP:{2} LengB:{3}", p == 1 ? "C->" : "S->", op, lng, buffer.Length);
     tw.Write(sw.GetStringBuilder());
     tw.WriteLine();
 }
开发者ID:CarlosX,项目名称:DarkEmu,代码行数:12,代码来源:Debug.cs

示例11: RenderHelperChildren

		/// <summary>
		/// Renders the content of a block helper.
		/// </summary>
		/// <param name="children">The children of the helper block.</param>
		/// <param name="context">The render context.</param>
		/// <param name="data">The new data model.</param>
		/// <returns>The string content of the result.</returns>
		private string RenderHelperChildren(IEnumerable<SyntaxTreeNode> children, RenderContext context, object data)
		{
			RenderContext targetContext = context;
			RenderContextScope scope = null;
			if (data != null)
			{
				scope = context.BeginScope(data);
				targetContext = scope.ScopeContext;
			}

			using (var writer = new StringWriter())
			{
				var renderer = new RenderingParserVisitor(writer, targetContext, context.ModelMetadataProvider);

				foreach (var node in children)
				{
					node.Accept(renderer);
				}

				if (scope != null)
				{
					scope.Dispose();
				}

				return writer.GetStringBuilder().ToString();
			}
		}
开发者ID:furesoft,项目名称:FuManchu,代码行数:34,代码来源:HelperBlockRenderer.cs

示例12: LineComponent1

        public void LineComponent1()
        {
            VelocityContext context = new VelocityContext();

            Template template = velocityEngine.GetTemplate(
                GetFileName(null, "componentusage1", TemplateTest.TMPL_FILE_EXT));

            StringWriter writer = new StringWriter();

            template.Merge(context, writer);

            System.Console.WriteLine(writer.GetStringBuilder().ToString());

            writer = new StringWriter();

            template.Merge(context, writer);

            System.Console.WriteLine(writer.GetStringBuilder().ToString());

            writer = new StringWriter();

            template.Merge(context, writer);

            System.Console.WriteLine(writer.GetStringBuilder().ToString());
        }
开发者ID:hatjhie,项目名称:NVelocity,代码行数:25,代码来源:ComponentDirectiveTestCase.cs

示例13: ExportStruct

		[Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
		public void ExportStruct ()
		{
			XmlSchemas schemas = Export (typeof (TimeSpan), "NSTimeSpan");
			Assert.AreEqual (1, schemas.Count, "#1");

			StringWriter sw = new StringWriter ();
			schemas[0].Write (sw);

			Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
				"<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
				"<xs:schema xmlns:tns=\"NSTimeSpan\" elementFormDefault=\"qualified\" targetNamespace=\"NSTimeSpan\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
				"  <xs:element name=\"TimeSpan\" type=\"tns:TimeSpan\" />{0}" +
				"  <xs:complexType name=\"TimeSpan\" />{0}" +
				"</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");

			schemas = Export (typeof (TimeSpan));
			Assert.AreEqual (1, schemas.Count, "#3");

			sw.GetStringBuilder ().Length = 0;
			schemas[0].Write (sw);

			Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
				"<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
				"<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
				"  <xs:element name=\"TimeSpan\" type=\"TimeSpan\" />{0}" +
				"  <xs:complexType name=\"TimeSpan\" />{0}" +
				"</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:29,代码来源:XmlSchemaExporterTests.cs

示例14: SimpleWriter

 public static void SimpleWriter()
 {
     var sw = new StringWriter();
     sw.Write(4);
     var sb = sw.GetStringBuilder();
     Assert.Equal("4", sb.ToString());
 }
开发者ID:Corillian,项目名称:corefx,代码行数:7,代码来源:StringWriterTests.cs

示例15: TestMethod1

        public void TestMethod1()
        {
            var input = new StringReader("2016 1");
            Console.SetIn(input);

            var writer = new StringWriter();
            Console.SetOut(writer);

            Program.Main(new[] { string.Empty });

            var consoleString = writer.GetStringBuilder().ToString();

            var expected =
            @"2016年01月

            日 月 火 水 木 金 土
                1  2
             3  4  5  6  7  8  9
            10 11 12 13 14 15 16
            17 18 19 20 21 22 23
            24 25 26 27 28 29 30
            31";

            Assert.AreEqual(expected, consoleString);
        }
开发者ID:yo-kondo,项目名称:CSharpStudy,代码行数:25,代码来源:ProgramTests.cs


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