Esempio n. 1
0
 internal static void Infer <T>(this InformationProvider provider, T instance)
 {
     foreach (var property in instance.GetType().GetTypeInfo().DeclaredProperties)
     {
         // simple props only
         if (
             property.PropertyType.GetTypeInfo().IsPrimitive ||
             property.PropertyType.GetTypeInfo().IsEnum ||
             property.PropertyType == typeof(string))
         {
             var prefix = property.GetCustomAttribute <PrefixAttribute>()?.Key ?? string.Empty;
             var value  = provider.GetValue(prefix + property.Name).FirstOrDefault();
             if (!string.IsNullOrWhiteSpace(value))
             {
                 property.SetValue(instance, Convert.ChangeType(value, property.PropertyType));
             }
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GitVersion" /> class.
 /// </summary>
 /// <param name="assembly">The assembly.</param>
 private GitVersion(Assembly assembly)
 {
     _information = new InformationProvider(assembly);
     _information.Infer(this);
 }