54 IEnumerable<IMethodSymbol> methods =
FindMethods(api);
55 AttributeData? apiAttribute = api.GetInteropApiAttribute();
56 if (apiAttribute ==
null)
58 throw new Exception(
"BadInteropApiAttribute not found");
61 string apiName = api.Name;
62 bool constructorPrivate =
false;
63 if (apiAttribute.ConstructorArguments.Length > 0)
65 apiName = apiAttribute.ConstructorArguments[0].Value?.ToString() ?? apiName;
66 bool? priv = apiAttribute.ConstructorArguments[1].Value as
bool?;
67 constructorPrivate = apiAttribute.ConstructorArguments.Length > 1 && priv !=
null && priv.Value;
71 Diagnostic[] diagnostics = Array.Empty<Diagnostic>();
79 api.ContainingNamespace?.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat.WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle.Omitted))!,
95 foreach (IParameterSymbol symbol
in method.Parameters.Where(x => x.Ordinal >= 0).OrderBy(x => x.Ordinal))
98 if (symbol.Ordinal == 0 && symbol.Type.ToDisplayString() ==
"BadScript2.Runtime.BadExecutionContext")
104 AttributeData? attribute = symbol.GetParameterAttribute();
105 string? name = symbol.Name;
106 string? description =
null;
107 bool isNullable = symbol.NullableAnnotation == NullableAnnotation.Annotated;
108 string type =
ConvertType(symbol.Type,
true, symbol);
110 if (attribute !=
null)
112 ImmutableArray<TypedConstant> cargs = attribute.ConstructorArguments;
113 name = cargs.Length > 0 ? cargs[0].Value?.ToString() ?? name : name;
114 description = cargs.Length > 1 ? cargs[1].Value?.ToString() :
null;
115 if (description !=
null)
120 type = cargs.Length > 2 ? cargs[2].Value?.ToString() ?? type : type;
123 bool hasDefaultValue = symbol.HasExplicitDefaultValue;
124 string? defaultValue =
null;
130 bool isRestArgs = symbol.IsParams;
132 yield
return new ParameterModel(
false, hasDefaultValue, defaultValue, name, description, type, symbol.Type.ToDisplayString(), isNullable, isRestArgs);
186 foreach (IMethodSymbol symbol
in symbols)
188 AttributeData? attribute = symbol.GetInteropMethodAttribute();
190 if (attribute ==
null)
195 ImmutableArray<TypedConstant> cargs = attribute.ConstructorArguments;
198 string name = cargs.Length > 0 ? cargs[0].Value?.ToString() ?? symbol.Name : symbol.Name;
201 string description =
EscapeDescription(cargs.Length > 1 ? cargs[1].Value?.ToString() ??
string.Empty :
string.Empty);
204 bool isVoidReturn = symbol.ReturnsVoid;
205 AttributeData? returnAttribute = symbol.GetReturnTypeAttribute();
206 string returnDescription =
string.Empty;
207 bool allowNativeReturn =
false;
208 if (returnAttribute !=
null)
210 if (returnAttribute.ConstructorArguments.Length > 0)
212 returnDescription =
EscapeDescription(returnAttribute.ConstructorArguments[0].Value?.ToString() ??
string.Empty);
215 if (returnAttribute.ConstructorArguments.Length > 1)
217 allowNativeReturn = (bool)returnAttribute.ConstructorArguments[1].Value!;
223 string returnType = isVoidReturn ?
"any" :
ConvertType(symbol.ReturnType, allowNativeReturn, symbol);
241 private string ConvertType(ITypeSymbol type,
bool allowAny, ISymbol sourceSymbol)
243 if (type.NullableAnnotation == NullableAnnotation.Annotated)
246 type = type.WithNullableAnnotation(NullableAnnotation.NotAnnotated);
250 if (type.SpecialType == SpecialType.System_String)
256 if (type.SpecialType == SpecialType.System_Boolean)
262 if (type.SpecialType == SpecialType.System_Byte ||
263 type.SpecialType == SpecialType.System_SByte ||
264 type.SpecialType == SpecialType.System_Int16 ||
265 type.SpecialType == SpecialType.System_UInt16 ||
266 type.SpecialType == SpecialType.System_Int32 ||
267 type.SpecialType == SpecialType.System_UInt32 ||
268 type.SpecialType == SpecialType.System_Int64 ||
269 type.SpecialType == SpecialType.System_UInt64 ||
270 type.SpecialType == SpecialType.System_Single ||
271 type.SpecialType == SpecialType.System_Double ||
272 type.SpecialType == SpecialType.System_Decimal)
278 if (type is IArrayTypeSymbol ||
279 type.AllInterfaces.Any(x => x.ToDisplayString() ==
"System.Collections.Generic.IList<T>") ||
280 type.AllInterfaces.Any(x => x.ToDisplayString() ==
"System.Collections.IList<T>"))
286 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.BadObject")
291 if (type.ToDisplayString() ==
"BadScript2.Interop.Common.Task.BadTask")
297 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.BadTable")
303 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.BadArray")
309 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Functions.BadFunction")
314 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Types.BadClassPrototype")
319 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Error.BadRuntimeError")
325 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Native.IBadBoolean" || type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Native.BadBoolean")
331 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Native.IBadNumber" || type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Native.BadNumber")
337 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Native.IBadString" || type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Native.BadString")
343 if (type.ToDisplayString() ==
"BadScript2.Runtime.BadScope")