- rssfeeder_src.zip
- RSSFeeder
- RSSBlogAPI
- RSSCommon
- RSSFeeder.sln
- RSSFeeder
- RSSFeederResources
- RSSFeederSetup
- Messages.ico
- RSSFeederSetup.vdproj
- Test
- RSSStarter
- RSSTests
- Thirdparty
- AxInterop.DHTMLEDLib.dll
- AxInterop.SHDocVw.dll
- Eyefinder.dll
- GotDotNet.Exslt.dll
- HttpDownloader.dll
- Interop.DHTMLEDLib.dll
- Interop.SHDocVw.dll
- Interop.WindowsInstaller.dll
- Microsoft.ApplicationBlocks.Updater.ActivationProcessors.dll
- Microsoft.ApplicationBlocks.Updater.dll
- Microsoft.ApplicationBlocks.Updater.Downloaders.dll
- Microsoft.Practices.EnterpriseLibrary.Caching.dll
- Microsoft.Practices.EnterpriseLibrary.Common.dll
- Microsoft.Practices.EnterpriseLibrary.Configuration.dll
- Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll
- Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll
- Microsoft.Practices.EnterpriseLibrary.Logging.dll
- Microsoft.Practices.EnterpriseLibrary.Security.Cache.CachingStore.dll
- Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll
- Microsoft.Practices.EnterpriseLibrary.Security.dll
- NotifyIconBalloon.dll
- SandBar.dll
- SandDock.dll
- SgmlReaderDll.dll
|
// Copyright � 2005 by Omar Al Zabir. All rights are reserved.
//
// If you like this code then feel free to go ahead and use it.
// The only thing I ask is that you don't remove or alter my copyright notice.
//
// Your use of this software is entirely at your own risk. I make no claims or
// warrantees about the reliability or fitness of this code for any particular purpose.
// If you make changes or additions to this code please mark your code as being yours.
//
// website http://www.oazabir.com, email OmarAlZabir@gmail.com, msn oazabir@hotmail.com
using System;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System.Reflection;
using System.Collections;
namespace RSSCommon.Helper
{
/// <summary>
/// Utility methods
/// </summary>
public class SerializationHelper
{
public const string RESOURCE_ASSEMBLY_PREFIX = "RSSFeederResources.";
public static XmlWriter Serialize( Stream stream, object o )
{
XmlTextWriter writer = new XmlTextWriter( stream, System.Text.Encoding.UTF8 );
XmlSerializer serializer = new XmlSerializer( o.GetType() );
serializer.Serialize( writer, o );
return writer;
}
public static XmlWriter Serialize( Stream stream, ArrayList array, Type type )
{
XmlTextWriter writer = new XmlTextWriter( stream, System.Text.Encoding.UTF8 );
XmlSerializer serializer = new XmlSerializer( typeof(ArrayList), new Type[] { type } );
serializer.Serialize( writer, array );
return writer;
}
public static object Deserialize( Stream stream, Type t )
{
XmlTextReader reader = new XmlTextReader( stream );
XmlSerializer serializer = new XmlSerializer( t );
object o = serializer.Deserialize( reader );
return o;
}
public static ArrayList DeserializeArraylist( Stream stream, Type t )
{
XmlTextReader reader = new XmlTextReader( stream );
XmlSerializer serializer = new XmlSerializer( typeof( ArrayList ), new Type [] { t } );
ArrayList list = (ArrayList) serializer.Deserialize( reader );
return list;
}
public static Stream GetStream( string name )
{
return GetResourceAssembly().GetManifestResourceStream(RESOURCE_ASSEMBLY_PREFIX + name);
}
public static System.Drawing.Icon GetIcon( string name )
{
using( Stream stream = GetStream( name ) )
{
return new System.Drawing.Icon( stream );
}
}
public static Assembly GetResourceAssembly()
{
return Assembly.LoadFrom("RSSFeederResources.dll");
}
public static void WriteEmbeddedFile( string name, string fileName )
{
using( Stream stream = GetStream( name ) )
{
FileInfo file = new FileInfo( fileName );
using( FileStream fileStream = file.Create() )
{
byte [] buf = new byte[ 1024 ];
int size;
while( (size = stream.Read( buf, 0, 1024 )) > 0 )
{
fileStream.Write( buf, 0, size );
}
}
}
}
public static void CopyProperties( object source, object destination )
{
PropertyInfo [] properties = source.GetType().GetProperties();
foreach( PropertyInfo prop in properties )
{
if( prop.CanWrite )
prop.SetValue( destination, prop.GetValue( source, null ), null );
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.