Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding Examples project.

  • Loading branch information...
commit dc28c904cc9e0bfe60aeaa02d36a1d61dfcf9156 1 parent d37a404
@idavis authored
View
6 Archetype.sln
@@ -5,6 +5,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Archetype", "src\Archetype\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Archetype.Tests", "src\Archetype.Tests\Archetype.Tests.csproj", "{ECC39D5A-879B-45CF-85DF-3BDD60C58EEF}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Archetype.Examples", "src\Archetype.Examples\Archetype.Examples.csproj", "{759220DD-3017-4331-8F37-7C0B7F2ACDC7}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -19,6 +21,10 @@ Global
{ECC39D5A-879B-45CF-85DF-3BDD60C58EEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ECC39D5A-879B-45CF-85DF-3BDD60C58EEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ECC39D5A-879B-45CF-85DF-3BDD60C58EEF}.Release|Any CPU.Build.0 = Release|Any CPU
+ {759220DD-3017-4331-8F37-7C0B7F2ACDC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {759220DD-3017-4331-8F37-7C0B7F2ACDC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {759220DD-3017-4331-8F37-7C0B7F2ACDC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {759220DD-3017-4331-8F37-7C0B7F2ACDC7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
65 src/Archetype.Examples/Archetype.Examples.csproj
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{759220DD-3017-4331-8F37-7C0B7F2ACDC7}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Archetype.Examples</RootNamespace>
+ <AssemblyName>Archetype.Examples</AssemblyName>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <TargetFrameworkProfile />
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <Prefer32Bit>false</Prefer32Bit>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <Prefer32Bit>false</Prefer32Bit>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="nunit.framework">
+ <HintPath>..\Archetype.Tests\bin\Debug\nunit.framework.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="NotifyPropertyChangesExamples.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Archetype\Archetype.csproj">
+ <Project>{74AAF77C-A943-489A-A78C-3612FA2CC938}</Project>
+ <Name>Archetype</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
View
173 src/Archetype.Examples/NotifyPropertyChangesExamples.cs
@@ -0,0 +1,173 @@
+#region License
+
+//
+// Copyright (c) 2012, Ian Davis
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// See the file LICENSE.txt for details.
+//
+
+#endregion
+
+#region Using Directives
+
+using System;
+using System.ComponentModel;
+using NUnit.Framework;
+
+#endregion
+
+namespace Archetype.Examples
+{
+ public interface INotifyPropertyChanges : INotifyPropertyChanged, INotifyPropertyChanging
+ {
+ void OnPropertyChanged( string propertyName = "" );
+ void OnPropertyChanging( string propertyName = "" );
+ }
+
+ public class NotifyPropertyChangesModule : INotifyPropertyChanges
+ {
+ #region INotifyPropertyChanges Members
+
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ public event PropertyChangingEventHandler PropertyChanging;
+
+ public virtual void OnPropertyChanged( string propertyName = "" )
+ {
+ PropertyChangedEventHandler handler = PropertyChanged;
+ if ( handler != null )
+ {
+ handler( this, new PropertyChangedEventArgs( propertyName ) );
+ }
+ }
+
+ public virtual void OnPropertyChanging( string propertyName = "" )
+ {
+ PropertyChangingEventHandler handler = PropertyChanging;
+ if ( handler != null )
+ {
+ handler( this, new PropertyChangingEventArgs( propertyName ) );
+ }
+ }
+
+ #endregion
+ }
+
+ public class Person : DelegatingObject
+ {
+ private int _Age;
+ private string _Name;
+
+ public Person()
+ : this( new NotifyPropertyChangesModule() )
+ {
+ }
+
+ public Person( params object[] modules )
+ : base( modules )
+ {
+ }
+
+ public string Name
+ {
+ get { return _Name; }
+ set
+ {
+ This.OnPropertyChanging( "Name" );
+ if ( _Name != value )
+ {
+ _Name = value;
+ This.OnPropertyChanged( "Name" );
+ }
+ }
+ }
+
+ public int Age
+ {
+ get { return _Age; }
+ set
+ {
+ Inpc.OnPropertyChanging( "Age" );
+ if ( _Age != value )
+ {
+ _Age = value;
+ Inpc.OnPropertyChanged( "Age" );
+ }
+ }
+ }
+
+ private dynamic This
+ {
+ get { return this; }
+ }
+
+ internal INotifyPropertyChanges Inpc
+ {
+ get { return This; }
+ }
+ }
+
+ [TestFixture]
+ public class PersonExamples
+ {
+ [Test]
+ public void SharedModulesToShareBehavior()
+ {
+ var module = new NotifyPropertyChangesModule();
+ module.PropertyChanged +=
+ ( sender, args ) => Console.WriteLine( "The field {0} has changed.", args.PropertyName );
+ module.PropertyChanging +=
+ ( sender, args ) => Console.WriteLine( "The field {0} is changing.", args.PropertyName );
+ var inigo = new Person( module ) { Name = "Inigo" };
+ var ian = new Person( module ) { Name = "Ian" };
+
+ inigo.Age = 45;
+ ian.Age = 30;
+ }
+
+ [Test]
+ public void UsingModelObjectAsDynamic()
+ {
+ dynamic person = new Person();
+ // The cast to the interface will work
+ INotifyPropertyChanges inpc = person;
+ inpc.PropertyChanged +=
+ ( sender, args ) => Console.WriteLine( "The field {0} has changed.", args.PropertyName );
+ inpc.PropertyChanging +=
+ ( sender, args ) => Console.WriteLine( "The field {0} is changing.", args.PropertyName );
+ // We have full IntelliSense when working with person.
+ // but now accessing .Name looses IntelliSense
+ person.Name = "Inigo Montoya";
+ }
+
+ [Test]
+ public void UsingModelObjectAsStronglyTyped()
+ {
+ var person = new Person();
+ // Casting first to dynamic triggers the DelegatingObjects casting system
+ INotifyPropertyChanges inpc = (dynamic) person;
+ inpc.PropertyChanged +=
+ ( sender, args ) => Console.WriteLine( "The field {0} has changed.", args.PropertyName );
+ inpc.PropertyChanging +=
+ ( sender, args ) => Console.WriteLine( "The field {0} is changing.", args.PropertyName );
+ // We have full IntelliSense when working with person.
+ // We have full IntelliSense when working with person.
+ person.Name = "Inigo Montoya";
+ }
+
+ [Test]
+ public void UsingModelWithProxyCastingProperty()
+ {
+ var person = new Person();
+ // The cast to the interface will work
+ person.Inpc.PropertyChanged +=
+ ( sender, args ) => Console.WriteLine( "The field {0} has changed.", args.PropertyName );
+ person.Inpc.PropertyChanging +=
+ ( sender, args ) => Console.WriteLine( "The field {0} is changing.", args.PropertyName );
+ // We have full IntelliSense when working with person.
+ // but now accessing .Name looses IntelliSense
+ person.Name = "Inigo Montoya";
+ }
+ }
+}
View
36 src/Archetype.Examples/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Archetype.Examples")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Archetype.Examples")]
+[assembly: AssemblyCopyright("Copyright © 2012")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("31c28bdb-61c1-492f-b083-16babf0fa7a4")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
Please sign in to comment.
Something went wrong with that request. Please try again.