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


C# IO.StringWriter类代码示例

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


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

示例1: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            DataBooks book=new DataBooks();
            book.name = context.Request["bookname"];
            book.type = context.Request["booktype"];
            if(book.name!=null)
                bookcollector.Add(book);

            context.Response.ContentType = "text/html";
            VelocityEngine vltEngine = new VelocityEngine();
            vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/templates"));//模板文件所在的文件夹
            vltEngine.Init();

            VelocityContext vltContext = new VelocityContext();

            //vltContext.Put("msg", "");
            vltContext.Put("bookcollector", bookcollector);
            vltContext.Put("book", book);

            Template vltTemplate = vltEngine.GetTemplate("Front/ShopingCar.html");//模版文件所在位置

            System.IO.StringWriter vltWriter = new System.IO.StringWriter();
            vltTemplate.Merge(vltContext, vltWriter);
            string html = vltWriter.GetStringBuilder().ToString();
            context.Response.Write(html);
        }
开发者ID:ujsxn,项目名称:UJSBookStore,代码行数:27,代码来源:ShopingCar.ashx.cs

示例2: OrganizeExternalNamespaces

 void OrganizeExternalNamespaces()
 {
     foreach (Assembly asm in Parameters.References)
     {
         try
         {
             NameResolutionService.OrganizeAssemblyTypes(asm);
         }
         catch (ReflectionTypeLoadException x)
         {
             System.IO.StringWriter loadErrors = new System.IO.StringWriter();
             loadErrors.Write("'" + asm.FullName + "' - (" + GetLocation(asm) + "):");
             loadErrors.WriteLine(x.Message);
             foreach(Exception e in x.LoaderExceptions)
             {
                 loadErrors.WriteLine(e.Message);
             }
             Errors.Add(
                 CompilerErrorFactory.FailedToLoadTypesFromAssembly(
                     loadErrors.ToString(), x));
         }
         catch (Exception x)
         {
             Errors.Add(
                 CompilerErrorFactory.FailedToLoadTypesFromAssembly(
                     "'" + asm.FullName + "' - (" + GetLocation(asm) + "): " + x.Message, x));
         }
     }
 }
开发者ID:w4x,项目名称:boolangstudio,代码行数:29,代码来源:InitializeNameResolutionService.cs

示例3: GenerateString

		// This method is OPTIONAL
		//
		/// <summary>Executes the template and returns the output as a string.</summary>
		/// <returns>The template output.</returns>
		public string GenerateString ()
		{
			using (var sw = new System.IO.StringWriter ()) {
				Generate (sw);
				return sw.ToString ();
			}
		}
开发者ID:jtrent238,项目名称:My-App,代码行数:11,代码来源:Razor1.cs

示例4: ConvertToJsonString

 public string ConvertToJsonString(object obj)
 {
     JsonSerializer js = new JsonSerializer();
     System.IO.TextWriter tw = new System.IO.StringWriter();
     js.Serialize(tw, obj);
     return tw.ToString();
 }
开发者ID:bsimp6983,项目名称:BackupDashes,代码行数:7,代码来源:GetLineStatus.ashx.cs

示例5: Serialize

 /// <summary>
 /// Serializes an object as a string.
 /// </summary>
 public static string Serialize(object json)
 {
     var sb = new System.Text.StringBuilder();
     var sw = new System.IO.StringWriter(sb);
     SerializeTo(json, sw);
     return sw.ToString();
 }
开发者ID:edbutler,项目名称:papika-telemetry,代码行数:10,代码来源:MicroJSON.cs

示例6: Render

 /// <summary>
 /// 模版文件名
 /// </summary>
 /// <param name="templatefile"></param>
 /// <returns></returns>
 public string Render(string templatefile)
 {
     Template tmp = velocity.GetTemplate(templatefile);
     System.IO.StringWriter writer = new System.IO.StringWriter();
     tmp.Merge(context, writer);
     return writer.ToString();
 }
开发者ID:nkaluva,项目名称:helper,代码行数:12,代码来源:VelocityHelper.cs

示例7: AddInvit

        public ActionResult AddInvit(int id)
        {
            var user = this.serviceUser.GetById(id);
            VMAddInvit model = new VMAddInvit();
            model.DisplayName = user.DisplayName;
            model.UserId = user.Id;
            model.ThumbnailUrl = user.PictureUrl;
            model.Message = string.Format(
            @"Hello {0},

            I'm working on a project that could use your talents.  Would you consider contributing to my project?

            Thanks,
            {1}

            ",
                user.DisplayName,
                CurrentUser.DisplayName);

            //todo : find a better way
            JsonSerializer js = JsonSerializer.Create(new JsonSerializerSettings());
            var jw = new System.IO.StringWriter();
            js.Serialize(jw, model);
            model.JSON = jw.ToString();

            return View(model);
        }
开发者ID:jrocket,项目名称:MOG,代码行数:27,代码来源:SocialController.cs

