Skip to content

Commit

Permalink
Fix generator bugs with un-namespaced types (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongin authored Aug 19, 2024
1 parent 04eb8a0 commit 259936d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
15 changes: 9 additions & 6 deletions src/NodeApi.DotNetHost/JSMarshaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,9 @@ public LambdaExpression BuildToJSMethodExpression(MethodInfo method)
string name = method.Name;
if (method.DeclaringType!.IsInterface)
{
name = method.DeclaringType.Namespace + '.' +
method.DeclaringType.Name + '.' + name;
string nsPrefix = method.DeclaringType.Namespace != null ?
method.DeclaringType.Namespace + '.' : string.Empty;
name = nsPrefix + method.DeclaringType.Name + '.' + name;
}

ParameterInfo[] allMethodParameters = method.GetParameters();
Expand Down Expand Up @@ -1097,8 +1098,9 @@ public LambdaExpression BuildToJSPropertyGetExpression(PropertyInfo property)
string name = "get_" + property.Name;
if (property.DeclaringType!.IsInterface)
{
name = property.DeclaringType.Namespace + '.' +
property.DeclaringType.Name + '.' + name;
string nsPrefix = property.DeclaringType.Namespace != null ?
property.DeclaringType.Namespace + '.' : string.Empty;
name = nsPrefix + property.DeclaringType.Name + '.' + name;
}

ParameterExpression thisParameter = Expression.Parameter(typeof(JSValue), "__this");
Expand Down Expand Up @@ -1167,8 +1169,9 @@ public LambdaExpression BuildToJSPropertySetExpression(PropertyInfo property)
string name = "set_" + property.Name;
if (property.DeclaringType!.IsInterface)
{
name = property.DeclaringType.Namespace + '.' +
property.DeclaringType.Name + '.' + name;
string nsPrefix = property.DeclaringType.Namespace != null ?
property.DeclaringType.Namespace + '.' : string.Empty;
name = nsPrefix + property.DeclaringType.Name + '.' + name;
}

ParameterExpression thisParameter =
Expand Down
3 changes: 2 additions & 1 deletion src/NodeApi.Generator/ExpressionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ internal static string FormatType(Type type)
}
else
{
return $"{type.Namespace}.{type.Name.Substring(0, type.Name.IndexOf('`'))}<{typeArgs}>";
string nsPrefix = type.Namespace != null ? type.Namespace + "." : string.Empty;
return $"{nsPrefix}{type.Name.Substring(0, type.Name.IndexOf('`'))}<{typeArgs}>";
}
}
else if (type.IsNested)
Expand Down
7 changes: 6 additions & 1 deletion src/NodeApi.Generator/ModuleGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,12 @@ private static void GenerateInterfaceAdapter(
JSMarshaller _marshaller)
{
string ns = GetNamespace(interfaceType);
string adapterName = $"proxy_{ns.Replace('.', '_')}_{interfaceType.Name}";
if (ns.Length > 0)
{
ns += '_';
}

string adapterName = $"proxy_{ns.Replace('.', '_')}{interfaceType.Name}";

static string ReplaceMethodVariables(string cs) =>
cs.Replace(typeof(JSValue).Namespace + ".", "")
Expand Down

0 comments on commit 259936d

Please sign in to comment.