예제 #1
0
 public Profile()
 {
     IgnorePaths                 = new List <string> ();
     CompilerOptions             = new List <string> ();
     GlobalReplacements          = new ReplacementCollection(ReplacementContext.Global);
     EnumBackingTypeReplacements = new ReplacementCollection(ReplacementContext.EnumBackingType);
 }
예제 #2
0
        static void ParseDefine(ReplacementCollection collection, string define, string optionName)
        {
            var split = define.Split(new [] { '=' }, 2);

            if (split.Length < 2)
            {
                throw new OptionException("invalid define: must be PATTERN=REPLACEMENT", optionName);
            }

            collection.Add(split [0].Trim(), split [1].Trim());
        }
예제 #3
0
        void ReadReplacementsElement(XmlTextReader reader)
        {
            ReplacementCollection replacements = null;
            string scope = null;

            if (reader.HasAttributes)
            {
                reader.MoveToNextAttribute();
                if (reader.Name == "scope")
                {
                    scope = reader.Value;
                }
            }

            switch (scope)
            {
            case "global":
                replacements = GlobalReplacements;
                break;

            case "enum":
                replacements = EnumBackingTypeReplacements;
                break;

            default:
                throw new XmlException("<replacements> must have a 'scope' " +
                                       "attribute with a value of either 'global' or 'enum'");
            }

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.EndElement:
                    if (reader.Name == "replacements")
                    {
                        return;
                    }
                    break;

                case XmlNodeType.Element:
                    switch (reader.Name)
                    {
                    case "regex":
                    case "exact":
                    case "prefix":
                        var elementName = reader.Name;
                        var replacement = new Replacement();
                        switch (reader.Name)
                        {
                        case "regex":
                            replacement.Kind = ReplacementKind.Regex;
                            break;

                        case "exact":
                            replacement.Kind = ReplacementKind.Exact;
                            break;

                        case "prefix":
                            replacement.Kind = ReplacementKind.Prefix;
                            break;
                        }

                        if (reader.HasAttributes)
                        {
                            while (reader.MoveToNextAttribute())
                            {
                                switch (reader.Name)
                                {
                                case "pattern":
                                    replacement.Pattern = reader.Value;
                                    break;

                                case "replacement":
                                    replacement.Replace = reader.Value;
                                    break;

                                default:
                                    throw new XmlException("<" + elementName + ">: unexpected attribute '" +
                                                           reader.Name + "'; expected 'pattern' or 'replacement'");
                                }
                            }
                        }

                        if (!replacement.IsValid)
                        {
                            throw new XmlException("<" + elementName +
                                                   "> must have 'pattern' and 'replacement' attributes");
                        }

                        replacements.Add(replacement);
                        break;

                    default:
                        throw new XmlException("<replacements>: unexpected element <" +
                                               reader.Name + ">; expected <regex>, <prefix>, or <exact>");
                    }
                    break;
                }
            }
        }