Skip to content

Commit

Permalink
Allow Members names from FauxType
Browse files Browse the repository at this point in the history
  • Loading branch information
jbtule committed Jan 6, 2018
1 parent 091c333 commit 4f91b3f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
25 changes: 25 additions & 0 deletions Dynamitey/DynamicObjects/FauxType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public static implicit operator FauxType(Type type)
/// <returns></returns>
public abstract Type[] GetContainedTypes();

public abstract IEnumerable<string> GetMemberNames();

/// <summary>
/// Determines whether the specified type contains the type.
/// </summary>
Expand Down Expand Up @@ -72,6 +74,11 @@ public override IEnumerable<MemberInfo> GetMember(string binderName)
return Enumerable.Empty<MemberInfo>();
}

public override IEnumerable<string> GetMemberNames()
{
return PropertySpec.Keys;
}

public override Type[] GetContainedTypes()
{
return new Type []{};
Expand Down Expand Up @@ -129,6 +136,17 @@ public override IEnumerable<MemberInfo> GetMember(string binderName)
return TargetType.GetTypeInfo().GetMember(binderName);
}

public override IEnumerable<string> GetMemberNames()
{

var members = TargetType.GetTypeInfo()
.GetMembers(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance)
.Where(it=> !((it as MethodInfo)?.IsHideBySig ?? false))
.Select(it => it.Name)
.Distinct();
return members.ToList();
}

/// <summary>
/// Gets the contained types.
/// </summary>
Expand Down Expand Up @@ -188,14 +206,21 @@ public Type[] GetInterfaceTypes()
return Types.SelectMany(it => it.GetContainedTypes()).Where(it => it.GetTypeInfo().IsInterface).ToArray();
}

public override IEnumerable<string> GetMemberNames()
{
return Types.SelectMany(it => it.GetMemberNames()).Distinct();
}

/// <summary>
/// Adds the type.
/// </summary>
/// <param name="type">The type.</param>
public void AddType(Type type)
{
if (!ContainsType(type))
{
Types.Add(type);
}
}

/// <summary>
Expand Down
33 changes: 30 additions & 3 deletions Tests/Impromptu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
using System.Threading.Tasks;
using NUnit.Framework;
using Dynamitey;
using Dynamitey.DynamicObjects;
using Dynamitey.SupportLibrary;
using ImpromptuInterface;
using NUnit.Framework.Constraints;

namespace Dynamitey.Tests
{
Expand All @@ -22,20 +24,46 @@ public static readonly dynamic Interfacing
[Test]
public void DictionaryInterfaceNullMethodsTest()
{

dynamic tNew = new DynamicObjects.Dictionary();

ISimpleStringMethod tActsLike = ImpromptuInterface.Impromptu.ActLike(tNew);

Assert.AreEqual(false, tActsLike.StartsWith("Te"));
}


[Test]
public void FauxTypeTest()
{
var testProp = new Dictionary<String,Type>(){
{"test", typeof(bool)}
};


var propType = new PropretySpecType(testProp);

var propMembers = propType.GetMemberNames();
Expect(propMembers, Contains("test"));

var realType = new RealType(typeof(ISimpeleClassProps));
var realMembers = realType.GetMemberNames();

Expect(realMembers, Contains("Prop2"));



var aggrType = new AggreType(propType, realType);

var aggrMembers = aggrType.GetMemberNames();

Expect(aggrMembers, Contains("Prop2"));
Expect(aggrMembers, Contains("test"));

}


[Test]
public void PropertySpecTest()

{ var testProp = new Dictionary<String,Type>(){
{"test", typeof(bool)}
};
Expand All @@ -55,7 +83,6 @@ public void PropertySpecTest()

[Test]
public void InterfaceSpecTest()

{
var baseObj = new DynamicObjects.Dictionary();
var output = ImpromptuInterface.Impromptu.ActLike<ISimpeleClassProps>(baseObj);
Expand Down
2 changes: 1 addition & 1 deletion Version.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<VersionPrefix>2.0.7</VersionPrefix>
<VersionPrefix>2.0.8</VersionPrefix>
</PropertyGroup>
</Project>

0 comments on commit 4f91b3f

Please sign in to comment.