示例8: PostProcess

 /// <summary>Called when extension shall process generated code</summary>
 /// <param name="code">The code</param>
 /// <param name="provider">CodeDOM provider (the language)</param>
 /// <version version="1.5.3">Parameter <c>Provider</c> renamed to <c>provider</c></version>
 public void PostProcess(ref string code, CodeDomProvider provider)
 {
     System.IO.StringWriter tw = new System.IO.StringWriter();
     provider.GenerateCodeFromStatement(new CodeCommentStatement(FirtsLineOfAccessor), tw, new System.CodeDom.Compiler.CodeGeneratorOptions());
     string srch = tw.GetStringBuilder().ToString();
     if (srch.EndsWith("\r\n")) srch = srch.Substring(0, srch.Length - 2);
     else if (srch.EndsWith("\r") || srch.EndsWith("\n")) srch = srch.Substring(0, srch.Length - 1);
     tw = new System.IO.StringWriter();
     CodeTypeDeclaration foo = new CodeTypeDeclaration("foo");
     foo.CustomAttributes.Add(NewAttribute);
     provider.GenerateCodeFromType(foo, tw, new System.CodeDom.Compiler.CodeGeneratorOptions());
     string attr = new System.IO.StringReader(tw.GetStringBuilder().ToString()).ReadLine();
     System.IO.StringReader sr = new System.IO.StringReader(code);
     List<String> Lines = new List<string>();
     do {
         string line = sr.ReadLine();
         if (line == null) break;
         if (line.EndsWith(srch))
             Lines[Lines.Count - 1] = attr + "\r\n" + Lines[Lines.Count - 1];
         else
             Lines.Add(line);
     } while (true);
     System.Text.StringBuilder b = new System.Text.StringBuilder();
     foreach (string line in Lines)
         b.AppendLine(line);
     code = b.ToString();
 }
开发者ID:wskplho,项目名称:Tools,代码行数:31,代码来源:DebuggerStepThrough.cs

示例9: ToXML

 public string ToXML(Outbound.ContractTypes.VMAP vmap)
 {
     var stringwriter = new System.IO.StringWriter();
     var serializer = new XmlSerializer(vmap.GetType());
     serializer.Serialize(stringwriter, vmap);
     return stringwriter.ToString();
 }
开发者ID:tcns,项目名称:impulse,代码行数:7,代码来源:VASTExportController.cs

示例10: TightFormat

 //Designed for emitting binding objects created by Autobind.
 public static String TightFormat(Object o)
 {
     var stream = new System.IO.StringWriter();
     if (o == null) stream.Write("null\n");
     else
     {
         var obj = o as ScriptObject;
         if (obj == null) stream.Write("Not a script object.\n");
         else foreach (var prop in obj.ListProperties())
             {
                 var val = obj.GetProperty(prop.ToString());
                 stream.Write(prop.ToString() + ": ");
                 if (val == null) stream.Write("null");
                 else if (val is ScriptObject && Function.IsFunction(val as ScriptObject))
                     stream.Write((val as ScriptObject).GetProperty("@help"));
                 else if (val is ScriptObject && (val as ScriptObject).GetProperty("@lazy-reflection") != null)
                     stream.Write("lazy bind " + (val as ScriptObject).GetProperty("@lazy-reflection") + " on " +
                         ((val as ScriptObject).GetProperty("@source-type") as System.Type).Name);
                 else
                     stream.Write(val.ToString());
                 stream.Write("\n");
             }
     }
     return stream.ToString();
 }
开发者ID:Blecki,项目名称:misp,代码行数:26,代码来源:StandardLibrary.cs

示例11: Render

        /// <summary>
        /// Altera a posição do campos ocultos do aspnet para o topo da página, evitando assim o
        /// erro de validação do post.
        /// </summary>
        /// <param name="writer">HTML writer.</param>
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            System.IO.StringWriter stringWriter =
                new System.IO.StringWriter();
            HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
            base.Render(htmlWriter);
            string html = stringWriter.ToString();
            string[] aspnet_formelems = new string[5];
            aspnet_formelems[0] = "__EVENTTARGET";
            aspnet_formelems[1] = "__EVENTARGUMENT";
            aspnet_formelems[2] = "__VIEWSTATE";
            aspnet_formelems[3] = "__EVENTVALIDATION";
            aspnet_formelems[4] = "__VIEWSTATEENCRYPTED";
            foreach (string elem in aspnet_formelems)
            {
                //Response.Write("input type=""hidden"" name=""" & abc.ToString & """")
                int StartPoint = html.IndexOf("<input type=\"hidden\" name=\"" +
                  elem.ToString() + "\"");
                if (StartPoint >= 0)
                {
                    //does __VIEWSTATE exist?
                    int EndPoint = html.IndexOf("/>", StartPoint) + 2;
                    string ViewStateInput = html.Substring(StartPoint,
                      EndPoint - StartPoint);
                    html = html.Remove(StartPoint, EndPoint - StartPoint);
                    int FormStart = html.IndexOf("<form");
                    int EndForm = html.IndexOf(">", FormStart) + 1;
                    if (EndForm >= 0)
                        html = html.Insert(EndForm, ViewStateInput);
                }
            }

            writer.Write(html);
        }
