Skip to content

Commit 378ddb3

Browse files
author
reflection-emit
committed
Issues with Factory in net core fixed
1 parent 24ceda0 commit 378ddb3

File tree

159 files changed

+1394
-264
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+1394
-264
lines changed

Cauldron.sln

+261-83
Large diffs are not rendered by default.

Fody/Cauldron.Interception.Cecilator/BuilderType.cs

+11-10
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,14 @@ public bool IsInternal
116116
}
117117
}
118118

119+
public bool IsNested => this.typeDefinition.Attributes.HasFlag(TypeAttributes.NestedFamily) ||
120+
this.typeDefinition.Attributes.HasFlag(TypeAttributes.NestedAssembly) ||
121+
this.typeDefinition.Attributes.HasFlag(TypeAttributes.NestedPrivate) ||
122+
this.typeDefinition.Attributes.HasFlag(TypeAttributes.NestedPublic);
123+
119124
public bool IsNestedFamily => this.typeDefinition.Attributes.HasFlag(TypeAttributes.NestedFamily);
120125

126+
public bool IsNestedPrivate => this.typeDefinition.Attributes.HasFlag(TypeAttributes.NestedPrivate);
121127
public bool IsNestedPublic => this.typeDefinition.Attributes.HasFlag(TypeAttributes.NestedPublic);
122128

123129
public bool IsNullable => this.typeDefinition.AreEqual(BuilderTypes.Nullable1.BuilderType.typeDefinition);
@@ -126,6 +132,7 @@ public bool IsInternal
126132

127133
public bool IsPublic => this.typeDefinition.Attributes.HasFlag(TypeAttributes.Public) && !this.IsNestedPrivate;
128134

135+
public bool IsSealed => this.typeDefinition.Attributes.HasFlag(TypeAttributes.Sealed);
129136
public bool IsStatic => this.IsAbstract && this.IsSealed;
130137

131138
public bool IsVoid => this.typeDefinition.FullName == "System.Void";
@@ -170,15 +177,7 @@ public string Namespace
170177
public bool IsGenericInstance => this.typeReference.IsGenericInstance;
171178

172179
public bool IsGenericParameter => this.typeReference.IsGenericParameter;
173-
174-
public bool IsNested => this.typeDefinition.Attributes.HasFlag(TypeAttributes.NestedFamily) ||
175-
this.typeDefinition.Attributes.HasFlag(TypeAttributes.NestedAssembly) ||
176-
this.typeDefinition.Attributes.HasFlag(TypeAttributes.NestedPrivate) ||
177-
this.typeDefinition.Attributes.HasFlag(TypeAttributes.NestedPublic);
178-
179-
public bool IsNestedPrivate => this.typeDefinition.Attributes.HasFlag(TypeAttributes.NestedPrivate);
180180
public bool IsPrimitive => this.typeDefinition?.IsPrimitive ?? this.typeReference?.IsPrimitive ?? false;
181-
public bool IsSealed => this.typeDefinition.Attributes.HasFlag(TypeAttributes.Sealed);
182181
public bool IsUsed => InstructionBucket.IsUsed(this.typeReference);
183182

184183
public bool IsValueType => this.typeDefinition == null ? this.typeReference == null ? false : this.typeReference.IsValueType : this.typeDefinition.IsValueType;
@@ -236,13 +235,15 @@ public bool Implements(BuilderType builderType, bool getAll = true)
236235

237236
public BuilderType Import()
238237
{
238+
var type = this.typeReference ?? this.typeDefinition;
239+
239240
try
240241
{
241-
return new BuilderType(this.Builder, this.moduleDefinition.ImportReference(this.typeReference ?? this.typeDefinition) ?? throw new ArgumentNullException("Unable to resolve."));
242+
return new BuilderType(this.Builder, this.moduleDefinition.ImportReference(type) ?? throw new ArgumentNullException("Unable to resolve."));
242243
}
243244
catch (Exception e)
244245
{
245-
throw new Exception($"An error has occured while trying to import the type '{this.Fullname}'", e);
246+
throw new Exception($"An error has occured while trying to import the type '{type.FullName}'", e);
246247
}
247248
}
248249

Fody/Cauldron.Interception.Cecilator/Extension.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,14 @@ TypeReference getIEnumerableInterfaceChild(TypeReference typeReference)
459459
var result = getIEnumerableInterfaceChild(type);
460460

