Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 5f2fb85

Browse files
committed
CompilerGeneratedAttribute are now resolved via ReferenceFinder
1 parent a248c10 commit 5f2fb85

3 files changed

Lines changed: 10 additions & 13 deletions

File tree

MethodCache.Fody/CecilHelper.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static Instruction AppendStloc(this Instruction instruction, ILProcessor
6363
return instruction.Append(processor.Create(OpCodes.Stloc, index), processor);
6464
}
6565

66-
public static bool ContainsAttribute(this ICustomAttributeProvider methodDefinition, Type attributeType)
66+
public static bool ContainsAttribute(this ICustomAttributeProvider methodDefinition, TypeDefinition attributeType)
6767
{
6868
return methodDefinition.CustomAttributes.Any(x => x.Constructor.DeclaringType.FullName == attributeType.FullName);
6969
}
@@ -128,11 +128,6 @@ public static MethodReference ImportMethod(this ModuleDefinition module, MethodD
128128
return module.Import(methodDefinition);
129129
}
130130

131-
public static TypeReference ImportType(this ModuleDefinition module, Type type)
132-
{
133-
return module.Import(type);
134-
}
135-
136131
public static VariableDefinition ImportVariable(this ModuleDefinition module, TypeReference typeReference)
137132
{
138133
return new VariableDefinition(module.Import(typeReference));

MethodCache.Fody/ModuleWeaver.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,6 @@ private Instruction InjectCacheKeyCreatedCode(MethodDefinition methodDefinition,
228228
if (LogDebugOutput)
229229
{
230230
// Call Debug.WriteLine with CacheKey
231-
TypeReference debug = methodDefinition.Module.TypeReferenceFromCorlib(typeof(Debug).FullName);
232-
233231
current =
234232
current.AppendLdstr(processor, "CacheKey created: {0}")
235233
.AppendLdcI4(processor, 1)
@@ -422,7 +420,7 @@ private bool ShouldWeaveMethod(MethodDefinition method)
422420
bool hasMethodLevelCache = method.ContainsAttribute(CacheAttributeName);
423421
bool hasNoCacheAttribute = method.ContainsAttribute(NoCacheAttributeName);
424422
bool isSpecialName = method.IsSpecialName || method.IsGetter || method.IsSetter || method.IsConstructor;
425-
bool isCompilerGenerated = method.ContainsAttribute(typeof(CompilerGeneratedAttribute));
423+
bool isCompilerGenerated = method.ContainsAttribute(References.CompilerGeneratedAttribute);
426424

427425
if (hasNoCacheAttribute || isSpecialName || isCompilerGenerated)
428426
{
@@ -455,10 +453,10 @@ private bool ShouldWeaveProperty(PropertyDefinition property)
455453
bool hasNoCacheAttribute = property.ContainsAttribute(NoCacheAttributeName);
456454
bool isCacheGetter = property.Name == CacheGetterName;
457455
bool hasGetAccessor = property.GetMethod != null;
458-
bool hasSetAccessor = property.GetMethod != null;
456+
bool hasSetAccessor = property.SetMethod != null;
459457
bool isAutoProperty = hasGetAccessor && hasSetAccessor &&
460-
property.GetMethod.ContainsAttribute(typeof(CompilerGeneratedAttribute)) &&
461-
property.SetMethod.ContainsAttribute(typeof(CompilerGeneratedAttribute));
458+
property.GetMethod.ContainsAttribute(References.CompilerGeneratedAttribute) &&
459+
property.SetMethod.ContainsAttribute(References.CompilerGeneratedAttribute);
462460

463461
if (hasNoCacheAttribute || isCacheGetter || isAutoProperty || !hasGetAccessor)
464462
{
@@ -593,7 +591,7 @@ private void WeaveMethod(MethodDefinition methodDefinition)
593591
return;
594592
}
595593

596-
if (methodDefinition.ReturnType.FullName == methodDefinition.Module.ImportType(typeof(void)).FullName)
594+
if (methodDefinition.ReturnType == methodDefinition.Module.TypeSystem.Void)
597595
{
598596
LogWarning(string.Format("Method {0} returns void. Skip weaving of method {0}.", methodDefinition.Name));
599597

MethodCache.Fody/ReferenceFinder.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class References
1616

1717
public MethodDefinition StringFormatMethod { get; set; }
1818

19+
public TypeDefinition CompilerGeneratedAttribute { get; set; }
20+
1921
public void LoadReferences()
2022
{
2123
var coreTypes = new List<TypeDefinition>();
@@ -39,6 +41,8 @@ public void LoadReferences()
3941
method =>
4042
method.Matches("Format", ModuleDefinition.TypeSystem.String,
4143
new[] { ModuleDefinition.TypeSystem.String, ModuleDefinition.TypeSystem.Object.MakeArrayType() }));
44+
45+
CompilerGeneratedAttribute = coreTypes.First(t => t.Name == "CompilerGeneratedAttribute");
4246
}
4347

4448
private void AppendTypes(string name, List<TypeDefinition> coreTypes)

0 commit comments

Comments
 (0)