public override void Populate(CSharpGeneratorContext context) { if (!context.Project.IsUnityProject()) { return; } var typeElement = context.ClassDeclaration.DeclaredElement as IClass; if (typeElement == null) { return; } var unityTypes = myUnityApi.GetBaseUnityTypes(typeElement).ToArray(); var events = unityTypes.SelectMany(h => h.Messages) .Where(m => !typeElement.Methods.Any(m.Match)).ToArray(); var classDeclaration = context.ClassDeclaration; var factory = CSharpElementFactory.GetInstance(classDeclaration); var methods = events .Select(e => e.CreateDeclaration(factory, classDeclaration)) .Select(d => d.DeclaredElement) .Where(m => m != null); // Make sure we only add a method once (e.g. EditorWindow derives from ScriptableObject // and both declare the OnDestroy message) var elements = methods.Select(m => new GeneratorDeclaredElement <IMethod>(m)) .Distinct(m => m.TestDescriptor); context.ProvidedElements.AddRange(elements); }
private bool HasUnityBaseType(CSharpGeneratorContext context) { var typeElement = context.ClassDeclaration.DeclaredElement as IClass; return(typeElement != null && myUnityApi.GetBaseUnityTypes(typeElement).Any()); }