Skip to content

Commit fe9e602

Browse files
committed
Remove the Exception when the AssemblyCompanyAttribute and AssemblyCopyrightAttribute are null and set Copyright to a default value.
1 parent 2063ffc commit fe9e602

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/CommandLine/Text/CopyrightInfo.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ public class CopyrightInfo
2727
/// <summary>
2828
/// An empty object used for initialization.
2929
/// </summary>
30-
public static CopyrightInfo Empty
30+
public static CopyrightInfo Empty
3131
{
3232
get
3333
{
34-
return new CopyrightInfo("author", 1);
34+
return new CopyrightInfo("author", DateTime.Now.Year);
3535
}
3636
}
3737

@@ -115,12 +115,13 @@ public static CopyrightInfo Default
115115
case MaybeType.Just:
116116
return new CopyrightInfo(copyrightAttr.FromJustOrFail());
117117
default:
118-
// if no copyright attribute exist but a company attribute does, use it as copyright holder
119-
return new CopyrightInfo(
120-
ReflectionHelper.GetAttribute<AssemblyCompanyAttribute>().FromJustOrFail(
121-
new InvalidOperationException("CopyrightInfo::Default requires that you define AssemblyCopyrightAttribute or AssemblyCompanyAttribute.")
122-
).Company,
123-
DateTime.Now.Year);
118+
var companyAttr = ReflectionHelper.GetAttribute<AssemblyCompanyAttribute>();
119+
return companyAttr.IsNothing()
120+
//if both copyrightAttr and companyAttr aren't available in Assembly,don't fire Exception
121+
? Empty
122+
// if no copyright attribute exist but a company attribute does, use it as copyright holder
123+
: new CopyrightInfo(companyAttr.FromJust().Company, DateTime.Now.Year);
124+
124125
}
125126
}
126127
}
@@ -192,4 +193,4 @@ protected virtual string FormatYears(int[] years)
192193
return yearsPart.ToString();
193194
}
194195
}
195-
}
196+
}

0 commit comments

Comments
 (0)