@@ -34,7 +34,7 @@ public abstract class CompositionContext
3434 /// <exception cref="CompositionFailedException" />
3535 public TExport GetExport < TExport > ( )
3636 {
37- return GetExport < TExport > ( ( string ) null ) ;
37+ return GetExport < TExport > ( null ) ;
3838 }
3939
4040 /// <summary>
@@ -55,26 +55,30 @@ public TExport GetExport<TExport>(string contractName)
5555 /// <see cref="CompositionContext"/>.
5656 /// </summary>
5757 /// <param name="exportType">The type of the export to retrieve.</param>
58- /// <param name="contractName">Optionally, a discriminator that constrains the selection of the export.</param>
5958 /// <returns>An instance of the export.</returns>
6059 /// <param name="export">The export if available, otherwise, null.</param>
6160 /// <exception cref="CompositionFailedException" />
62- public bool TryGetExport ( Type exportType , string contractName , out object export )
61+ public bool TryGetExport ( Type exportType , out object export )
6362 {
64- return TryGetExport ( new CompositionContract ( exportType , contractName ) , out export ) ;
63+ return TryGetExport ( exportType , null , out export ) ;
6564 }
6665
6766 /// <summary>
6867 /// Retrieve the single <paramref name="exportType"/> instance from the
6968 /// <see cref="CompositionContext"/>.
7069 /// </summary>
7170 /// <param name="exportType">The type of the export to retrieve.</param>
71+ /// <param name="contractName">Optionally, a discriminator that constrains the selection of the export.</param>
7272 /// <returns>An instance of the export.</returns>
7373 /// <param name="export">The export if available, otherwise, null.</param>
7474 /// <exception cref="CompositionFailedException" />
75- public bool TryGetExport ( Type exportType , out object export )
75+ public bool TryGetExport ( Type exportType , string contractName , out object export )
7676 {
77- return TryGetExport ( exportType , null , out export ) ;
77+ if ( TryGetExport ( new CompositionContract ( exportType , contractName ) , out export ) )
78+ return true ;
79+
80+ export = default ;
81+ return false ;
7882 }
7983
8084 /// <summary>
@@ -87,7 +91,7 @@ public bool TryGetExport(Type exportType, out object export)
8791 /// <exception cref="CompositionFailedException" />
8892 public bool TryGetExport < TExport > ( out TExport export )
8993 {
90- return TryGetExport < TExport > ( null , out export ) ;
94+ return TryGetExport ( null , out export ) ;
9195 }
9296
9397 /// <summary>
@@ -101,10 +105,9 @@ public bool TryGetExport<TExport>(out TExport export)
101105 /// <exception cref="CompositionFailedException" />
102106 public bool TryGetExport < TExport > ( string contractName , out TExport export )
103107 {
104- object untypedExport ;
105- if ( ! TryGetExport ( typeof ( TExport ) , contractName , out untypedExport ) )
108+ if ( ! TryGetExport ( typeof ( TExport ) , contractName , out object untypedExport ) )
106109 {
107- export = default ( TExport ) ;
110+ export = default ;
108111 return false ;
109112 }
110113
@@ -121,7 +124,7 @@ public bool TryGetExport<TExport>(string contractName, out TExport export)
121124 /// <exception cref="CompositionFailedException" />
122125 public object GetExport ( Type exportType )
123126 {
124- return GetExport ( exportType , ( string ) null ) ;
127+ return GetExport ( exportType , null ) ;
125128 }
126129
127130 /// <summary>
@@ -146,12 +149,10 @@ public object GetExport(Type exportType, string contractName)
146149 /// <exception cref="CompositionFailedException" />
147150 public object GetExport ( CompositionContract contract )
148151 {
149- object export ;
150- if ( ! TryGetExport ( contract , out export ) )
151- throw new CompositionFailedException (
152- string . Format ( SR . CompositionContext_NoExportFoundForContract , contract ) ) ;
152+ if ( TryGetExport ( contract , out object export ) )
153+ return export ;
153154
154- return export ;
155+ throw new CompositionFailedException ( SR . Format ( SR . CompositionContext_NoExportFoundForContract , contract ) ) ;
155156 }
156157
157158 /// <summary>
@@ -162,7 +163,7 @@ public object GetExport(CompositionContract contract)
162163 /// <exception cref="CompositionFailedException" />
163164 public IEnumerable < object > GetExports ( Type exportType )
164165 {
165- return GetExports ( exportType , ( string ) null ) ;
166+ return GetExports ( exportType , null ) ;
166167 }
167168
168169 /// <summary>
@@ -192,7 +193,7 @@ public IEnumerable<object> GetExports(Type exportType, string contractName)
192193 /// <exception cref="CompositionFailedException" />
193194 public IEnumerable < TExport > GetExports < TExport > ( )
194195 {
195- return GetExports < TExport > ( ( string ) null ) ;
196+ return GetExports < TExport > ( null ) ;
196197 }
197198
198199 /// <summary>
0 commit comments