using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace DotNetHelper
{
#region // AssemblyProperties
///
/// Contains static properties that reflect this assembly's properties, such as Title and Version.
///
public static class AssemblyProperties
{
#region Properties ------------------------------------------
///
/// Retrieves the title of the currently executing assembly.
///
public static string AssemblyTitle
{
get
{
// Get all Title attributes on this assembly
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
// If there is at least one Title attribute
if (attributes.Length > 0)
{
// Select the first one
AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
// If it is not an empty string, return it
if (titleAttribute.Title != "")
return titleAttribute.Title;
}
// If there was no Title attribute, or if the Title attribute was the empty string, return the .exe name
return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
}
}
///
/// Retrieves the version of the currently executing assembly.
///
public static string AssemblyVersion
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
///
/// Retrieves the trademark of the currently executing assembly.
///
public static string AssemblyTrademark
{
get
{
// Get all Description attributes on this assembly
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTrademarkAttribute), false);
// If there aren't any Description attributes, return an empty string
if (attributes.Length == 0)
return "";
// If there is a Description attribute, return its value
return ((AssemblyTrademarkAttribute)attributes[0]).Trademark;
}
}
///
/// Retrieves the description of the currently executing assembly.
///
public static string AssemblyDescription
{
get
{
// Get all Description attributes on this assembly
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
// If there aren't any Description attributes, return an empty string
if (attributes.Length == 0)
return "";
// If there is a Description attribute, return its value
return ((AssemblyDescriptionAttribute)attributes[0]).Description;
}
}
///
/// Retrieves the product of the currently executing assembly.
///
public static string AssemblyProduct
{
get
{
// Get all Product attributes on this assembly
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
// If there aren't any Product attributes, return an empty string
if (attributes.Length == 0)
return "";
// If there is a Product attribute, return its value
return ((AssemblyProductAttribute)attributes[0]).Product;
}
}
///
/// Retrieves the copyright of the currently executing assembly.
///
public static string AssemblyCopyright
{
get
{
// Get all Copyright attributes on this assembly
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
// If there aren't any Copyright attributes, return an empty string
if (attributes.Length == 0)
return "";
// If there is a Copyright attribute, return its value
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
}
}
///
/// Retrieves the company of the currently executing assembly.
///
public static string AssemblyCompany
{
get
{
// Get all Company attributes on this assembly
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
// If there aren't any Company attributes, return an empty string
if (attributes.Length == 0)
return "";
// If there is a Company attribute, return its value
return ((AssemblyCompanyAttribute)attributes[0]).Company;
}
}
#endregion // Properties
}
#endregion // AssemblyProperties
#region // FileSystemHelper
class FileSystemHelper
{
///
/// Removes any read-only attributes from files in a directory, optionally recursively.
///
/// The directory from which to remove read-only attributes from files.
/// If true, attributes are changed for all sub-folders recursively.
///
/// The function can be useful when you want to delete a directory that may or may not
/// contain file that are read-only.
///
public static void MakeDirectoryReadWrite(string path, bool bRecurse)
{
string[] files = System.IO.Directory.GetFiles(path);
foreach (string file in files)
{
System.IO.File.SetAttributes(file, System.IO.FileAttributes.Normal);
}
if (bRecurse)
{
string[] directories = System.IO.Directory.GetDirectories(path);
foreach (string directory in directories)
{
MakeDirectoryReadWrite(directory, bRecurse);
}
}
}
}
#endregion // FileSystemHelper
}