/// <summary> /// Gets reference field from an argument. /// </summary> private static string GetFromArgument(ArgumentProperties args, string key) { string result = null; if (args.Contains(key)) { result = args.GetValue(key); args.Remove(key); } return(result); }
/// <summary> /// Gets binary references. /// </summary> public static List <Reference> GetBinaryReferences() { List <Reference> references = new List <Reference>(); foreach (XmlNode node in SelectNodes("/ms:Project/ms:ItemGroup/ms:Reference")) { Reference reference = new Reference(); Dictionary <string, string> properties = PropertiesHelper.ParseFromXml(node); if (properties.ContainsKey("/Reference[@Include]")) { string include = "Name={0}".Display(properties["/Reference[@Include]"]); properties.Remove("/Reference[@Include]"); ArgumentProperties args = ArgumentProperties.Parse(include.Split(',')); reference.Name = GetFromArgument(args, "Name"); reference.Version = GetFromArgument(args, "Version"); reference.Culture = GetFromArgument(args, "Culture"); reference.PublicKeyToken = GetFromArgument(args, "PublicKeyToken"); reference.ProcessorArchitecture = GetFromArgument(args, "processorArchitecture"); if (args.Keys.Count > 0) { throw new InvalidOperationException( "Unknown reference include properties: {0}." .Display(String.Join(", ", args.Keys))); } } reference.SpecificVersion = GetFromProperty(properties, "/Reference/SpecificVersion"); reference.HintPath = GetFromProperty(properties, "/Reference/HintPath"); reference.Private = GetFromProperty(properties, "/Reference/Private"); reference.Aliases = GetFromProperty(properties, "/Reference/Aliases"); reference.EmbedInteropTypes = GetFromProperty(properties, "/Reference/EmbedInteropTypes"); reference.RequiredTargetFramework = GetFromProperty(properties, "/Reference/RequiredTargetFramework"); reference.ExecutableExtension = GetFromProperty(properties, "/Reference/ExecutableExtension"); if (properties.Keys.Count > 0) { throw new InvalidOperationException( "Unknown reference child properties: {0}." .Display(String.Join(", ", properties.Keys))); } references.Add(reference); } return(references); }
/// <summary> /// Parses a list of argument properties. /// </summary> public static ArgumentProperties Parse(params string[] args) { Contract.Requires(args != null); ArgumentProperties result = new ArgumentProperties(); foreach (string arg in args) { string[] parts = arg.Split('='); if (parts.Length != 2) { throw new InvalidOperationException( "Argument {0} doesn't define a property." .Display(arg)); } string key = parts[0].Trim(); string value = parts[1].Trim(); result.Add(key, value); } return(result); }