public createInvokeMethodIdentifier()

in packages/jsii-pacmak/lib/targets/dotnet/dotnetruntimegenerator.ts [159:194]


  public createInvokeMethodIdentifier(
    method: spec.Method,
    cls: spec.ClassType,
  ): string {
    const className = this.typeresolver.toNativeFqn(cls.fqn);
    const isStatic = method.static ? 'Static' : 'Instance';
    const returns = method.returns ? '' : 'Void';
    const invokeMethodName = method.returns
      ? `return Invoke${isStatic}${returns}Method`
      : `Invoke${isStatic}${returns}Method`;
    const returnType = method.returns
      ? `<${this.typeresolver.toDotNetType(method.returns.type)}${
          method.returns.optional ? '?' : ''
        }>`
      : '';
    // If the method returns a non-optional value, apply a "!" to silence compilation warning.
    const bang = method.returns && !method.returns.optional ? '!' : '';
    const typeofStatement = method.static ? `typeof(${className}), ` : '';
    const paramTypes = new Array<string>();
    const params = new Array<string>();
    if (method.parameters) {
      for (const param of method.parameters) {
        paramTypes.push(
          `typeof(${this.typeresolver.toDotNetType(param.type)}${
            param.variadic ? '[]' : ''
          })`,
        );
        params.push(this.nameutils.convertParameterName(param.name));
      }
    }
    const hasOptional =
      method.parameters?.find((param) => param.optional) != null ? '?' : '';
    return `${invokeMethodName}${returnType}(${typeofStatement}new System.Type[]{${paramTypes.join(
      ', ',
    )}}, new object${hasOptional}[]{${params.join(', ')}})${bang};`;
  }