56 IEnumerable<IMethodSymbol> methods =
FindMethods(api);
57 AttributeData? apiAttribute = api.GetInteropApiAttribute();
59 if (apiAttribute ==
null)
61 throw new Exception(
"BadInteropApiAttribute not found");
64 string apiName = api.Name;
65 bool constructorPrivate =
false;
67 if (apiAttribute.ConstructorArguments.Length > 0)
69 apiName = apiAttribute.ConstructorArguments[0]
72 bool? priv = apiAttribute.ConstructorArguments[1].Value as
bool?;
73 constructorPrivate = apiAttribute.ConstructorArguments.Length > 1 && priv !=
null && priv.Value;
78 Diagnostic[] diagnostics = Array.Empty<Diagnostic>();
86 return new ApiModel(api.ContainingNamespace?.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat
87 .WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle
108 foreach (IParameterSymbol symbol
in method.Parameters.Where(x => x.Ordinal >= 0)
109 .OrderBy(x => x.Ordinal))
112 if (symbol.Ordinal == 0 && symbol.Type.ToDisplayString() ==
"BadScript2.Runtime.BadExecutionContext")
118 AttributeData? attribute = symbol.GetParameterAttribute();
119 string? name = symbol.Name;
120 string? description =
null;
121 bool isNullable = symbol.NullableAnnotation == NullableAnnotation.Annotated;
122 string type =
ConvertType(symbol.Type,
true, symbol);
124 if (attribute !=
null)
126 ImmutableArray<TypedConstant> cargs = attribute.ConstructorArguments;
128 name = cargs.Length > 0
130 .Value?.ToString() ??
134 description = cargs.Length > 1
139 if (description !=
null)
144 type = cargs.Length > 2
146 .Value?.ToString() ??
151 bool hasDefaultValue = symbol.HasExplicitDefaultValue;
152 string? defaultValue =
null;
159 bool isRestArgs = symbol.IsParams;
167 symbol.Type.ToDisplayString(),
225 foreach (IMethodSymbol symbol
in symbols)
227 AttributeData? attribute = symbol.GetInteropMethodAttribute();
229 if (attribute ==
null)
234 ImmutableArray<TypedConstant> cargs = attribute.ConstructorArguments;
237 string name = cargs.Length > 0
239 .Value?.ToString() ??
246 .Value?.ToString() ??
252 bool isVoidReturn = symbol.ReturnsVoid;
253 AttributeData? returnAttribute = symbol.GetReturnTypeAttribute();
254 string returnDescription =
string.Empty;
255 bool allowNativeReturn =
false;
257 if (returnAttribute !=
null)
259 if (returnAttribute.ConstructorArguments.Length > 0)
262 .Value?.ToString() ??
267 if (returnAttribute.ConstructorArguments.Length > 1)
269 allowNativeReturn = (bool)returnAttribute.ConstructorArguments[1].Value!;
274 string returnType = isVoidReturn ?
"any" :
ConvertType(symbol.ReturnType, allowNativeReturn, symbol);
291 private string ConvertType(ITypeSymbol type,
bool allowAny, ISymbol sourceSymbol)
293 if (type.NullableAnnotation == NullableAnnotation.Annotated)
296 type = type.WithNullableAnnotation(NullableAnnotation.NotAnnotated);
300 if (type.SpecialType == SpecialType.System_String)
306 if (type.SpecialType == SpecialType.System_Boolean)
312 if (type.SpecialType == SpecialType.System_Byte ||
313 type.SpecialType == SpecialType.System_SByte ||
314 type.SpecialType == SpecialType.System_Int16 ||
315 type.SpecialType == SpecialType.System_UInt16 ||
316 type.SpecialType == SpecialType.System_Int32 ||
317 type.SpecialType == SpecialType.System_UInt32 ||
318 type.SpecialType == SpecialType.System_Int64 ||
319 type.SpecialType == SpecialType.System_UInt64 ||
320 type.SpecialType == SpecialType.System_Single ||
321 type.SpecialType == SpecialType.System_Double ||
322 type.SpecialType == SpecialType.System_Decimal)
328 if (type is IArrayTypeSymbol ||
329 type.AllInterfaces.Any(x => x.ToDisplayString() ==
"System.Collections.Generic.IList<T>") ||
330 type.AllInterfaces.Any(x => x.ToDisplayString() ==
"System.Collections.IList<T>"))
336 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.BadObject")
341 if (type.ToDisplayString() ==
"BadScript2.Interop.Common.Task.BadTask")
347 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.BadTable")
353 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.BadArray")
359 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Functions.BadFunction")
364 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Types.BadClassPrototype")
369 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Error.BadRuntimeError")
375 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Native.IBadBoolean" ||
376 type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Native.BadBoolean")
382 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Native.IBadNumber" ||
383 type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Native.BadNumber")
389 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Native.IBadString" ||
390 type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Native.BadString")
396 if (type.ToDisplayString() ==
"BadScript2.Runtime.BadScope")