461461
if (result != null)
462-
return (module.ImportReference(result), true);
462+
try
463+
{
464+
return (module.ImportReference(result), true);
465+
}
466+
catch (Exception e)
467+
{
468+
throw new Exception($"An error has occured while trying to import the type '{result.FullName}'", e);
469+
}
463470

464471
// We just don't know :(
465472
return (module.ImportReference(typeof(object)), false);

Fody/Cauldron.Interception.Cecilator/WeaverBase.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace Cauldron.Interception.Cecilator
1414
/// <exclude/>
1515
public abstract class WeaverBase : BaseModuleWeaver, ICecilatorObject
1616
{
17+
private IAssemblyResolver resolver = new DotNetCoreAssemblyResolver();
18+
1719
[EditorBrowsable(EditorBrowsableState.Never), DebuggerBrowsable(DebuggerBrowsableState.Never)]
1820
public static IEnumerable<TypeDefinition> AllTypes { get; internal set; }
1921

@@ -128,7 +130,11 @@ public IEnumerable<AssemblyDefinition> GetAllReferencedAssemblies(IEnumerable<As
128130
/// <exclude/>
129131
public override IEnumerable<string> GetAssembliesForScanning()
130132
{
131-
yield break;
133+
yield return "netstandard";
134+
yield return "mscorlib";
135+
yield return "System";
136+
yield return "System.Runtime";
137+
yield return "System.Core";
132138
}
133139

134140
/// <summary>
Binary file not shown.
Binary file not shown.
Binary file not shown.

NetStandard/Cauldron.Activator/Assemblies.cs

+20-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.IO;
55
using System.Linq;
66
using System.Reflection;
7-
using System.Threading.Tasks;
87

98
namespace Cauldron.Reflection
109
{
@@ -63,17 +62,32 @@ public static void LoadAssemblies(DirectoryInfo directory, string filter = "*.dl
6362

6463
private static void GetAllAssemblies()
6564
{
66-
AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += ResolveAssembly;
67-
AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly;
65+
void addAssemblies()
66+
{
67+
for (int i = 0; i < AssembliesCore._referencedAssemblies.Length; i++)
68+
AddAssembly(AssembliesCore._referencedAssemblies[i], false);
69+
}
6870

6971
AddAssembly(EntryAssembly, false);
7072

7173
if (AssembliesCore._referencedAssemblies == null)
7274
{
75+
var cauldronHelper = EntryAssembly.GetType("CauldronInterceptionHelper")?.GetMethod("GetReferencedAssemblies", BindingFlags.Public | BindingFlags.Static);
76+
77+
if (cauldronHelper != null)
78+
{
79+
if (cauldronHelper.Invoke(null, null) is Assembly[] refAssemblies && refAssemblies.Length > 0)
80+
{
81+
AssembliesCore._referencedAssemblies = refAssemblies;
82+
addAssemblies();
83+
return;
84+
}
85+
}
86+
7387
var assemblies = new List<Assembly>();
7488
var allAssemblies = AppDomain.CurrentDomain.GetAssemblies();
7589

76-
Parallel.For(0, allAssemblies.Length, i =>
90+
for (int i = 0; i < allAssemblies.Length; i++)
7791
{
7892
var assembly = allAssemblies[i];
7993
if (AddAssembly(assembly, false) != null)
@@ -82,13 +96,12 @@ private static void GetAllAssemblies()
8296
for (int c = 0; c < referencedAssemblies.Length; c++)
8397
LoadAssembly(referencedAssemblies[c]);
8498
}
85-
});
99+
};
86100

87101
return;
88102
}
89103

90-
for (int i = 0; i < AssembliesCore._referencedAssemblies.Length; i++)
91-
AddAssembly(AssembliesCore._referencedAssemblies[i], false);
104+
addAssemblies();
92105
}
93106

94107
private static Assembly ResolveAssembly(object sender, ResolveEventArgs e)

Shared/Cauldron.Activator/Factory.cs

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ static Factory()
3939
};
4040
}
4141

42+
/// <exclude/>
43+
[EditorBrowsable(EditorBrowsableState.Never)]
44+
public static void Rebuild() => InitializeFactory();
45+
4246
/// <summary>
4347
/// Occures if an object was created. This will only be invoked if the created object has set its <see cref="ComponentAttribute.InvokeOnObjectCreationEvent"/> to true.
4448
/// </summary>

0 commit comments

Comments
 (0)