diff --git a/src/ContainerIntegration/AdditionalInterface.cs b/src/ContainerIntegration/AdditionalInterface.cs index 9a3e362..7d4a0e5 100644 --- a/src/ContainerIntegration/AdditionalInterface.cs +++ b/src/ContainerIntegration/AdditionalInterface.cs @@ -3,7 +3,7 @@ using System; using System.Globalization; using Microsoft.Practices.ObjectBuilder2; -using Microsoft.Practices.Unity.InterceptionExtension.Properties; +using Unity.Interception.Properties; using Microsoft.Practices.Unity.Utility; namespace Microsoft.Practices.Unity.InterceptionExtension diff --git a/src/ContainerIntegration/Interception.cs b/src/ContainerIntegration/Interception.cs index b0d71c1..7197c5d 100644 --- a/src/ContainerIntegration/Interception.cs +++ b/src/ContainerIntegration/Interception.cs @@ -3,7 +3,7 @@ using System; using System.Globalization; using Microsoft.Practices.ObjectBuilder2; -using Microsoft.Practices.Unity.InterceptionExtension.Properties; +using Unity.Interception.Properties; using Microsoft.Practices.Unity.ObjectBuilder; using Guard = Microsoft.Practices.Unity.Utility.Guard; diff --git a/src/Intercept.cs b/src/Intercept.cs index 804944e..ae1afd2 100644 --- a/src/Intercept.cs +++ b/src/Intercept.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using System.Globalization; using System.Linq; -using Microsoft.Practices.Unity.InterceptionExtension.Properties; +using Unity.Interception.Properties; using Microsoft.Practices.Unity.Utility; namespace Microsoft.Practices.Unity.InterceptionExtension diff --git a/src/Interceptors/GenericParameterMapper.cs b/src/Interceptors/GenericParameterMapper.cs index a7ff139..00fca6a 100644 --- a/src/Interceptors/GenericParameterMapper.cs +++ b/src/Interceptors/GenericParameterMapper.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.Practices.Unity.InterceptionExtension.Properties; +using Unity.Interception.Properties; using Microsoft.Practices.Unity.Utility; namespace Microsoft.Practices.Unity.InterceptionExtension diff --git a/src/Interceptors/InstanceInterceptors/InterfaceInterception/InterfaceInterceptorClassGenerator.cs b/src/Interceptors/InstanceInterceptors/InterfaceInterception/InterfaceInterceptorClassGenerator.cs index 041294b..47187e1 100644 --- a/src/Interceptors/InstanceInterceptors/InterfaceInterception/InterfaceInterceptorClassGenerator.cs +++ b/src/Interceptors/InstanceInterceptors/InterfaceInterception/InterfaceInterceptorClassGenerator.cs @@ -9,7 +9,7 @@ using System.Reflection; using System.Reflection.Emit; using System.Security; using Microsoft.Practices.ObjectBuilder2; -using Microsoft.Practices.Unity.InterceptionExtension.Properties; +using Unity.Interception.Properties; namespace Microsoft.Practices.Unity.InterceptionExtension { diff --git a/src/Interceptors/InstanceInterceptors/InterfaceInterception/InterfaceMethodOverride.cs b/src/Interceptors/InstanceInterceptors/InterfaceInterception/InterfaceMethodOverride.cs index 88deea9..f1edfa1 100644 --- a/src/Interceptors/InstanceInterceptors/InterfaceInterception/InterfaceMethodOverride.cs +++ b/src/Interceptors/InstanceInterceptors/InterfaceInterception/InterfaceMethodOverride.cs @@ -6,7 +6,7 @@ using System.Globalization; using System.Linq; using System.Reflection; using System.Reflection.Emit; -using Microsoft.Practices.Unity.InterceptionExtension.Properties; +using Unity.Interception.Properties; using Microsoft.Practices.Unity.Utility; namespace Microsoft.Practices.Unity.InterceptionExtension diff --git a/src/Interceptors/InstanceInterceptors/TransparentProxyInterception/InterceptingRealProxy.cs b/src/Interceptors/InstanceInterceptors/TransparentProxyInterception/InterceptingRealProxy.cs index 4bd23b9..bec1aab 100644 --- a/src/Interceptors/InstanceInterceptors/TransparentProxyInterception/InterceptingRealProxy.cs +++ b/src/Interceptors/InstanceInterceptors/TransparentProxyInterception/InterceptingRealProxy.cs @@ -10,7 +10,7 @@ using System.Runtime.Remoting.Messaging; using System.Runtime.Remoting.Proxies; using System.Security; using System.Security.Permissions; -using Microsoft.Practices.Unity.InterceptionExtension.Properties; +using Unity.Interception.Properties; using Microsoft.Practices.Unity.Utility; namespace Microsoft.Practices.Unity.InterceptionExtension diff --git a/src/Interceptors/TypeInterceptors/VirtualMethodInterception/InterceptingClassGeneration/MethodOverride.cs b/src/Interceptors/TypeInterceptors/VirtualMethodInterception/InterceptingClassGeneration/MethodOverride.cs index 6404b6c..4718573 100644 --- a/src/Interceptors/TypeInterceptors/VirtualMethodInterception/InterceptingClassGeneration/MethodOverride.cs +++ b/src/Interceptors/TypeInterceptors/VirtualMethodInterception/InterceptingClassGeneration/MethodOverride.cs @@ -7,7 +7,7 @@ using System.Globalization; using System.Linq; using System.Reflection; using System.Reflection.Emit; -using Microsoft.Practices.Unity.InterceptionExtension.Properties; +using Unity.Interception.Properties; using Microsoft.Practices.Unity.Utility; namespace Microsoft.Practices.Unity.InterceptionExtension diff --git a/src/Interceptors/TypeInterceptors/VirtualMethodInterception/VirtualMethodInterceptor.cs b/src/Interceptors/TypeInterceptors/VirtualMethodInterception/VirtualMethodInterceptor.cs index 46c4c1d..178d317 100644 --- a/src/Interceptors/TypeInterceptors/VirtualMethodInterception/VirtualMethodInterceptor.cs +++ b/src/Interceptors/TypeInterceptors/VirtualMethodInterception/VirtualMethodInterceptor.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Reflection; -using Microsoft.Practices.Unity.InterceptionExtension.Properties; +using Unity.Interception.Properties; using Microsoft.Practices.Unity.Utility; namespace Microsoft.Practices.Unity.InterceptionExtension diff --git a/src/PolicyInjection/MatchingRules/CustomAttributeMatchingRule.cs b/src/PolicyInjection/MatchingRules/CustomAttributeMatchingRule.cs index 98bf729..b178898 100644 --- a/src/PolicyInjection/MatchingRules/CustomAttributeMatchingRule.cs +++ b/src/PolicyInjection/MatchingRules/CustomAttributeMatchingRule.cs @@ -3,7 +3,7 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Reflection; -using Microsoft.Practices.Unity.InterceptionExtension.Properties; +using Unity.Interception.Properties; using Microsoft.Practices.Unity.Utility; namespace Microsoft.Practices.Unity.InterceptionExtension diff --git a/src/Properties/Resources.Designer.cs b/src/Properties/Resources.Designer.cs index 83a9a04..c8dc564 100644 --- a/src/Properties/Resources.Designer.cs +++ b/src/Properties/Resources.Designer.cs @@ -1,15 +1,16 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.17379 +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // //------------------------------------------------------------------------------ -namespace Microsoft.Practices.Unity.InterceptionExtension.Properties { +namespace Unity.Interception.Properties { using System; + using System.Reflection; /// @@ -19,7 +20,7 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -39,7 +40,7 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Properties { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.Practices.Unity.InterceptionExtension.Properties.Resources", typeof(Resources).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Unity.Interception.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; diff --git a/src/Properties/Resources.resx b/src/Properties/Resources.resx index 30d85dd..58da506 100644 --- a/src/Properties/Resources.resx +++ b/src/Properties/Resources.resx @@ -112,10 +112,10 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Intercepted abstract method was invoked. @@ -131,7 +131,7 @@ Could not create instance of type {0} with no constructor arguments. - {0} = Name of the type that caused the exception + {0} = Name of the type that caused the exception Cannot map generic type parameters on a generic type definition (an unbound generic type). diff --git a/src/Utilities/EnumerableExtensions.cs b/src/Utilities/EnumerableExtensions.cs new file mode 100644 index 0000000..edfd531 --- /dev/null +++ b/src/Utilities/EnumerableExtensions.cs @@ -0,0 +1,77 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Text; +using Microsoft.Practices.Unity.Utility; + +namespace Microsoft.Practices.ObjectBuilder2 +{ + /// + /// The almost inevitable collection of extra helper methods on + /// to augment the rich set of what + /// LINQ already gives us. + /// + public static class EnumerableExtensions + { + /// + /// Execute the provided on every item in . + /// + /// Type of the items stored in + /// Sequence of items to process. + /// Code to run over each item. + [SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods", Justification = "Validation done by Guard class")] + public static void ForEach(this IEnumerable sequence, Action action) + { + Guard.ArgumentNotNull(sequence, "sequence"); + + foreach (var item in sequence) + { + action(item); + } + } + + /// + /// Create a single string from a sequence of items, separated by the provided , + /// and with the conversion to string done by the given . + /// + /// This method does basically the same thing as , + /// but will work on any sequence of items, not just arrays. + /// Type of items in the sequence. + /// Sequence of items to convert. + /// Separator to place between the items in the string. + /// The conversion function to change TItem -> string. + /// The resulting string. + public static string JoinStrings(this IEnumerable sequence, string separator, Func converter) + { + var sb = new StringBuilder(); + sequence.Aggregate(sb, (builder, item) => + { + if (builder.Length > 0) + { + builder.Append(separator); + } + builder.Append(converter(item)); + return builder; + }); + return sb.ToString(); + } + + /// + /// Create a single string from a sequence of items, separated by the provided , + /// and with the conversion to string done by the item's method. + /// + /// This method does basically the same thing as , + /// but will work on any sequence of items, not just arrays. + /// Type of items in the sequence. + /// Sequence of items to convert. + /// Separator to place between the items in the string. + /// The resulting string. + public static string JoinStrings(this IEnumerable sequence, string separator) + { + return sequence.JoinStrings(separator, item => item.ToString()); + } + } +} diff --git a/tests/VirtualMethodInterception/InterceptingClassGenerationFixture.cs b/tests/VirtualMethodInterception/InterceptingClassGenerationFixture.cs index 03018b7..329019a 100644 --- a/tests/VirtualMethodInterception/InterceptingClassGenerationFixture.cs +++ b/tests/VirtualMethodInterception/InterceptingClassGenerationFixture.cs @@ -248,13 +248,19 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests.VirtualMethodInt } [TestMethod] - [ExpectedException(typeof(InvalidOperationException))] public void AttemptingToInterceptInvalidClassThrows() { PostCallCountHandler handler = new PostCallCountHandler(); VirtualMethodInterceptor interceptor = new VirtualMethodInterceptor(); - - interceptor.CreateProxyType(typeof(CantTouchThis)); + try + { + interceptor.CreateProxyType(typeof(CantTouchThis)); + Assert.Fail(); + } + catch (Exception ex) + { + Assert.IsInstanceOfType(ex, typeof(InvalidOperationException)); + } } [TestMethod] @@ -789,7 +795,7 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests.VirtualMethodInt { char[] chars = obj.ToString().ToCharArray(); Array.Reverse(chars); - return string.Join(string.Empty, chars); + return chars.JoinStrings(String.Empty); } }