Ok so it looks like StructLayoutAttribute melts away and converts to metadata
This commit is contained in:
Родитель
7ca0a146b9
Коммит
9a7b41a2c3
|
@ -97,34 +97,27 @@ namespace NSubstitute.Elevated.Weaver
|
|||
return;
|
||||
if (type.Name == "<Module>")
|
||||
return;
|
||||
if (type.CustomAttributes.Any(a =>
|
||||
a.AttributeType.FullName == typeof(CompilerGeneratedAttribute).FullName ||
|
||||
a.AttributeType.FullName == typeof(StructLayoutAttribute).FullName))
|
||||
if (type.IsExplicitLayout)
|
||||
return;
|
||||
if (type.CustomAttributes.Any(a => a.AttributeType.FullName == typeof(CompilerGeneratedAttribute).FullName))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var patched = false;
|
||||
foreach (var method in type.Methods)
|
||||
Patch(method);
|
||||
|
||||
void AddField(string fieldName, FieldAttributes fieldAttributes)
|
||||
{
|
||||
if (Patch(method))
|
||||
patched = true;
|
||||
type.Fields.Add(new FieldDefinition(fieldName,
|
||||
FieldAttributes.Private | FieldAttributes.NotSerialized | fieldAttributes,
|
||||
type.Module.TypeSystem.Object));
|
||||
}
|
||||
|
||||
if (patched)
|
||||
{
|
||||
void AddField(string fieldName, FieldAttributes fieldAttributes)
|
||||
{
|
||||
type.Fields.Add(new FieldDefinition(fieldName,
|
||||
FieldAttributes.Private | FieldAttributes.NotSerialized | fieldAttributes,
|
||||
type.Module.TypeSystem.Object));
|
||||
}
|
||||
AddField(InjectedMockStaticDataName, FieldAttributes.Static);
|
||||
AddField(InjectedMockDataName, 0);
|
||||
|
||||
AddField(InjectedMockStaticDataName, FieldAttributes.Static);
|
||||
AddField(InjectedMockDataName, 0);
|
||||
|
||||
AddMockCtor(type);
|
||||
}
|
||||
AddMockCtor(type);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -179,14 +172,12 @@ namespace NSubstitute.Elevated.Weaver
|
|||
type.Methods.Add(ctor);
|
||||
}
|
||||
|
||||
bool Patch(MethodDefinition method)
|
||||
void Patch(MethodDefinition method)
|
||||
{
|
||||
if (method.IsCompilerControlled || method.IsConstructor || method.IsAbstract)
|
||||
return false;
|
||||
return;
|
||||
|
||||
// $$$ DOWIT
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ using Shouldly;
|
|||
|
||||
namespace NSubstitute.Elevated.Tests
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class ElevatedWeaverTests
|
||||
{
|
||||
|
@ -32,7 +31,7 @@ namespace NSubstitute.Elevated.Tests
|
|||
|
||||
class ClassWithGeneratedNestedType
|
||||
{
|
||||
public IEnumerable<int> Foo() // this causes a state machine type to be generated which shouldn't be patched
|
||||
public IEnumerable<int> Foo() // this causes a state machine type to be generated which shouldn't be patched
|
||||
{ yield return 1; }
|
||||
}
|
||||
|
||||
|
@ -78,9 +77,8 @@ namespace NSubstitute.Elevated.Tests
|
|||
[Test]
|
||||
public void PrivateNestedTypes_ShouldNotPatch()
|
||||
{
|
||||
var type = m_FixtureTestAssembly.GetType("ShouldNotPatch.ClassWithPrivateNestedType");
|
||||
var nestedType = type.NestedTypes.Single(t => t.Name == "PrivateNested");
|
||||
MockInjector.IsPatched(nestedType).ShouldBeFalse();
|
||||
var type = m_FixtureTestAssembly.GetType("ShouldNotPatch.ClassWithPrivateNestedType/PrivateNested");
|
||||
MockInjector.IsPatched(type).ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -101,17 +99,15 @@ namespace NSubstitute.Elevated.Tests
|
|||
[Test]
|
||||
public void PublicNestedClasses_ShouldPatch()
|
||||
{
|
||||
var type = m_FixtureTestAssembly.GetType("ShouldPatch.ClassWithNestedTypes");
|
||||
var nestedType = type.NestedTypes.Single(t => t.Name == "PublicNested");
|
||||
MockInjector.IsPatched(nestedType).ShouldBeTrue();
|
||||
var type = m_FixtureTestAssembly.GetType("ShouldPatch.ClassWithNestedTypes/PublicNested");
|
||||
MockInjector.IsPatched(type).ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InternalNestedClasses_ShouldPatch()
|
||||
{
|
||||
var type = m_FixtureTestAssembly.GetType("ShouldPatch.ClassWithNestedTypes");
|
||||
var nestedType = type.NestedTypes.Single(t => t.Name == "InternalNested");
|
||||
MockInjector.IsPatched(nestedType).ShouldBeTrue();
|
||||
var type = m_FixtureTestAssembly.GetType("ShouldPatch.ClassWithNestedTypes/InternalNested");
|
||||
MockInjector.IsPatched(type).ShouldBeTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче