Skip to content

Commit 2f3437f

Browse files
Erik Schillingoliverbock
authored andcommitted
Added generic convenience method for registering constructors
1 parent 823e2c1 commit 2f3437f

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

Source/Noesis.Javascript/JavascriptContext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ JavascriptContext::SetParameter(System::String^ iName, System::Object^ iObject,
281281

282282
////////////////////////////////////////////////////////////////////////////////////////////////////
283283

284+
generic <typename AssociatedType> void JavascriptContext::SetConstructor(System::String^ name, System::Delegate^ constructor)
285+
{
286+
SetConstructor(name, AssociatedType::typeid, constructor);
287+
}
284288

285289
void JavascriptContext::SetConstructor(System::String^ name, System::Type^ associatedType, System::Delegate^ constructor)
286290
{

Source/Noesis.Javascript/JavascriptContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public ref class JavascriptContext: public System::IDisposable
141141

142142
void SetParameter(System::String^ iName, System::Object^ iObject, SetParameterOptions options);
143143

144+
generic <typename AssociatedType> void SetConstructor(System::String^ name, System::Delegate^ constructor);
144145
void SetConstructor(System::String^ name, System::Type^ associatedType, System::Delegate^ constructor);
145146

146147
System::Object^ GetParameter(System::String^ iName);

Tests/Noesis.Javascript.Tests/InstanceOfTest.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ public void RegisteredConstructorInstanceOfTest()
2828
_context.Run("(new Test()) instanceof Test").Should().Be(true);
2929
}
3030

31+
[TestMethod]
32+
public void RegisterConstructorUsingGenericTest()
33+
{
34+
_context.SetConstructor<TestClass>("Test", new Func<TestClass>(() => new TestClass()));
35+
_context.Run("(new Test()) instanceof Test").Should().Be(true);
36+
}
37+
3138
[TestMethod]
3239
public void RegisteredConstructorInstanceOfWorksWithCSharpObjectTest()
3340
{

0 commit comments

Comments
 (0)