コード例 #1
0
        // pass the Nameable.Name last, after all constructor arguments
        public override T Create <T>(
            params object[] dependencies)
        {
            var ds = dependencies;

            if (ds == null)
            {
                return(base.Create <T>());
            }

            var l = ds.Length;

            if (l < one || !typeof(Nameable).IsAssignableFrom(typeof(T)))
            {
                return(base.Create <T>(ds));
            }

            var possibleNameable = base.Create <T>(
                EH.ToArray(
                    EH.Take(
                        ds,
                        l - one)));

            if (possibleNameable is Nameable n &&
                EH.Last(ds) is string name)
            {
                n.Name = name;
            }

            return(possibleNameable);
        }
コード例 #2
0
        protected virtual ICollection <string> readKeysInSectionProtected(
            string[] lines,
            SectionHeader targetHeader)
        {
            ICollection <string> keys = new LinkedList <string>();

            if (targetHeader == default)
            {
                return(keys);
            }

            var headers = this.readSectionHeaders(lines);

            if (!EH.Contains(
                    EH.Select(
                        headers,
                        header => header.Name),
                    targetHeader.Name))
            {
                return(keys);
            }

            var lineNumber = targetHeader.LineNumber;
            int lastLineIndex;

            if (EH.Last(
                    EH.Select(
                        headers,
                        header => header.Name)) == targetHeader.Name)
            {
                lastLineIndex = lines.Length - 1;
                goto readKeys;
            }

            var headerCounter = 1;

            foreach (var header in headers)
            {
                if (header.Name == targetHeader.Name)
                {
                    break;
                }

                ++headerCounter;
            }

            var nextHeader = EH.FirstOrDefault(
                EH.Skip(
                    headers, headerCounter));

            lastLineIndex = nextHeader?.LineNumber - 1
                            ?? lines.Length - 1;


readKeys:
            for (var i = lineNumber; i <= lastLineIndex; ++i)
            {
                var indexOfSemicolon = lines[i].IndexOf(';');
                if (indexOfSemicolon == 0)
                {
                    continue;
                }

                var indexOfEquals = lines[i].IndexOf('=');
                if (indexOfEquals < 0)
                {
                    continue;
                }

                if (indexOfSemicolon > -1 &&
                    indexOfSemicolon < indexOfEquals)
                {
                    continue;
                }

                var keyName = lines[i]
                              .Substring(0, indexOfEquals);
                keys.Add(keyName);
            }

            return(keys);
        }