Skip to content
This repository has been archived by the owner on Apr 13, 2020. It is now read-only.

Commit

Permalink
Theory for Multicast Mixin Rules (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Pittle committed Jul 6, 2014
1 parent 0068254 commit 030d031
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pMixins.TheorySandbox/IMixinMulticastRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;

namespace CopaceticSoftware.pMixins.TheorySandbox
{
/// <summary>
/// Basis for applying mulitcast rules. Inheritors can be located anywhere,
/// pMixin code generator will find them!
/// </summary>
public interface IMixinMulticastRule
{
IEnumerable<Type> MixinsForTypes(string typeFullName);
}
}
21 changes: 21 additions & 0 deletions pMixins.TheorySandbox/MulticastRule/MulticastMixin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;

namespace CopaceticSoftware.pMixins.TheorySandbox.MulticastRule
{
public class MulticastMixin
{
public int GetNumber()
{
return 42;
}
}

public class MulticastMixinRule : IMixinMulticastRule
{
public IEnumerable<Type> MixinsForTypes(string typeFullName)
{
yield return typeof (MulticastMixin);
}
}
}
89 changes: 89 additions & 0 deletions pMixins.TheorySandbox/MulticastRule/MulticastRuleSpec.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System.Collections.Generic;

namespace CopaceticSoftware.pMixins.TheorySandbox.MulticastRule
{
/// <summary>
/// Because of <see cref="MulticastMixinRule"/>,
/// <see cref="MulticastMixin"/> should be applied here.
/// </summary>
public partial class MulticastRuleSpec
{
}

/*/////////////////////////////////////////
/// Generated Code
/////////////////////////////////////////*/
public partial class MulticastRuleSpec
{
private class __pMixinAutoGenerated
{
public class CopaceticSoftware_pMixin_TheorySandbox_Interceptors_BasicInterceptor_Mixin
{
//don't need protected wrapper

//don't need abstract wrapper

public sealed class MasterWrapper : MasterWrapperBase
{
public readonly MulticastMixin Mixin;

public MasterWrapper(MulticastRuleSpec target)
{
this.Mixin = new MulticastMixin();

base.Initialize(target, Mixin,
new List<IMixinInterceptor>());
}

public int GetNumber()
{
return base.ExecuteMethod(
"Method",
new List<Parameter>(),
() => Mixin.GetNumber());
}
}
}
}

private sealed partial class __Mixins
{
public static readonly global::System.Object ____Lock = new global::System.Object();

public readonly __pMixinAutoGenerated.CopaceticSoftware_pMixin_TheorySandbox_Interceptors_BasicInterceptor_Mixin.MasterWrapper MixinMasterWrapper;

public __Mixins(MulticastRuleSpec target)
{
this.MixinMasterWrapper =
new DefaultMixinActivator()
.CreateInstance<__pMixinAutoGenerated.CopaceticSoftware_pMixin_TheorySandbox_Interceptors_BasicInterceptor_Mixin.MasterWrapper>(
target);
}
}

private __Mixins _____mixins;
private __Mixins ___mixins
{
get
{
if (null == _____mixins)
{
lock (__Mixins.____Lock)
{
if (null == _____mixins)
{
_____mixins = new __Mixins(this);
}
}
}
return _____mixins;
}
}

public int GetNumber()
{
return ___mixins.MixinMasterWrapper.GetNumber();
}
}
}

21 changes: 21 additions & 0 deletions pMixins.TheorySandbox/MulticastRule/MulticastRuleSpecTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using NBehave.Spec.NUnit;
using NUnit.Framework;

namespace CopaceticSoftware.pMixins.TheorySandbox.MulticastRule
{
public class MulticastRuleSpecTest : SpecTestBase
{
private MulticastRuleSpec _spec;

protected override void Establish_context()
{
_spec = new MulticastRuleSpec();
}

[Test]
public void CanCallMulticastMixinMethod()
{
_spec.GetNumber().ShouldEqual(42);
}
}
}
4 changes: 4 additions & 0 deletions pMixins.TheorySandbox/pMixins.TheorySandbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@
<Compile Include="COVERED\MixinIsTargetsNestedClass\MixinIsTargetsNestedClassSpecTest.cs" />
<Compile Include="MixinDependency\MixinDependencySpec.cs" />
<Compile Include="MixinDependency\MixinDependencySpecTest.cs" />
<Compile Include="IMixinMulticastRule.cs" />
<Compile Include="MulticastRule\MulticastMixin.cs" />
<Compile Include="MulticastRule\MulticastRuleSpec.cs" />
<Compile Include="MulticastRule\MulticastRuleSpecTest.cs" />
<Compile Include="MultipleMixinsMethodPriority\MultipleMixinsMethodPrioritySpec.cs" />
<Compile Include="COVERED\NonParameterlessConstructorMixin\NonParameterlessConstructorMixinSpec.cs" />
<Compile Include="COVERED\NonParameterlessConstructorMixin\NonParameterlessConstructorMixinSpecTest.cs" />
Expand Down

0 comments on commit 030d031

Please sign in to comment.