Skip to content

Commit

Permalink
Added support for 'any' type of dictionary to be 'serialized' into ja…
Browse files Browse the repository at this point in the history
…vascriptcontext.

Needed this to support a dictionary that inherited the generic dictionary.
  • Loading branch information
PEtter Ekrann committed Apr 9, 2015
1 parent 2d7a393 commit 711f12a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Source/Noesis.Javascript/JavascriptInterop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ JavascriptInterop::ConvertToV8(System::Object^ iObject)
return ConvertFromSystemArray(safe_cast<System::Array^>(iObject));
if (System::Delegate::typeid->IsAssignableFrom(type))
return ConvertFromSystemDelegate(safe_cast<System::Delegate^>(iObject));



if (type->IsGenericType)
{
if(type->GetGenericTypeDefinition() == System::Collections::Generic::Dictionary::typeid)
Expand All @@ -169,6 +170,14 @@ JavascriptInterop::ConvertToV8(System::Object^ iObject)
return ConvertFromSystemList(iObject);
}


if (System::Collections::IDictionary::typeid->IsAssignableFrom(type)){
//Only do this if no fields defined on this type
if (type->GetFields(System::Reflection::BindingFlags::DeclaredOnly | System::Reflection::BindingFlags::Instance )->Length == 0){
return ConvertFromSystemDictionary(iObject);
}
}

if (System::Exception::typeid->IsAssignableFrom(type))
{
// Converting exceptions to proper v8 Error objects has the advantage that
Expand Down Expand Up @@ -326,6 +335,8 @@ JavascriptInterop::ConvertFromSystemDictionary(System::Object^ iObject)
object->Set(key, val);
}



return object;
}

Expand Down

0 comments on commit 711f12a

Please sign in to comment.