コード例 #1
0
 private void DirectiveMinVer(string val, IBaseFunction func)
 {
     val = val.Replace(" ", "").Replace("\n", "").Replace("\t", "").Replace("\r", "");
     string[] splode = val.Split(',');
     if (splode[0] == "soft")
     {
         var maj   = splode.ElementAtOrDefault(1);
         var min   = splode.ElementAtOrDefault(2);
         var build = splode.ElementAtOrDefault(3);
         var rev   = splode.ElementAtOrDefault(4);
         if (maj == null)
         {
             Compiler.ExceptionListener.Throw("MinVer Directive must express a major version");
         }
         string[] ver      = Assembly.GetExecutingAssembly().GetName().Version.ToString().Split('.');
         int      majint   = -1;
         int      minint   = -1;
         int      buildint = -1;
         int      revint   = -1;
         int.TryParse(maj, out majint);
         if (min != null)
         {
             int.TryParse(min, out minint);
         }
         if (build != null)
         {
             int.TryParse(build, out buildint);
         }
         if (rev != null)
         {
             int.TryParse(rev, out revint);
         }
         if (majint == -1)
         {
             Compiler.ExceptionListener.Throw("MinVer Directive must express a major version as a number");
         }
         if (int.Parse(ver[0]) < majint)
         {
             Compiler.ExceptionListener.ThrowSilent(new ExceptionHandler($"Function [{func.Name}] did not pass minimum version directive. Expected Major version [{majint}]."));
             if (FunctionStack.Contains(func))
             {
                 FunctionStack.Remove(func);
             }
             return;
         }
         if (minint != -1 && int.Parse(ver[1]) < minint)
         {
             Compiler.ExceptionListener.ThrowSilent(new ExceptionHandler($"Function [{func.Name}] did not pass minimum version directive. Expected Minor version [{minint}]."));
             if (FunctionStack.Contains(func))
             {
                 FunctionStack.Remove(func);
             }
             return;
         }
         if (buildint != -1 && int.Parse(ver[2]) < buildint)
         {
             Compiler.ExceptionListener.ThrowSilent(new ExceptionHandler($"Function [{func.Name}] did not pass minimum version directive. Expected Build version [{buildint}]."));
             if (FunctionStack.Contains(func))
             {
                 FunctionStack.Remove(func);
             }
             return;
         }
         if (revint != -1 && int.Parse(ver[3]) < revint)
         {
             Compiler.ExceptionListener.ThrowSilent(new ExceptionHandler($"Function [{func.Name}] did not pass minimum version directive. Expected Revision version [{revint}]."));
             if (FunctionStack.Contains(func))
             {
                 FunctionStack.Remove(func);
             }
             return;
         }
     }
     else
     {
         var maj   = splode.ElementAtOrDefault(0);
         var min   = splode.ElementAtOrDefault(1);
         var build = splode.ElementAtOrDefault(2);
         var rev   = splode.ElementAtOrDefault(3);
         if (maj == null)
         {
             Compiler.ExceptionListener.Throw("MinVer Directive must express a major version");
         }
         string[] ver      = Assembly.GetExecutingAssembly().GetName().Version.ToString().Split('.');
         int      majint   = -1;
         int      minint   = -1;
         int      buildint = -1;
         int      revint   = -1;
         int.TryParse(maj, out majint);
         if (min != null)
         {
             int.TryParse(min, out minint);
         }
         if (build != null)
         {
             int.TryParse(build, out buildint);
         }
         if (rev != null)
         {
             int.TryParse(rev, out revint);
         }
         if (majint == -1)
         {
             Compiler.ExceptionListener.Throw("MinVer Directive must express a major version as a number");
         }
         if (int.Parse(ver[0]) < majint)
         {
             Compiler.ExceptionListener.Throw(new ExceptionHandler($"Function [{func.Name}] did not pass minimum version directive. Expected Major version [{majint}]."));
         }
         if (minint != -1 && int.Parse(ver[1]) < minint)
         {
             Compiler.ExceptionListener.Throw(new ExceptionHandler($"Function [{func.Name}] did not pass minimum version directive. Expected Minor version [{minint}]."));
         }
         if (buildint != -1 && int.Parse(ver[2]) < buildint)
         {
             Compiler.ExceptionListener.Throw(new ExceptionHandler($"Function [{func.Name}] did not pass minimum version directive. Expected Build version [{buildint}]."));
         }
         if (revint != -1 && int.Parse(ver[3]) < revint)
         {
             Compiler.ExceptionListener.Throw(new ExceptionHandler($"Function [{func.Name}] did not pass minimum version directive. Expected Revision version [{revint}]."));
         }
     }
 }