コード例 #1
0
        public void Test()
        {

            ParsedClass parsedClass = new ParsedClass(TestStringClassOnly, false);
            if (parsedClass.ParsedMethods.Count < 2)
            {
                throw new Exception("ParsedMethod count is too low");
            }


            ParsedFile parsedFile = new ParsedFile();
            parsedFile.SetFromContents(TestString, false, false);

            if (parsedFile.Namespaces.Count == 0)
            {
                throw new Exception("ParsedFile namespace is 0 when it shouldn't be");
            }

            if (parsedFile.Namespaces[0].Classes.Count == 0)
            {
                throw new Exception("ParsedNamespace class count is 0 when it shouldn't be");
            }

            if (parsedFile.Namespaces[0].Classes[0].ParsedMethods.Count < 2)
            {
                throw new Exception("ParsedMethod count is too low");
            }

        }
コード例 #2
0
        public static bool InheritsFrom(string fileName, string baseClass, string nameToMatch)
        {
            fileName = FileManager.Standardize(fileName);

            if (FileManager.FileExists(fileName))
            {
                ParsedFile parsedFile = new ParsedFile(fileName);

                if (parsedFile.Namespaces.Count != 0)
                {
                    for (int i = 0; i < parsedFile.Namespaces[0].Classes.Count; i++)
                    {
                        ParsedClass parsedClass = parsedFile.Namespaces[0].Classes[i];

                        if (nameToMatch != null && parsedClass.Name != nameToMatch)
                        {
                            continue;
                        }

                        foreach (ParsedType parsedType in parsedClass.ParentClassesAndInterfaces)
                        {
                            if (parsedType.ToString() == baseClass)
                            {
                                return(true);
                            }
                        }
                    }
                }
                return(false);
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Looking for the Game class.  The file  " + fileName + " is part of the project but couldn't find it on disk.");
                return(false);
            }
        }
コード例 #3
0
        public static ParsedMethod GetParsedMethodFromAssociatedFile(string fullFileName, EventResponseSave instance)
        {


            if (File.Exists(fullFileName))
            {
                ParsedFile file = new ParsedFile(fullFileName, false, false);

                if (file.Namespaces.Count != 0)
                {
                    ParsedNamespace parsedNamespace = file.Namespaces[0];

                    if (parsedNamespace.Classes.Count != 0)
                    {
                        ParsedClass parsedClass = parsedNamespace.Classes[0];

                        return parsedClass.GetMethod("On" + instance.EventName);
                    }
                }
            }

            return null;
        }
コード例 #4
0
        static ParsedClass GetParsedClassFrom(string fileName)
        {
            ParsedFile parsedFile = new ParsedFile(fileName, false, false);

            if (parsedFile.Namespaces.Count != 0)
            {
                ParsedNamespace parsedNamespace = parsedFile.Namespaces[0];

                if (parsedNamespace.Classes.Count != 0)
                {
                    return parsedNamespace.Classes[0];
                }
            }
            return null;
        }
コード例 #5
0
        protected void StartCacheTask(CachedTypesReadyHandler typesReadyHandler)
        {
            new Task(() =>
            {
                lock (_cacheLock)
                {
                    _cacheReady = false;
                }

                try
                {
                    PluginManager.ReceiveOutput("Caching of project types for CSV editor has begun.  " +
                                                "Some functionality will not be available until this is complete");

                    // Save all the entity screens and
                    _entities = ObjectFinder.Self.GlueProject.Entities;
                    _screens = ObjectFinder.Self.GlueProject.Screens;

                    // Go through all the code in the project and generate a list of enums and classes
                    var items = ProjectManager.ProjectBase.Where(x => x.Name == "Compile");
                    string baseDirectory = ProjectManager.ProjectBase.Directory;

                    _parsedPrjectClasses = new List<ParsedClass>();
                    _parsedProjectEnums = new List<ParsedEnum>();

                    foreach (var item in items)
                    {
                        var file = new ParsedFile(baseDirectory + item.Include);
                        foreach (var ns in file.Namespaces)
                        {
                            _parsedProjectEnums.AddRange(ns.Enums);
                            _parsedPrjectClasses.AddRange(ns.Classes);
                        }
                    }

                    // Get a list of all enums via reflection
                    _assemblyEnums = AppDomain.CurrentDomain
                                              .GetAssemblies()
                                              .SelectMany(x => x.GetTypes())
                                              .Where(x => x.IsEnum)
                                              .ToList();

                    _assemblyClasses = AppDomain.CurrentDomain
                                              .GetAssemblies()
                                              .SelectMany(x => x.GetTypes())
                                              .Where(x => !x.IsEnum)
                                              .ToList();
                }
                catch (Exception ex)
                {
                    PluginManager.ReceiveOutput(
                        string.Concat(
                            "Exception occurred while caching project types: ",
                            ex.GetType(),
                            ":",
                            ex.Message));

                    return;
                }

                lock (_cacheLock)
                {
                    _cacheReady = true;
                }

                PluginManager.ReceiveOutput("Caching of project types completed");

                // Run the CachedTypesHandler delegate
                if (typesReadyHandler != null)
                    typesReadyHandler();

            }).Start();
        }
コード例 #6
0
ファイル: CodeParser.cs プロジェクト: vchelaru/FlatRedBall
        public static bool InheritsFrom(string fileName, string baseClass, string nameToMatch)
        {
            fileName = FileManager.Standardize(fileName);

            if (FileManager.FileExists(fileName))
            {

                ParsedFile parsedFile = new ParsedFile(fileName);

                if (parsedFile.Namespaces.Count != 0)
                {
                    for (int i = 0; i < parsedFile.Namespaces[0].Classes.Count; i++)
                    {
                        ParsedClass parsedClass = parsedFile.Namespaces[0].Classes[i];

                        if (nameToMatch != null && parsedClass.Name != nameToMatch)
                        {
                            continue;
                        }

                        foreach (ParsedType parsedType in parsedClass.ParentClassesAndInterfaces)
                        {
                            if (parsedType.ToString() == baseClass)
                            {
                                return true;
                            }
                        }
                    }
                }
                return false;
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Looking for the Game class.  The file  " + fileName + " is part of the project but couldn't find it on disk.");
                return false;
            }
        }