Beispiel #1
0
        public ResxGenWriter(string filename, string nameSpace, string resxNameSpace, bool asPublic, bool asPartial, bool asSealed,
                             string className, string baseException)
        {
            _options       = new ResXOptions();
            _fileName      = filename;
            _nameSpace     = nameSpace;
            _resxNameSpace = resxNameSpace;
            _public        = asPublic;
            _partial       = asPartial;
            _sealed        = asSealed;
            _className     = className;
            _baseException = baseException;
            _fullClassName = String.Format("{0}.{1}", _nameSpace, _className);
            _eventLogger   = null;

            //Environment.CurrentDirectory = Path.GetDirectoryName(_fileName);
            Parse(_xstrings = new List <ResxString>(), _xexceptions = new Dictionary <string, ResxException>(StringComparer.Ordinal), _xnodes = new List <ResXDataNode>());
            _eventLogger    = _eventLogger ?? _options.AutoLogMethod;
        }
        public ResxGenItem(ResXOptions options, ResXDataNode node)
        {
            Node    = node;
            Ignored = true;            //and clear upon complete...

            Options = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            Args    = new List <ResxGenArgument>();
            try
            {
                if (node.FileRef != null)
                {
                    return;
                }
                Type type = Type.GetType(node.GetValueTypeName(AllowedNames));
                if (type == null || type != typeof(String))
                {
                    return;
                }
                Value = (String)node.GetValue(AllowedNames);
            }
            catch { return; }

            MemberName = Identifier = StronglyTypedResourceBuilder.VerifyResourceName(node.Name, Csharp);
            FullName   = ItemName = node.Name;

            Comments = node.Comment;
            string rawArgs = null;

            IsFormatter = FormatingMatch.IsMatch(Value);
            IsException = ExceptionMatch.IsMatch(node.Name);
            //if (!IsFormatter && !IsException)
            //    return;

            int pos;

            if ((pos = ItemName.IndexOf('(')) > 0)
            {
                rawArgs    = ItemName.Substring(pos);
                ItemName   = ItemName.Substring(0, pos);
                MemberName = StronglyTypedResourceBuilder.VerifyResourceName(ItemName, Csharp);
            }
            else if (Comments.StartsWith("(") && (pos = Comments.IndexOf(')')) > 0)
            {
                rawArgs  = Comments.Substring(0, 1 + pos);
                Comments = Comments.Substring(pos + 1).Trim();
            }
            if (!String.IsNullOrEmpty(rawArgs))
            {
                Args.AddRange(new ResxGenArgParser(rawArgs));
            }

            //now thats out of the way... let's transform the format string into something usable:
            Value = StringUtils.Transform(Value, FormatingMatch,
                                          delegate(Match m)
            {
                return("{" + GetArg(null, m.Groups["field"].Value) + m.Groups["suffix"].Value + "}");
            }
                                          );

            if (Comments.StartsWith(":") && Comments.IndexOf("Exception") > 0)
            {
                IsException = true;
            }

            bool parsedOptions = ParseOptions(ref Comments);

            FacilityId = options.FacilityId;
            bool hasId = GetMessageIdForItem(out MessageId);

            hasId |= GetHResultForItem(out HResult);

            HasArguments = Args.Count > 0;
            if (HasArguments || IsFormatter || IsException || hasId)
            {
                Ignored = false;
                if (!parsedOptions)
                {
                    throw new ApplicationException(String.Format("Unable to parse comment options: '{0}'", Comments));
                }
            }
            AutoLog = hasId && MessageId != 0 && options.AutoLog && GetOption("log", true);
        }