Archive for the ‘C#’ Category.

View and ViewModel pattern code snippet

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
	<CodeSnippet Format="1.0.0">
		<Header>
			<Title>ViewModel pattern snippet</Title>
			<Shortcut>viewmodel</Shortcut>
			<Description>Creates a view and viewmodel interface and a concreate view model </Description>
			<Author>Alex Boyne-Aitken</Author>
			<SnippetTypes>
				<SnippetType>Expansion</SnippetType>
			</SnippetTypes>
		</Header>
		<Snippet>
			<Declarations>
				<Literal>
					<ID>name</ID>
					<ToolTip>Base name</ToolTip>
					<Default>Class</Default>
				</Literal>
			</Declarations>
			<Code Language="csharp"><![CDATA[
    public interface I$name$View
    {
        I$name$ViewModel Model { get; set; }
    }

    public interface I$name$ViewModel
    {
        I$name$View View { get; }
    }

    class $name$ViewModel : I$name$ViewModel
    {
        private readonly I$name$View view;

        public $name$ViewModel(I$name$View view)
        {
            this.view = view;
            view.Model = this;
        }

        public I$name$View View
        {
            get { return view; }
        }
    }
			$end$]]>
			</Code>
		</Snippet>
	</CodeSnippet>
</CodeSnippets>

Download

A managed Guild Wars Template Parser

I am currently working on a small project to help me organise my Guild Wars skill builds but I came across a problem, I had nothing to help me decode the templates and I found I had a gap in my knowledge when dealing with converting binary and base 64.

I found some source code long ago from GWFreaks however it was so old, messy and written in VB.NET that I really struggled to understand it. The last resort was a PHP based version of the template parser and a small snippet I found on a Code Guru forum. With this information I begun playing around and eventually began to build a greater understanding of what was involved.

Using the wiki guide on the Skill Template Format and the Equipment Template Format I finally built a set of objects to help encode and decode the templates.

You will find the details and the project files on the Template Parser project page