Skip to content

Commit

Permalink
Added understandable exception for the case when MainConfigAssemblyAt…
Browse files Browse the repository at this point in the history
…tribute is applied several times
  • Loading branch information
kirmir committed Dec 4, 2016
1 parent 863e7fa commit 501cd5c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions ConfigEx.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">

<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/BLANK_LINES_AFTER_CONTROL_TRANSFER_STATEMENTS/@EntryValue">1</s:Int64>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_BEFORE_TYPEOF_PARENTHESES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_BETWEEN_ATTRIBUTE_SECTIONS/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LIMIT/@EntryValue">140</s:Int64>
Expand Down
15 changes: 10 additions & 5 deletions ConfigEx/AssemblyLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ public static Assembly GetEntryAssembly()
private static Assembly GetAssemblyWithAttribute()
{
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
var entryAssemblies = from assembly in assemblies
let attribute = assembly.GetCustomAttributes(typeof(MainConfigAssemblyAttribute)).SingleOrDefault()
where attribute != null
select assembly;
var entryAssemblies = (from assembly in assemblies
let attribute = assembly.GetCustomAttributes(typeof(MainConfigAssemblyAttribute)).FirstOrDefault()
where attribute != null
select assembly).ToList();

return entryAssemblies.SingleOrDefault();
if (entryAssemblies.Count > 1)
{
throw new Exception("Only one assembly should be marked as main using the MainConfigAssemblyAttribute");
}

return entryAssemblies.FirstOrDefault();
}
}
}

0 comments on commit 501cd5c

Please sign in to comment.