Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generator bugs with un-namespaced types #360

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading