public CodeGeneratorResult GenerateCode (FileCodeElement c) { this.fileCodeElement = c; result = new CodeGeneratorResult (); if (fileCodeElement == null) { return result.SetError ("No Class Data", "The providing classCodeElement is null. This indicates a problem during preprocessing the input source."); } Smart.Default.ErrorAction = ErrorAction.OutputErrorInResult; Smart.Default.Parser.ErrorAction = ErrorAction.ThrowError; Smart.Default.Parser.UseAlternativeEscapeChar ('\\'); code = Smart.Format(template, fileCodeElement); return result; }
public CodeGeneratorResult GenerateCode(FileCodeElement c) { this.fileCodeElement = c; result = new CodeGeneratorResult(); if (fileCodeElement == null) { return(result.SetError("No Class Data", "The providing classCodeElement is null. This indicates a problem during preprocessing the input source.")); } Smart.Default.ErrorAction = ErrorAction.OutputErrorInResult; Smart.Default.Parser.ErrorAction = ErrorAction.ThrowError; Smart.Default.Parser.UseAlternativeEscapeChar('\\'); code = Smart.Format(template, fileCodeElement); return(result); }
/// <summary> /// Performs final merging of old and new class, then triggers template engine to generate the code. /// </summary> /// <returns>Result to check for errors.</returns> public CodeGeneratorResult GenerateCode () { if (!config.IgnoreExistingCode) { if (existingClass != null && !existingClass.IsEmpty ()) { string msg = string.Format ("Animator state or parameter is no longer valid{0}. Refactor your code to not contain any references.", (config.KeepObsoleteMembers ? "" : " and will be removed in the next code generation")); existingClass.AddAttributeToAllMembers (new ObsoleteAttributeCodeElement (msg, false)); List<MemberCodeElement> allMembers = newClass.GetAllMembers (); newClass.MergeMethods (existingClass, (element) => !allMembers.Contains (element)); newClass.MergeProperties (existingClass,(element) => !allMembers.Contains (element)); newClass.MergeFields (existingClass, (element) => !allMembers.Contains (element)); } } FileCodeElement fileElement = new FileCodeElement (newClass); fileElement.Usings.Add (new UsingCodeElement ("UnityEngine")); CodeGeneratorResult result = templateEngine.GenerateCode (fileElement); if (result.Success) { code = templateEngine.Code; } return result; }