Ejemplo n.º 1
0
        public bool TryFix(string errorMessage, Generator gen)
        {
            Match m = ID.Match (errorMessage);
            if (!m.Success)
                return false;

            string typeName = m.Groups [1].Value;
            string oldMember = m.Groups [2].Value;
            string newMember = oldMember + "2";
            bool memberFound = false;

            CodeContainer type = gen.GetPath (typeName.Split ('.').Skip (1).ToArray ());

            foreach (var method in type.Atoms.OfType<Method> ()) {
                if (method.FormattedName == oldMember) {
                    method.FormattedName = newMember;
                    memberFound = true;
                    break;
                }
            }

            if (!memberFound) {
                foreach (var prop in type.Atoms.OfType<Property> ()) {
                    if (prop.Name == oldMember) {
                        prop.Name = newMember;
                        memberFound = true;
                        break;
                    }
                }
            }

            if (memberFound) {
                //Console.WriteLine ("Renaming \"{0}\" to \"{1}\" to prevent name collision in class \"{2}\" ...", oldMember, newMember, typeName);
                gen.Save ();
            }

            return memberFound;
        }