开发者ID:ViniciusConsultor,项目名称:controle-compras,代码行数:39,代码来源:Page.cs

示例12: ToString

        /// <summary>
        /// Returns a string representation of this exception, including
        /// any inner exceptions.
        /// </summary>
        /// <returns>The string representation of this exception.</returns>
        public override string ToString()
        {
            //
            // This prints the exception Java style. That is, the outermost
            // exception, "Caused by:" to the innermost exception. The
            // stack trace is not nicely indented as with Java, but
            // without string parsing (perhaps tokenize on "\n"), it
            // doesn't appear to be possible to reformat it.
            //
            System.IO.StringWriter sw = new System.IO.StringWriter(CultureInfo.CurrentCulture);
            IceUtilInternal.OutputBase op = new IceUtilInternal.OutputBase(sw);
            op.setUseTab(false);
            op.print(GetType().FullName);
            op.inc();
            IceInternal.ValueWriter.write(this, op);
            sw.Write("\n");
            sw.Write(StackTrace);

            System.Exception curr = InnerException;
            while(curr != null)
            {
                sw.Write("\nCaused by: ");
                sw.Write(curr.GetType().FullName);
                if(!(curr is Ice.Exception))
                {
                    sw.Write(": ");
                    sw.Write(curr.Message);
                }
                sw.Write("\n");
                sw.Write(curr.StackTrace);
                curr = curr.InnerException;
            }

            return sw.ToString();
        }
开发者ID:bholl,项目名称:zeroc-ice,代码行数:40,代码来源:Exception.cs

示例13: ToXml

        /// <summary>
        /// Serialize an object into XML
        /// </summary>
        /// <param name="serializableObject">Object that can be serialized</param>
        /// <returns>Serial XML representation</returns>
        public static string ToXml(this object serializableObject)
        {
            string ret = "";

            Type serializableObjectType = serializableObject.GetType();

            using (System.IO.StringWriter output = new System.IO.StringWriter(new System.Text.StringBuilder())) {
                System.Xml.Serialization.XmlSerializer s = new System.Xml.Serialization.XmlSerializer(serializableObjectType);
                System.Xml.Serialization.XmlSerializerNamespaces xsn = new System.Xml.Serialization.XmlSerializerNamespaces();
                xsn.Add("", "");

                // get a list of the xml type attributes so that we can clean up the xml. In other words. remove extra namespace text.
                object[] attributes = serializableObjectType.GetCustomAttributes(typeof(System.Xml.Serialization.XmlTypeAttribute), false);
                if (attributes != null) {
                    System.Xml.Serialization.XmlTypeAttribute xta;
                    for (int i = 0; i < attributes.Length; i++) {
                        xta = (System.Xml.Serialization.XmlTypeAttribute)attributes[i];
                        //xsn.Add("ns" + 1, xta.Namespace);
                    }
                }

                s.Serialize(output, serializableObject, xsn);
                ret = output.ToString().Replace("utf-16", "utf-8").Trim();
            }

            return ret;
        }
开发者ID:nickfloyd,项目名称:restify,代码行数:32,代码来源:StringExtensions.cs

示例14: btnExport_Click

 protected void btnExport_Click(object sender, EventArgs e)
 {
     //string thamchieu = "";
     //if (Session["ThamChieu"] != null)
     //    thamchieu = Session["ThamChieu"].ToString();
     //else
     //{
     //    if (int.Parse(drDSClaim.SelectedValue.ToString()) != 0)
     //        thamchieu = drDSClaim.SelectedItem.Text;
     //}
     Response.ClearContent();
     Response.AddHeader("content-disposition", "attachment; filename=Income.xls");
     Response.ContentType = "application/ms-excel";
     Response.ContentEncoding = Encoding.Unicode;
     Response.BinaryWrite(Encoding.Unicode.GetPreamble());
     Response.Charset = "";
     //Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250");
     //sets font
     Response.Write("<font style='font-size:13.0pt; font-family:Times New Roman;'>");
     System.IO.StringWriter sw = new System.IO.StringWriter();
     HtmlTextWriter htw = new HtmlTextWriter(sw);
     gvDSincome.RenderControl(htw);
     Response.Write(sw.ToString());
     Response.End();
 }
开发者ID:baotiit,项目名称:savvyplatform,代码行数:25,代码来源:detailincome.aspx.cs

示例15: ToString

 public override string ToString() {
   XmlSerializer ser = new XmlSerializer(typeof(Brunet.Chat.Presence));
   System.IO.StringWriter sw = new System.IO.StringWriter();
   XmlWriter w = new XmlTextWriter(sw);
   ser.Serialize(w, this);
   return sw.ToString();
 }
开发者ID:xujyan,项目名称:brunet,代码行数:7,代码来源:Presence.cs


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