private void WriteThrow(MagickMethod method)
        {
            WriteThrowStart();

            if (method.CreatesInstance)
            {
                WriteLine("IntPtr result;");
            }
            else if (!method.ReturnType.IsVoid)
            {
                WriteLine(method.ReturnType.Native + " result;");
            }

            var arguments = GetNativeArgumentsCall(method);
            var action    = "NativeMethods.{0}." + Class.Name + "_" + method.Name + "(" + arguments + ");";

            if (!method.ReturnType.IsVoid || method.CreatesInstance)
            {
                action = "result = " + action;
            }
            WriteNativeIfContent(action);

            WriteCreateOut(method.Arguments);

            var cleanupString = CreateCleanupString(method);

            if (!string.IsNullOrEmpty(cleanupString))
            {
                WriteCleanup(cleanupString);
            }
            else if (method.CreatesInstance && !Class.IsConst)
            {
                WriteLine("CheckException(exception, result);");
            }
            else
            {
                WriteCheckException(true);
            }

            if (method.CreatesInstance && method.ReturnType.IsVoid)
            {
                WriteLine("if (result != IntPtr.Zero)");
                WriteLine("  Instance = result;");
            }
            else
            {
                WriteReturn(method.ReturnType);
            }
        }
Пример #2
0
        protected string GetNativeArgumentsDeclaration(MagickMethod method)
        {
            string arguments = GetNativeArgumentsDeclaration(method.Arguments);

            if (Class.IsStatic || method.IsStatic)
            {
                return(arguments);
            }
            else if (string.IsNullOrEmpty(arguments))
            {
                return("IntPtr Instance");
            }
            else
            {
                return("IntPtr Instance, " + arguments);
            }
        }
    private string CreateCleanupString(MagickMethod method)
    {
      if (method.Cleanup == null)
      {
        if (!Class.HasInstance && !method.ReturnType.IsVoid)
          return "Dispose(result);";

        return null;
      }

      var cleanup = method.Cleanup;

      string result = cleanup.Name + "(result";
      if (cleanup.Arguments.Count() > 0)
        result += ", " + string.Join(", ", cleanup.Arguments);
      return result + ");";
    }
Пример #4
0
        protected string?GetNativeArgumentsCall(MagickMethod method)
        {
            var arguments = GetNativeArgumentsCall(method.Arguments);

            if (Class.IsStatic || method.IsStatic)
            {
                return(arguments);
            }
            else if (string.IsNullOrEmpty(arguments))
            {
                return("Instance");
            }
            else
            {
                return("Instance, " + arguments);
            }
        }
        private string CreateCleanupString(MagickMethod method)
        {
            if (method.Cleanup == null)
            {
                if (!Class.HasInstance && !method.ReturnType.IsVoid)
                {
                    return("Dispose(result);");
                }

                return(null);
            }

            var cleanup = method.Cleanup;

            string result = cleanup.Name + "(result";

            if (cleanup.Arguments.Count() > 0)
            {
                result += ", " + string.Join(", ", cleanup.Arguments);
            }
            return(result + ");");
        }
    private void WriteThrow(MagickMethod method)
    {
      WriteThrowStart();

      if (method.CreatesInstance)
        WriteLine("IntPtr result;");
      else if (!method.ReturnType.IsVoid)
        WriteLine(method.ReturnType.Native + " result;");

      string arguments = GetNativeArgumentsCall(method);
      string action = "NativeMethods.{0}." + Class.Name + "_" + method.Name + "(" + arguments + ");";
      if (!method.ReturnType.IsVoid || method.CreatesInstance)
        action = "result = " + action;
      WriteNativeIfContent(action);

      WriteCreateOut(method.Arguments);

      string cleanupString = CreateCleanupString(method);
      if (!string.IsNullOrEmpty(cleanupString))
        WriteCleanup(cleanupString);
      else if ((method.CreatesInstance) && !Class.IsConst)
        WriteLine("CheckException(exception, result);");
      else
        WriteCheckException(true);

      if (method.CreatesInstance && method.ReturnType.IsVoid)
        WriteLine("Instance = result;");
      else
        WriteReturn(method.ReturnType);
    }
Пример #7
0
 protected bool HasSpan(MagickMethod method)
 => method.Arguments.Any(argument => argument.Type.IsSpan);
Пример #8
0
    protected string GetNativeArgumentsDeclaration(MagickMethod method)
    {
      string arguments = GetNativeArgumentsDeclaration(method.Arguments);

      if (Class.IsStatic || method.IsStatic)
        return arguments;
      else if (string.IsNullOrEmpty(arguments))
        return "IntPtr Instance";
      else
        return "IntPtr Instance, " + arguments;
    }