Exemplo n.º 1
0
 IPackageBuilder AssignProperties(IPackageBuilder builder, IEnumerable <IGrouping <string, string> > properties)
 {
     foreach (var property in properties)
     {
         var pi = builder.GetType().GetProperty(property.Key, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public);
         if (pi != null)
         {
             pi.SetValue(builder, property.ToList(), null);
         }
     }
     return(builder);
 }
Exemplo n.º 2
0
        static IPackageBuilder AssignProperties(IPackageBuilder builder, IEnumerable <IGrouping <string, string> > properties)
        {
            var unknown = new List <KeyValuePair <string, string> >();


            var builderType = builder.GetType();

            foreach (var property in properties)
            {
                var pi = builderType.GetProperty(property.Key, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public);
                if (pi != null)
                {
                    bool boolProperty;
                    if (typeof(IEnumerable <string>).IsAssignableFrom(pi.PropertyType))
                    {
                        var existingValues = pi.GetValue(builder, null) as IEnumerable <string>;
                        if (existingValues == null || existingValues.Count() == 0)
                        {
                            pi.SetValue(builder, property.ToList(), null);
                        }
                    }
                    else if (pi.PropertyType == typeof(string) && property.Count() > 0)
                    {
                        pi.SetValue(builder, property.Last(), null);
                    }
                    else if (pi.PropertyType == typeof(bool) && property.Count() > 0 && bool.TryParse(property.Last(), out boolProperty))
                    {
                        pi.SetValue(builder, boolProperty, null);
                    }
                }
                else
                {
                    unknown.AddRange(property.Select(x => new KeyValuePair <string, string>(property.Key, x)));
                }
            }
            var propertiesPi = builderType.GetProperty("Properties", BindingFlags.Instance | BindingFlags.Public);

            if (propertiesPi != null && typeof(IEnumerable <IGrouping <string, string> >).IsAssignableFrom(propertiesPi.PropertyType))
            {
                var unknownLookup = unknown.ToLookup(x => x.Key, x => x.Value, StringComparer.OrdinalIgnoreCase);
                propertiesPi.SetValue(builder, unknownLookup, null);
            }
            return(builder);
        }
Exemplo n.º 3
0
        static IPackageBuilder AssignProperties(IPackageBuilder builder, IEnumerable<IGrouping<string, string>> properties)
        {
            var unknown = new List<KeyValuePair<string, string>>();

            var builderType = builder.GetType();
            foreach (var property in properties)
            {
                var pi = builderType.GetProperty(property.Key, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public);
                if (pi != null)
                {
                    bool boolProperty;
                    if (typeof(IEnumerable<string>).IsAssignableFrom(pi.PropertyType))
                    {
                        var existingValues = pi.GetValue(builder, null) as IEnumerable<string>;
                        if (existingValues == null || existingValues.Count() == 0)
                            pi.SetValue(builder, property.ToList(), null);
                    }
                    else if (pi.PropertyType == typeof(string) && property.Count() > 0)
                    {
                        pi.SetValue(builder, property.Last(), null);
                    }
                    else if (pi.PropertyType == typeof(bool) && property.Count() > 0 && bool.TryParse(property.Last(), out boolProperty))
                    {
                        pi.SetValue(builder, boolProperty, null);
                    }
                }
                else
                {
                    unknown.AddRange(property.Select(x => new KeyValuePair<string, string>(property.Key, x)));
                }
            }
            var propertiesPi = builderType.GetProperty("Properties", BindingFlags.Instance | BindingFlags.Public);
            if (propertiesPi != null && typeof(IEnumerable<IGrouping<string, string>>).IsAssignableFrom(propertiesPi.PropertyType))
            {
                var unknownLookup = unknown.ToLookup(x => x.Key, x => x.Value, StringComparer.OrdinalIgnoreCase);
                propertiesPi.SetValue(builder, unknownLookup, null);
            }
            return builder;
        }
Exemplo n.º 4
0
 IPackageBuilder AssignProperties(IPackageBuilder builder, IEnumerable<IGrouping<string,string>> properties)
 {
     foreach (var property in properties)
     {
         var pi = builder.GetType().GetProperty(property.Key, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public);
         if (pi != null)
             pi.SetValue(builder, property.ToList(), null);
     }
     return builder;
 }
Exemplo n.º 5
0
        ICommandOutput CreateBuilder()
        {
            var commandLine = Environment.Descriptor.BuildCommand;
            if (string.IsNullOrEmpty(commandLine))
                commandLine = "msbuild";
            var properties = from segment in commandLine.Split(';').Skip(1)
                             let keyValues = segment.Split('=')
                             where keyValues.Length >= 2
                             let key = keyValues[0]
                             let value = segment.Substring(key.Length + 1)
                             group new { key, value } by key;

            _builder = commandLine.Trim().StartsWith("msbuild", StringComparison.OrdinalIgnoreCase)
                                  ? (IPackageBuilder)new MSBuildBuildEngine(FileSystem, Environment)
                                  : new MetaPackageBuilder(Environment);
            foreach(var property in properties)
            {
                var pi = _builder.GetType().GetProperty(property.Key, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public);
                if (pi != null)
                    pi.SetValue(_builder, property.Select(x=>x.value).ToList(), null);
            }
            return null;
        }