示例#1
0
文件: Project.cs 项目: yongaru/uno
        Project(string fullPath, UnoprojDocument document)
        {
            _fullPath = fullPath;
            _doc      = document;

            foreach (var e in PropertyDefinitions.RenamedItems)
            {
                if (_doc.Properties.ContainsKey(e.Key) && !_doc.Properties.ContainsKey(e.Value))
                {
                    _doc.Properties[e.Value] = _doc.Properties[e.Key];
                    _doc.Properties.Remove(e.Key);

                    var newProperties = new Dictionary <string, SourceValue>();

                    foreach (var p in _doc.Properties)
                    {
                        if (!string.IsNullOrEmpty(p.Value.String))
                        {
                            newProperties[p.Key] = new SourceValue(p.Value.Source, p.Value.String.Replace("$(" + e.Key + ")", "$(" + e.Value + ")"));
                        }
                    }

                    foreach (var p in newProperties)
                    {
                        _doc.Properties[p.Key] = p.Value;
                    }
                }
            }
        }
示例#2
0
 UnoprojParser(Log log, string filename)
     : base(new StreamReader(filename))
 {
     _log      = log;
     _file     = new SourceFile(SourcePackage.Unknown, filename);
     _document = new UnoprojDocument();
 }
示例#3
0
 public static void Serialize(UnoprojDocument project, string filename)
 {
     using (var f = File.Create(filename))
         Serialize(project, f);
 }
示例#4
0
        public static void Serialize(UnoprojDocument project, Stream stream)
        {
            var json = new Dictionary <string, object>();

            foreach (var e in project.Properties)
            {
                var parts  = e.Key.Split('.');
                var key    = parts.Last();
                var parent = json;

                for (int i = 0; i < parts.Length - 1; i++)
                {
                    object obj;
                    if (!parent.TryGetValue(parts[i], out obj))
                    {
                        obj = new Dictionary <string, object>();
                        parent.Add(parts[i], obj);
                    }

                    parent = (Dictionary <string, object>)obj;
                }

                bool boolValue;
                int  intValue;
                if (e.Value.String == null)
                {
                    parent[key] = null;
                }
                else if (bool.TryParse(e.Value.String, out boolValue))
                {
                    parent[key] = boolValue;
                }
                else if (int.TryParse(e.Value.String, out intValue))
                {
                    parent[key] = intValue;
                }
                else if (parent != json && e.Value.String.IndexOf('\n') != -1)
                {
                    parent[key] = e.Value.String.Split('\n');
                }
                else
                {
                    parent[key] = e.Value.String;
                }
            }

            if (project.OptionalInternalsVisibleTo != null)
            {
                var internals = new List <string>();

                foreach (var e in project.OptionalInternalsVisibleTo)
                {
                    internals.Add(e.String);
                }

                json["InternalsVisibleTo"] = internals;
            }

            if (project.OptionalPackages != null)
            {
                var packages = new List <string>();

                foreach (var e in project.OptionalPackages)
                {
                    packages.Add(e.ToString());
                }

                json["Packages"] = packages;
            }

            if (project.OptionalProjects != null)
            {
                var projects = new List <string>();

                foreach (var e in project.OptionalProjects)
                {
                    projects.Add(e.ToString());
                }

                json["Projects"] = projects;
            }

            if (project.Includes != null)
            {
                var includes = new List <string>();

                foreach (var e in project.Includes)
                {
                    includes.Add(e.ToString());
                }

                json["Includes"] = includes;
            }

            if (project.OptionalExcludes != null)
            {
                var excludes = new List <string>();

                foreach (var e in project.OptionalExcludes)
                {
                    excludes.Add(e.String.NativeToUnix());
                }

                json["Excludes"] = excludes;
            }

            var w = new StreamWriter(stream);

            try
            {
                new JsonSerializer()
                {
                    Formatting = Formatting.Indented
                }
                .Serialize(w, json);
            }
            finally
            {
                w.Flush();
            }
        }