コード例 #1
0
        string GeneratePythonCode()
        {
            NRefactoryToPythonConverter converter = NRefactoryToPythonConverter.Create(view.PrimaryFileName);

            converter.IndentString = view.TextEditorOptions.IndentationString;
            return(converter.Convert(view.EditableView.Text));
        }
コード例 #2
0
        /// <summary>
        /// Converts C# and VB.NET files to Python and saves the files.
        /// </summary>
        protected override void ConvertFile(FileProjectItem sourceItem, FileProjectItem targetItem)
        {
            NRefactoryToPythonConverter converter = NRefactoryToPythonConverter.Create(sourceItem.Include);

            if (converter != null)
            {
                targetItem.Include = ChangeFileExtensionToPythonFileExtension(sourceItem.Include);

                string code       = GetParseableFileContent(sourceItem.FileName);
                string pythonCode = converter.Convert(code);

                PythonProject pythonTargetProject = (PythonProject)targetItem.Project;
                if ((converter.EntryPointMethods.Count > 0) && !pythonTargetProject.HasMainFile)
                {
                    pythonTargetProject.AddMainFile(targetItem.Include);

                    // Add code to call main method at the end of the file.
                    pythonCode += "\r\n\r\n" + converter.GenerateMainMethodCall(converter.EntryPointMethods[0]);
                }

                SaveFile(targetItem.FileName, pythonCode, GetDefaultFileEncoding());
            }
            else
            {
                LanguageConverterConvertFile(sourceItem, targetItem);
            }
        }
コード例 #3
0
ファイル: Util.cs プロジェクト: L3tum/BesiegeScriptingMod
        /// <summary>
        /// Converts the C# Source into Python
        /// </summary>
        /// <param Name="sauce">Source code written by $user</param>
        /// <param Name="refs">References specified by $user</param>
        /// <param Name="name">$Name of the script</param>
        /// <returns>Source code in Python format</returns>
        public static String Compile(FileInfo sauce, string[] refs, string name)
        {
            NRefactoryToPythonConverter indentString = NRefactoryToPythonConverter.Create(sauce.FullName);

            indentString.IndentString = new string(' ', 2);
            string str = "";

            using (var tr = sauce.OpenText())
            {
                str = indentString.Convert(tr.ReadToEnd());
            }
            return(str);

            #region alternative[OBSOLETE]

            /*
             * String refss = "";
             * foreach (var @ref in refs)
             * {
             *  refss += ":\"" + @ref + "\"";
             * }
             *
             * String args = Application.dataPath + "/Mods/Scripts/Resource/cs-script/cscs.exe /cd /r" + refss + sauce.FullName;
             * if (Application.platform.Equals(RuntimePlatform.WindowsPlayer) ||
             *  Application.platform.Equals(RuntimePlatform.WindowsEditor))
             * {
             *  var process = new Process();
             *  var startInfo = new ProcessStartInfo
             *  {
             *      WindowStyle = ProcessWindowStyle.Hidden,
             *      FileName = "cmd.exe",
             *      Arguments = args
             *  };
             *  process.StartInfo = startInfo;
             *  process.Start();
             *  process.WaitForExit();
             * }
             * else if (Application.platform.Equals(RuntimePlatform.LinuxPlayer) ||
             *       Application.platform.Equals(RuntimePlatform.OSXEditor) ||
             *       Application.platform.Equals(RuntimePlatform.OSXPlayer))
             * {
             *  var psi = new ProcessStartInfo
             *  {
             *      WindowStyle = ProcessWindowStyle.Hidden,
             *      FileName = "/bin/bash.sh",
             *      UseShellExecute = false,
             *      RedirectStandardOutput = true,
             *      Arguments = args
             *  };
             *
             *  var p = Process.Start(psi);
             *  p.WaitForExit();
             * }
             */

            #endregion
        }
コード例 #4
0
        protected void Run(IWorkbench workbench, ITextEditorProperties textEditorProperties)
        {
            // Get the code to convert.
            IViewContent viewContent = workbench.ActiveWorkbenchWindow.ActiveViewContent;
            IEditable    editable    = viewContent as IEditable;

            // Generate the python code.
            NRefactoryToPythonConverter converter = NRefactoryToPythonConverter.Create(viewContent.PrimaryFileName);

            converter.IndentString = NRefactoryToPythonConverter.GetIndentString(textEditorProperties);
            string pythonCode = converter.Convert(editable.Text);

            // Show the python code in a new window.
            NewFile("Generated.py", "Python", pythonCode);
        }
コード例 #5
0
 public void TextFileCannotBeConverted()
 {
     Assert.IsNull(NRefactoryToPythonConverter.Create(".txt"));
 }
コード例 #6
0
 public void NullFileName()
 {
     Assert.IsNull(NRefactoryToPythonConverter.Create(null));
 }
コード例 #7
0
        public void CSharpCaseInsensitive()
        {
            NRefactoryToPythonConverter converter = NRefactoryToPythonConverter.Create(".CS");

            Assert.AreEqual(SupportedLanguage.CSharp, converter.SupportedLanguage);
        }
コード例 #8
0
        public void VBNetSupportedLanguage()
        {
            NRefactoryToPythonConverter converter = NRefactoryToPythonConverter.Create(".vb");

            Assert.AreEqual(SupportedLanguage.VBNet, converter.SupportedLanguage);
        }
コード例 #9
0
        public void CSharpSupportedLanguage()
        {
            NRefactoryToPythonConverter converter = NRefactoryToPythonConverter.Create(".cs");

            Assert.AreEqual(SupportedLanguage.CSharp, converter.SupportedLanguage);
        }