public override int CalculateNumberOfMethods() { int counter = 0; bool flag = false; SourceCode.Replace(" ", "").Replace("\t", "").Split('\n').ToList().ForEach(delegate(string line) { if (flag && line.Contains("{")) { counter++; flag = false; } if (line.Contains("(") && line.Contains(")") && !line.Contains("if") && !line.Contains("for") && !line.Contains("switch") && !line.Contains("while") && !line.Contains(".")) { if (line.Contains("{")) { counter++; flag = false; } else { flag = true; } } }); return(Metrics.NumberOfMethods = counter); }
private void InitialPreparing() { CompileErrors = new List <Error>(); SourceCode = SourceCode.Replace("\r", ""); if (SourceCode[SourceCode.Length - 1] != '\n') { SourceCode += '\n'; } }
private string GetSourceCodeCleaned() { // Remove encoded quotes var codeWithoutQuotes = SourceCode.Replace("\\\"", ""); // Remove strings var codeWithoutStrings = Regex.Replace( codeWithoutQuotes, "\".*?\"", ""); // Remove multiline strings. var codeWithoutMultilineStrings = GetCodeWithoutMultilines(codeWithoutStrings); // Remove comments, summaries and empty lines var result = Regex.Replace( codeWithoutMultilineStrings, "(//.*?$)|(///.*?)|(^/s*?$)", ""); return(result); }
public void GenerateCode() { ResultConsole.Clear(); if (string.IsNullOrEmpty(PluginName)) { ResultConsole.Add("Enter plugin name."); return; } if (!Directory.Exists("./Plugins")) { Directory.CreateDirectory("./Plugins"); } string codeToCompile = $@" namespace PluginSystemWPF.Plugins {{ public class {PluginName}:PluginLib.IPlugin {{ public string Name {{ set; get; }} public string Author {{ set; get; }} public string Version {{ set; get; }} public string Code {{ set; get; }} public {PluginName}(){{ Name = ""{PluginName}""; Version= ""{PluginVersion}""; Code = @""{SourceCode.Replace("\"","\"\"")}""; Author= ""{PluginAutor}""; }} public void Calculate() {{ {SourceCode} }} }} }}"; var codeProvider = new CSharpCodeProvider(); CompilerParameters parameters = new CompilerParameters(); parameters.GenerateExecutable = false; parameters.ReferencedAssemblies.Add("System.dll"); parameters.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location); parameters.ReferencedAssemblies.Add(typeof(IPlugin).Assembly.Location); parameters.OutputAssembly = $"./Plugins/{PluginName}.dll"; CompilerResults rresults = codeProvider.CompileAssemblyFromSource(parameters, codeToCompile); if (rresults.Errors.Count > 0) { foreach (var error in rresults.Errors) { ResultConsole.Add(error.ToString()); } } else { ResultConsole.Add("Compiller sucsess."); } }