• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IO.StringWriter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Format

 private string Format(string msg, params object[] args) {
   Contract.Requires(msg != null);
   Contract.Ensures(Contract.Result<string>() != null);
   if (System.Type.GetType("Mono.Runtime") != null) {  // MONO
     // something in mono seems to be broken so that calling
     // NamedDeclarations.ToString (and similar ToString methods)
     // causes a stack overflow. We therefore convert those to
     // strings by hand
     object[] fixedArgs = new object[cce.NonNull(args).Length];
     for (int i = 0; i < args.Length; ++i) {
       if (args[i] is NamedDeclaration) {
         fixedArgs[i] = cce.NonNull((NamedDeclaration)args[i]).Name;
       } else if (args[i] is Type) {
         System.IO.StringWriter buffer = new System.IO.StringWriter();
         using (TokenTextWriter stream = new TokenTextWriter("<buffer>", buffer, /*setTokens=*/ false, /*pretty=*/ false)) {
           cce.NonNull((Type)args[i]).Emit(stream);
         }
         fixedArgs[i] = buffer.ToString();
       } else if (args[i] is Expr) {
         System.IO.StringWriter buffer = new System.IO.StringWriter();
         using (TokenTextWriter stream = new TokenTextWriter("<buffer>", buffer, /*setTokens=*/ false, /*pretty=*/ false)) {
           cce.NonNull((Expr/*!*/)args[i]).Emit(stream, 0, false);
         }
         fixedArgs[i] = buffer.ToString();
       } else {
         fixedArgs[i] = args[i];
       }
     }
     args = fixedArgs;
   }
   return string.Format(msg, args);
 }
开发者ID:qunyanm,项目名称:boogie,代码行数:32,代码来源:ResolutionContext.cs


示例17: CreateRegistrationFile

        /// <summary>
        /// regisztrációs file elkészítése  
        /// </summary>
        /// <param name="registrationFileNameWithPath"></param>
        /// <param name="htmlContent"></param>
        public void CreateRegistrationFile(string registrationFileNameWithPath, string htmlContent)
        {

//using (FileStream fs = new FileStream("test.htm", FileMode.Create)) 
//{ 
//    using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8)) 
//    { 
//        w.WriteLine("<H1>Hello</H1>"); 
//    } 
//} 

            try
            {
                Helpers.DesignByContract.Require(!String.IsNullOrEmpty(registrationFileNameWithPath), "Registration file name with path cannot be null or empty!");

                System.IO.FileStream fs = new System.IO.FileStream(registrationFileNameWithPath, System.IO.FileMode.Create, System.IO.FileAccess.Write); //System.IO.FileShare.Write,

                System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(fs, System.Text.Encoding.GetEncoding(28592));

                System.IO.StringWriter stringWriter = new System.IO.StringWriter();

                stringWriter.Write(htmlContent);

                System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(stringWriter);

                streamWriter.WriteLine(stringWriter.ToString());

                streamWriter.Close();

            }
            catch (Exception ex) 
            {
                throw ex;
            }
        }
开发者ID:juaqaai,项目名称:CompanyGroup.ServiceLayers,代码行数:40,代码来源:RegistrationFileRepository.cs


示例18: Create

        /// <summary>
        /// Writes the code to string in the specific language
        /// and returns the string
        /// </summary>
        public static string Create(Language language, string expression, RegexOptions options)
        {
            CodeCompileUnit unit = Create(expression, options);

            System.Text.StringBuilder builder = new System.Text.StringBuilder();

            using (System.IO.StringWriter stringWriter = new System.IO.StringWriter(builder))
            {
                System.CodeDom.Compiler.ICodeGenerator generator;

                switch (language)
                {
                    case Language.CSharp:
                        System.CodeDom.Compiler.CodeGeneratorOptions genOptions = new System.CodeDom.Compiler.CodeGeneratorOptions();
                        genOptions.BracingStyle = "C";
                        generator = new Microsoft.CSharp.CSharpCodeProvider().CreateGenerator();
                        generator.GenerateCodeFromCompileUnit(unit, stringWriter, genOptions);
                        break;
                    case Language.VisualBasic:
                        generator = new Microsoft.VisualBasic.VBCodeProvider().CreateGenerator();
                        generator.GenerateCodeFromCompileUnit(unit, stringWriter, null);
                        break;
                }

                return builder.ToString();
            }
        }
开发者ID:78655931,项目名称:The-Regulator,代码行数:31,代码来源:CodeGenerator.cs


示例19: TimedLogToHTML

 public TimedLogToHTML(
     )
     : base()
 {
     this.HtmlLog = new StringBuilder();
     System.IO.StringWriter sw = new System.IO.StringWriter(this.HtmlLog);
     this.HtmlTextWriter = new System.Web.UI.HtmlTextWriter(sw);
     this.StepStarted += (o, e) =>
     {
         this.HtmlTextWriter.AddAttribute("data-offset", ((int)e.LogSection.Offset).ToString());
         this.HtmlTextWriter.RenderBeginTag("ul");
         this.HtmlTextWriter.RenderBeginTag("li");
         this.HtmlTextWriter.WriteEncodedText(e.LogSection.Title);
         this.HtmlTextWriter.RenderBeginTag("ul");
     };
     this.StepComplete += (o, e) =>
     {
         this.HtmlTextWriter.RenderEndTag();
         this.HtmlTextWriter.WriteLine();
         this.HtmlTextWriter.RenderEndTag();
         this.HtmlTextWriter.WriteLine();
         this.HtmlTextWriter.AddAttribute("data-duration", ((int)e.LogSection.Elapsed.TotalMilliseconds).ToString());
         this.HtmlTextWriter.AddAttribute("class", "duration");
         this.HtmlTextWriter.RenderBeginTag("span");
         this.HtmlTextWriter.RenderEndTag();
         this.HtmlTextWriter.RenderEndTag();
         this.HtmlTextWriter.WriteLine();
     };
     var ts = this.GetNewTimedLogSection();
     ts.Title = "Timed Log";
     this.Stack.Push(ts);
     ts.StartTiming();
 }
开发者ID:BarbaraHarris,项目名称:xcricap-validator,代码行数:33,代码来源:TimedLogToHTML.cs


示例20: ObjetoSerializado

 public static string ObjetoSerializado(Object Objeto)
 {
     System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(Objeto.GetType());
     System.IO.StringWriter textWriter = new System.IO.StringWriter();
     x.Serialize(textWriter, Objeto);
     return textWriter.ToString();
 }
开发者ID:pjeconde,项目名称:condeco,代码行数:7,代码来源:Funciones.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IO.TextReader类代码示例发布时间:2022-05-24
下一篇:
C# IO.StringReader类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap