Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Game Attack Combos : WPF Hybrid Smart Client for Combo Calculations

, 23 May 2009
A WPF hybrid smart client for calculating attack combos in the Prince of Persia game.
Prize winner in Competition "Smart Client Article Contest"
GameAttackCombos_Src.zip
ComboServices
App_Data
ComboPackagesService.svc
GameAttackCombos.snk
Properties
GameAttackCombos.mdf
GameAttackCombos_log.LDF
Packages
PrinceOfPersia2008.gcp
PrinceOfPersia2010.gcp
PackageComboFiles
Properties
ServiceData
GameAttackCombosModel.edmx
Properties
Assets
Button Icons.design
Game Attack Combos Icon.design
Game Attack Combos Icon.ico
Prince of Persia 2008
Prince of Persia 2010
PrinceOfPersia2010Background.png
PrinceOfPersia2010Icon.png
PrinceOfPersia2008Background.png
PrinceOfPersia2008Icon.png
ComboClient
Game Attack Combos Icon.ico
Properties
Resources
Service References
Supporting
Themes
ComboServices
ComboPackagesService.disco
ComboPackagesService.wsdl
ComboPackagesService1.wsdl
configuration.svcinfo
configuration91.svcinfo
Reference.svcmap
app.manifest
ComboLogic
Properties
GameAttackCombos_Standalone.zip
Packages
PrinceOfPersia2008.gcp
PrinceOfPersia2010.gcp
Resources
using System;
using System.Reflection;

namespace GG.GameAttackCombos.Client {

	/// <summary>
	/// Gets the attribute values of an assembly.
	/// </summary>
	public class AssemblyAttributes {

		#region Properties

		public string Company { get; private set; }
		public string Copyright { get; private set; }
		public string Description { get; private set; }
		public string Product { get; private set; }
		public string Title { get; private set; }
		public string Trademark { get; private set; }
		public string Version { get; private set; }

		#endregion

		#region Constructors

		/// <summary>
		/// Creates an instance AssemblyAttributes with the specified assembly.
		/// </summary>
		/// <param name="assembly">An assembly to get attributes for.</param>
		public AssemblyAttributes(Assembly assembly) {
			GetAttributeValues(assembly);
		}

		/// <summary>
		/// Creates an instance of AssemblyAttributes with the default assembly.
		/// </summary>
		public AssemblyAttributes() : this(GetDefaultAssembly()) { }

		#endregion

		/// <summary>
		/// Gets the attribute values for the specified assembly and stores them in this 
		/// instance's properties.
		/// </summary>
		/// <param name="assembly">The assembly to retrieve from.</param>
		protected virtual void GetAttributeValues(Assembly assembly) {
			// Get the necessary attributes.
			AssemblyCompanyAttribute CompanyAttribute = GetCustomAttribute<AssemblyCompanyAttribute>(assembly);
			AssemblyCopyrightAttribute CopyrightAttribute = GetCustomAttribute<AssemblyCopyrightAttribute>(assembly);
			AssemblyDescriptionAttribute DescriptionAttribute = GetCustomAttribute<AssemblyDescriptionAttribute>(assembly);
			AssemblyProductAttribute ProductAttribute = GetCustomAttribute<AssemblyProductAttribute>(assembly);
			AssemblyTitleAttribute TitleAttribute = GetCustomAttribute<AssemblyTitleAttribute>(assembly);
			AssemblyTrademarkAttribute TrademarkAttribute = GetCustomAttribute<AssemblyTrademarkAttribute>(assembly);
			AssemblyVersionAttribute VersionAttribute = GetCustomAttribute<AssemblyVersionAttribute>(assembly);

			// Set the necessary properties to the attribute values.
			Company = (CompanyAttribute != null ? CompanyAttribute.Company : null);
			Copyright = (CopyrightAttribute != null ? CopyrightAttribute.Copyright : null);
			Description = (DescriptionAttribute != null ? DescriptionAttribute.Description : null);
			Product = (ProductAttribute != null ? ProductAttribute.Product : null);
			Title = (TitleAttribute != null ? TitleAttribute.Title : null);
			Trademark = (TrademarkAttribute != null ? TrademarkAttribute.Trademark : null);
			Version = (VersionAttribute != null ? VersionAttribute.Version : null);
		}

		/// <summary>
		/// Gets the first custom attribute of type T found for the specified Assembly.
		/// </summary>
		/// <typeparam name="T">The attribute type to find.</typeparam>
		/// <param name="assembly">The assembly to search on.</param>
		/// <returns></returns>
		protected T GetCustomAttribute<T>(Assembly assembly) where T : Attribute {
			T CustomAttribute = null;

			if (assembly != null) {
				object[] CustomAttributes = assembly.GetCustomAttributes(typeof(T), false);
				if (CustomAttributes != null && CustomAttributes.Length > 0) {
					CustomAttribute = (T)CustomAttributes[0];
				}
			}

			return CustomAttribute;
		}

		/// <summary>
		/// Gets the default assembly.
		/// </summary>
		/// <returns></returns>
		private static Assembly GetDefaultAssembly() {
			// First, attempt to get the entry assembly.
			Assembly DefaultAssembly = Assembly.GetEntryAssembly();
			if (DefaultAssembly == null) {
				// Next, attempt to get the executing assembly.
				DefaultAssembly = Assembly.GetExecutingAssembly();
				if (DefaultAssembly == null) {
					// Finally, attempt to get the calling assembly.
					DefaultAssembly = Assembly.GetCallingAssembly();
				}
			}

			return DefaultAssembly;
		}

	}

}

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Matt Sollars
Web Developer
United States United States
I began programming on my Commodore 64 at around the age of 12. After migrating to DOS and then Windows, I decided to take on the Web. Several languages and platforms later, I have settled in with .NET nicely. I am currently the owner of a software consulting company and lead application developer for a learning-based technology consultation company.
 
The love of a finished application is usually at war with the desire to improve it as soon as it's released (they're never really finished).

| Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 23 May 2009
Article Copyright 2009 by Matt Sollars
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid