This commit is contained in:
Eugene Sadovoi 2017-10-06 20:13:46 -04:00
Родитель 8e47ab900a
Коммит 8235b59c41
14 изменённых файлов: 105 добавлений и 21 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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;

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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
{

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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

9
src/Properties/Resources.Designer.cs сгенерированный
Просмотреть файл

@ -1,15 +1,16 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Microsoft.Practices.Unity.InterceptionExtension.Properties {
namespace Unity.Interception.Properties {
using System;
using System.Reflection;
/// <summary>
@ -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;

Просмотреть файл

@ -112,10 +112,10 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ExceptionAbstractMethodNotImplemented" xml:space="preserve">
<value>Intercepted abstract method was invoked.</value>
@ -131,7 +131,7 @@
</data>
<data name="ExceptionCannotCreateInstance" xml:space="preserve">
<value>Could not create instance of type {0} with no constructor arguments.</value>
<comment>{0} = Name of the type that caused the exception</comment>
<comment>{0} = Name of the type that caused the exception </comment>
</data>
<data name="ExceptionCannotMapGenericTypeDefinition" xml:space="preserve">
<value>Cannot map generic type parameters on a generic type definition (an unbound generic type).</value>

Просмотреть файл

@ -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
{
/// <summary>
/// The almost inevitable collection of extra helper methods on
/// <see cref="IEnumerable{T}"/> to augment the rich set of what
/// LINQ already gives us.
/// </summary>
public static class EnumerableExtensions
{
/// <summary>
/// Execute the provided <paramref name="action"/> on every item in <paramref name="sequence"/>.
/// </summary>
/// <typeparam name="TItem">Type of the items stored in <paramref name="sequence"/></typeparam>
/// <param name="sequence">Sequence of items to process.</param>
/// <param name="action">Code to run over each item.</param>
[SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods", Justification = "Validation done by Guard class")]
public static void ForEach<TItem>(this IEnumerable<TItem> sequence, Action<TItem> action)
{
Guard.ArgumentNotNull(sequence, "sequence");
foreach (var item in sequence)
{
action(item);
}
}
/// <summary>
/// Create a single string from a sequence of items, separated by the provided <paramref name="separator"/>,
/// and with the conversion to string done by the given <paramref name="converter"/>.
/// </summary>
/// <remarks>This method does basically the same thing as <see cref="string.Join(string,string[])"/>,
/// but will work on any sequence of items, not just arrays.</remarks>
/// <typeparam name="TItem">Type of items in the sequence.</typeparam>
/// <param name="sequence">Sequence of items to convert.</param>
/// <param name="separator">Separator to place between the items in the string.</param>
/// <param name="converter">The conversion function to change TItem -&gt; string.</param>
/// <returns>The resulting string.</returns>
public static string JoinStrings<TItem>(this IEnumerable<TItem> sequence, string separator, Func<TItem, string> 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();
}
/// <summary>
/// Create a single string from a sequence of items, separated by the provided <paramref name="separator"/>,
/// and with the conversion to string done by the item's <see cref='object.ToString'/> method.
/// </summary>
/// <remarks>This method does basically the same thing as <see cref="string.Join(string,string[])"/>,
/// but will work on any sequence of items, not just arrays.</remarks>
/// <typeparam name="TItem">Type of items in the sequence.</typeparam>
/// <param name="sequence">Sequence of items to convert.</param>
/// <param name="separator">Separator to place between the items in the string.</param>
/// <returns>The resulting string.</returns>
public static string JoinStrings<TItem>(this IEnumerable<TItem> sequence, string separator)
{
return sequence.JoinStrings(separator, item => item.ToString());
}
}
}

Просмотреть файл

@ -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);
}
}