54 IEnumerable<IPropertySymbol> methods = api.GetMembers()
55 .Where(x => x is IPropertySymbol)
56 .Cast<IPropertySymbol>();
58 foreach (IPropertySymbol method
in methods)
60 AttributeData? attribute = method.GetInteropPropertyAttribute();
62 if (attribute !=
null)
71 IEnumerable<IMethodSymbol> methods =
FindMethods(api);
73 AttributeData? apiAttribute = api.GetInteropObjectAttribute();
75 if (apiAttribute ==
null)
77 throw new Exception(
"BadInteropObjectAttribute not found");
80 string apiName = api.Name;
81 string? baseClassName =
null;
82 if (apiAttribute.ConstructorArguments.Length > 0)
84 apiName = apiAttribute.ConstructorArguments[0]
88 if(apiAttribute.ConstructorArguments.Length > 1)
90 var t = apiAttribute.ConstructorArguments[1].Value;
91 baseClassName = $
"{t}";
97 Diagnostic[] diagnostics = [];
99 var ctorModel =
GenerateConstructorModel(api.Constructors.FirstOrDefault(x => x.DeclaredAccessibility == Accessibility.Public && !x.IsStatic));
108 return new ObjectModel(api.ContainingNamespace?.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat
109 .WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle
132 foreach (IParameterSymbol symbol
in method.Parameters.Where(x => x.Ordinal >= 0)
133 .OrderBy(x => x.Ordinal))
136 if (symbol.Ordinal == 0 && symbol.Type.ToDisplayString() ==
"BadScript2.Runtime.BadExecutionContext")
142 AttributeData? attribute = symbol.GetParameterAttribute();
143 string? name = symbol.Name;
144 string? description =
null;
145 bool isNullable = symbol.NullableAnnotation == NullableAnnotation.Annotated;
146 string type =
ConvertType(symbol.Type,
true, symbol);
148 if (attribute !=
null)
150 ImmutableArray<TypedConstant> cargs = attribute.ConstructorArguments;
152 name = cargs.Length > 0
154 .Value?.ToString() ??
158 description = cargs.Length > 1
163 if (description !=
null)
168 type = cargs.Length > 2
170 .Value?.ToString() ??
175 bool hasDefaultValue = symbol.HasExplicitDefaultValue;
176 string? defaultValue =
null;
183 bool isRestArgs = symbol.IsParams;
191 symbol.Type.ToDisplayString(),
249 foreach (IPropertySymbol symbol
in symbols)
251 AttributeData? attribute = symbol.GetInteropPropertyAttribute();
253 if (attribute ==
null)
258 ImmutableArray<TypedConstant> cargs = attribute.ConstructorArguments;
261 string name = cargs.Length > 0
263 .Value?.ToString() ??
270 .Value?.ToString() ??
274 bool readOnly = cargs.Length > 2 && (cargs[2].Value as
bool? ??
false);
276 bool allowNativeReturn = cargs.Length > 3 && (cargs[3].Value as
bool? ??
false);
279 string returnType =
ConvertType(symbol.Type, allowNativeReturn, symbol);
281 var model =
new PropertyModel(symbol.Name, name, returnType, description, readOnly || symbol.SetMethod ==
null, symbol.Type.ToDisplayString());
299 foreach (IMethodSymbol symbol
in symbols)
301 AttributeData? attribute = symbol.GetInteropMethodAttribute();
303 if (attribute ==
null)
308 ImmutableArray<TypedConstant> cargs = attribute.ConstructorArguments;
311 string name = cargs.Length > 0
313 .Value?.ToString() ??
320 .Value?.ToString() ??
326 bool isVoidReturn = symbol.ReturnsVoid;
327 AttributeData? returnAttribute = symbol.GetReturnTypeAttribute();
328 string returnDescription =
string.Empty;
329 bool allowNativeReturn =
false;
331 if (returnAttribute !=
null)
333 if (returnAttribute.ConstructorArguments.Length > 0)
336 .Value?.ToString() ??
341 if (returnAttribute.ConstructorArguments.Length > 1)
343 allowNativeReturn = (bool)returnAttribute.ConstructorArguments[1].Value!;
348 string returnType = isVoidReturn ?
"any" :
ConvertType(symbol.ReturnType, allowNativeReturn, symbol);
365 private string ConvertType(ITypeSymbol type,
bool allowAny, ISymbol sourceSymbol)
367 if (type.NullableAnnotation == NullableAnnotation.Annotated)
370 type = type.WithNullableAnnotation(NullableAnnotation.NotAnnotated);
374 if (type.SpecialType == SpecialType.System_String)
380 if (type.SpecialType == SpecialType.System_Boolean)
386 if (type.SpecialType == SpecialType.System_Byte ||
387 type.SpecialType == SpecialType.System_SByte ||
388 type.SpecialType == SpecialType.System_Int16 ||
389 type.SpecialType == SpecialType.System_UInt16 ||
390 type.SpecialType == SpecialType.System_Int32 ||
391 type.SpecialType == SpecialType.System_UInt32 ||
392 type.SpecialType == SpecialType.System_Int64 ||
393 type.SpecialType == SpecialType.System_UInt64 ||
394 type.SpecialType == SpecialType.System_Single ||
395 type.SpecialType == SpecialType.System_Double ||
396 type.SpecialType == SpecialType.System_Decimal)
402 if (type is IArrayTypeSymbol ||
403 type.AllInterfaces.Any(x => x.ToDisplayString() ==
"System.Collections.Generic.IList<T>") ||
404 type.AllInterfaces.Any(x => x.ToDisplayString() ==
"System.Collections.IList<T>"))
410 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.BadObject")
415 if (type.ToDisplayString() ==
"BadScript2.Interop.Common.Task.BadTask")
421 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.BadTable")
427 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.BadArray")
433 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Functions.BadFunction")
438 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Types.BadClassPrototype")
443 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Error.BadRuntimeError")
449 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Native.IBadBoolean" ||
450 type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Native.BadBoolean")
456 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Native.IBadNumber" ||
457 type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Native.BadNumber")
463 if (type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Native.IBadString" ||
464 type.ToDisplayString() ==
"BadScript2.Runtime.Objects.Native.BadString")
470 if (type.ToDisplayString() ==
"BadScript2.Runtime.BadScope")