[c#-plist]c#生成plist文件

我总觉的,贴了这段代码,是一件很‘杯具’的事情。

作为一个iphone的码农,竟然就这样,懒得手写添加plist文件,而用代码生成。需求呢。就是把当前文件夹里面所有的某种或者某几种类型的文件,做一个目录。本例中,用的是txt当作示范。最终生成一个标准的,可以在xcode里面使用的一个plist文件。其实后来想想,完全可以使用ObjectiveC 实现,但是对于c#熟悉程度确实要好一点。。。



 

ExpandedBlockStart.gif 代码
     class  Program
    {
        
static   void  Main( string [] args)
        {
            
//  Create the file and writer.
            FileStream fs  =   new  FileStream( " info.plist " , FileMode.Create);
            XmlTextWriter w 
=   new  XmlTextWriter(fs, Encoding.UTF8);

            
//  Start the document.
            w.WriteStartDocument();
            
//  Add commets
            w.WriteComment( " DOCTYPE plist PUBLIC \ " - // Apple // DTD PLIST 1.0 // EN\" \" http://www.apple.com/DTDs/PropertyList-1.0.dtd ");
            
// PLIST START
            w.WriteStartElement( " plist " );
            
// PLIST VERSION
            w.WriteAttributeString( " version " " 1.0 " );

            w.WriteStartElement(
" array " );

            
string  pathName  =  System.Environment.CurrentDirectory;
            DirectoryInfo di 
=   new  DirectoryInfo(pathName);
            FileSystemInfo[] fsi 
=  di.GetFileSystemInfos();
            
foreach  (FileSystemInfo fi  in  fsi)
            {
                
if (fi.Extension.Contains( " .txt " ))
                {
                    
//  Write a key string pair
                    w.WriteStartElement( " dict " );
                    
                    w.WriteElementString(
" key " , fi.Name.ToString());
                    w.WriteElementString(
" string " , fi.Name.ToString());
                    w.WriteEndElement();
                }
            }

            
//  End the document.
            w.WriteEndElement();
            w.WriteEndElement();
            w.WriteEndDocument();
            w.Flush();
            fs.Close();

        }
    }

 

 

 

 




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值