コード例 #1
0
ファイル: StuffObject.cs プロジェクト: mohammedmanssour/uno
        public static StuffObject Parse(string filename, string stuff, Func <string, string> requireResolver = null, StuffFlags flags = 0, IEnumerable <string> optionalDefines = null)
        {
            var file = new StuffFile(
                filename,
                flags.HasFlag(StuffFlags.AcceptAll)
                    ? null
                    : new HashSet <string>(
                    (optionalDefines ?? StuffFile.DefaultDefines)
                    .Select(x => x.ToUpperInvariant())));

            file.Parse(stuff, flags.HasFlag(StuffFlags.Print));
            var result = file.Flatten(requireResolver).ToObject();

            // Workaround to avoid side-effect when StuffFlags.AcceptAll is set
            if (flags.HasFlag(StuffFlags.AcceptAll))
            {
                foreach (var e in Parse(filename, stuff, requireResolver, 0, optionalDefines))
                {
                    if (!result.ContainsKey(e.Key) || result[e.Key]?.ToString().IndexOf('\n') == -1)
                    {
                        result[e.Key] = e.Value;
                    }
                }
            }

            if (flags.HasFlag(StuffFlags.Print))
            {
                Log.WriteLine(result.StringifyStuff());
            }

            return(result);
        }
コード例 #2
0
ファイル: StuffMap.cs プロジェクト: mohammedmanssour/uno
        public void Require(string filename, HashSet <string> defines, Func <string, string> requireResolver = null)
        {
            // Early out on circular include
            if (ContainsFile(filename))
            {
                return;
            }

            if (requireResolver == null)
            {
                throw new NotSupportedException("'require' is not supported because a 'requireResolver' was not provided");
            }

            var includeFile = new StuffFile(filename, defines);

            includeFile.Parse(requireResolver(filename));
            AddFile(includeFile, requireResolver);
        }