Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            //AsyncContext.Run(GenerateVisitorInterface);
            string baseDirectory = Path.GetFullPath(
                Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"..\..\..\.."));
            AssemblyWithReflection assembly       = new AssemblyWithReflection(typeof(ClassWithCodeAnalysis).Assembly);
            Interface            visitorInterface = new Interface("ICodeAnalysisVisitor");
            IEnumerable <string> classNames       =
                from @class in assembly.AllClasses
                let baseClassName = @class.BaseClass?.Name
                                    where baseClassName != null &&
                                    baseClassName.StartsWith("Editable") &&
                                    !baseClassName.Contains("Expression") &&
                                    !baseClassName.Contains("Statement")
                                    let className = @class.Name
                                                    orderby className
                                                    select className;

            foreach (string className in classNames)
            {
                string parameterName = Regex.Replace(className, "WithCodeAnalysis$", "");
                parameterName = parameterName.Substring(0, 1).ToLower() + parameterName.Substring(1);
                InterfaceMethod method = new InterfaceMethod($"Visit{className}")
                {
                    ReturnType = new TypeReference(typeof(void)),
                    Parameters = new Collection <MethodParameter>()
                    {
                        new MethodParameter(parameterName, new TypeReference(className))
                    }
                };
                visitorInterface.Body.Methods.Add(method);
            }

            Console.WriteLine(visitorInterface.ToString());
        }
 internal SolutionWithReflection(AssemblyWithReflection assembly)
 {
     this.assembly = assembly;
     projects      = new ProjectWithReflection[] { new ProjectWithReflection(this, assembly) };
 }