DelimitedFieldBuilder.cs :  » Persistence-Frameworks » FileHelpers-Library » FileHelpers » RunTime » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Persistence Frameworks » FileHelpers Library 
FileHelpers Library » FileHelpers » RunTime » DelimitedFieldBuilder.cs
using System;
using System.Diagnostics;
using System.Text;
using System.Xml;

namespace FileHelpers.RunTime{
  /// <summary>Used to create fields that are part of a dilimited record class.</summary>
  public sealed class DelimitedFieldBuilder: FieldBuilder
  {

    internal DelimitedFieldBuilder(string fieldName, string fieldType): base(fieldName, fieldType)
    {}

    internal DelimitedFieldBuilder(string fieldName, Type fieldType): base(fieldName, fieldType)
    {}

#if NET_2_0
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
#endif
        private bool mFieldQuoted = false;

    /// <summary>Indicates if the field is quoted with some char. (works with QuoteMode and QuoteChar)</summary>
    public bool FieldQuoted
    {
      get { return mFieldQuoted; }
      set { mFieldQuoted = value; }
    }

#if NET_2_0
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
#endif
        private char mQuoteChar = '"';

    /// <summary>Indicates the char used to quote this field. (only used when FieldQuoted is true)</summary>
    public char QuoteChar
    {
      get { return mQuoteChar; }
      set { mQuoteChar = value; }
    }

#if NET_2_0
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
#endif
        private QuoteMode mQuoteMode = QuoteMode.OptionalForRead;

    /// <summary>Indicates the QuoteMode for this field. (only used when FieldQuoted is true)</summary>
    public QuoteMode QuoteMode
    {
      get { return mQuoteMode; }
      set { mQuoteMode = value; }
    }

#if NET_2_0
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
#endif
        private MultilineMode mQuoteMultiline = MultilineMode.AllowForRead;

    /// <summary>Indicates if this quoted field can span multiple lines. (only used when FieldQuoted is true)</summary>
    public MultilineMode QuoteMultiline
    {
      get { return mQuoteMultiline; }
      set { mQuoteMultiline = value; }
    }



    internal override void AddAttributesCode(AttributesBuilder attbs, NetLanguage leng)
    {
      
      if (mFieldQuoted == true)
      {
        if (leng == NetLanguage.CSharp)
        {
          string quoteStr = mQuoteChar.ToString();
          if (mQuoteChar == '\'') quoteStr = @"\'";

          attbs.AddAttribute("FieldQuoted('" + quoteStr + "', QuoteMode." + mQuoteMode.ToString()+", MultilineMode." + mQuoteMultiline.ToString() +")");
        }
        else if (leng == NetLanguage.VbNet)
        {
          string quoteStr = mQuoteChar.ToString();
          if (mQuoteChar == '"') quoteStr = "\"\"";

          attbs.AddAttribute("FieldQuoted(\"" + quoteStr + "\"c, QuoteMode." + mQuoteMode.ToString()+", MultilineMode." + mQuoteMultiline.ToString() +")");
        }
      }
      
    }

    internal override void WriteHeaderAttributes(XmlHelper writer)
    {
    }

    internal override void WriteExtraElements(XmlHelper writer)
    {
      writer.WriteElement("FieldQuoted", this.FieldQuoted);
      writer.WriteElement("QuoteChar", this.QuoteChar.ToString(), "\"");
      writer.WriteElement("QuoteMode", this.QuoteMode.ToString(), "OptionalForRead");
      writer.WriteElement("QuoteMultiline", this.QuoteMultiline.ToString(), "AllowForRead");
    }

    internal override void ReadFieldInternal(XmlNode node)
    {
      XmlNode ele;
      
      FieldQuoted = node["FieldQuoted"] != null;
      
      ele = node["QuoteChar"];
      if (ele != null) QuoteChar = ele.InnerText[0];

      ele = node["QuoteMode"];
      if (ele != null) QuoteMode = (QuoteMode) Enum.Parse(typeof(QuoteMode), ele.InnerText);

      ele = node["QuoteMultiline"];
      if (ele != null) QuoteMultiline = (MultilineMode) Enum.Parse(typeof(MultilineMode), ele.InnerText);

    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.