diff --git a/src/Cortex.Net.Fody/ActionWeaver.cs b/src/Cortex.Net.Fody/ActionWeaver.cs index 3694ad1..2899aa9 100644 --- a/src/Cortex.Net.Fody/ActionWeaver.cs +++ b/src/Cortex.Net.Fody/ActionWeaver.cs @@ -98,7 +98,7 @@ from m in t.Methods /// The type of the action delegate to invoke. /// The definition of the field that holds the entrance counter. /// The definition of the field that holds the action delegate. - private void ExtendActionMethodBody(MethodDefinition methodDefinition, TypeReference actionType, FieldDefinition counterFieldDefinition, FieldDefinition actionFieldDefinition) + private static void ExtendActionMethodBody(MethodDefinition methodDefinition, TypeReference actionType, FieldDefinition counterFieldDefinition, FieldDefinition actionFieldDefinition) { if (methodDefinition is null) { @@ -157,15 +157,9 @@ private void ExtendActionMethodBody(MethodDefinition methodDefinition, TypeRefer processor.Create(OpCodes.Ldfld, actionFieldDefinition), }; - // workaround for fody bug. - var genericActionDefinition = (actionType is GenericInstanceType) ? - this.parentWeaver.FindStandardType($"System.Action`{(actionType as GenericInstanceType).GenericArguments.Count}") - : this.parentWeaver.FindStandardType("System.Action"); - - var invokeMethod = genericActionDefinition.Methods.Single(x => x.Name == "Invoke"); + var invokeMethod = actionType.Resolve().Methods.Single(x => x.Name == "Invoke"); var invokeReference = invokeMethod.GetGenericMethodOnInstantance(actionType); - // push all function arguments onto the evaluation stack. for (int i = 0; i < methodDefinition.Parameters.Count; i++) { @@ -220,16 +214,11 @@ private void EmitSharedStateSetter( } var actionExtensions = this.weavingContext.CortexNetApiActionExtensions; - var voidType = moduleDefinition.ImportReference(typeof(void)); + var voidType = moduleDefinition.TypeSystem.Void; MethodReference createActionMethod; - // workaround for fody bug. - var genericActionDefinition = (actionType is GenericInstanceType) ? - this.parentWeaver.FindStandardType($"System.Action`{(actionType as GenericInstanceType).GenericArguments.Count}") - : this.parentWeaver.FindStandardType("System.Action"); - - MethodReference actionTypeConstructorReference = genericActionDefinition.Methods.Single(x => x.IsConstructor); + MethodReference actionTypeConstructorReference = actionType.Resolve().Methods.Single(x => x.IsConstructor); actionTypeConstructorReference = actionTypeConstructorReference.GetGenericMethodOnInstantance(actionType); @@ -284,7 +273,7 @@ private void WeaveMethod(MethodDefinition methodDefinition) } // convert the method definition to a corresponding Action<> delegate. - var actionType = methodDefinition.GetActionType(); + var actionType = methodDefinition.GetActionType(this.weavingContext); // add the delegate as field to the class. var actionFieldDefinition = declaringType.CreateField(actionType, $"{InnerActionFieldPrefix}{methodDefinition.Name}_Action", this.weavingContext, fieldAttributes); diff --git a/src/Cortex.Net.Fody/BlazorObserverWeaver.cs b/src/Cortex.Net.Fody/BlazorObserverWeaver.cs index 075d0c7..b42fe85 100644 --- a/src/Cortex.Net.Fody/BlazorObserverWeaver.cs +++ b/src/Cortex.Net.Fody/BlazorObserverWeaver.cs @@ -230,24 +230,14 @@ private void EmitObserverObjectInit(ILProcessor processor, string observerName, var buildRenderTreeReference = module.ImportReference(buildRenderTreeMethod); var stateChangedReference = module.ImportReference(stateChangedMethod); - var renderActionType = buildRenderTreeMethod.GetActionType(); + var renderActionType = buildRenderTreeMethod.GetActionType(this.weavingContext); - // workaround for fody bug. - var genericActionDefinition = (renderActionType is GenericInstanceType) ? - this.parentWeaver.FindStandardType($"System.Action`{(renderActionType as GenericInstanceType).GenericArguments.Count}") - : this.parentWeaver.FindStandardType("System.Action"); - - MethodReference renderActionConstructorType = genericActionDefinition.Methods.Single(x => x.IsConstructor); + MethodReference renderActionConstructorType = renderActionType.Resolve().Methods.Single(x => x.IsConstructor); var renderActionConstructorReference = module.ImportReference(renderActionConstructorType.GetGenericMethodOnInstantance(renderActionType)); - var stateChangedActionType = stateChangedMethod.GetActionType(); - - // workaround for fody bug. - genericActionDefinition = (stateChangedActionType is GenericInstanceType) ? - this.parentWeaver.FindStandardType($"System.Action`{(stateChangedActionType as GenericInstanceType).GenericArguments.Count}") - : this.parentWeaver.FindStandardType("System.Action"); + var stateChangedActionType = stateChangedMethod.GetActionType(this.weavingContext); - MethodReference stateChangedActionConstructorType = genericActionDefinition.Methods.Single(x => x.IsConstructor); + MethodReference stateChangedActionConstructorType = stateChangedActionType.Resolve().Methods.Single(x => x.IsConstructor); var stateChangedActionConstructorReference = module.ImportReference(stateChangedActionConstructorType); var instructions = new List diff --git a/src/Cortex.Net.Fody/BlazorWeavingContext.cs b/src/Cortex.Net.Fody/BlazorWeavingContext.cs index f15308a..ef2c233 100644 --- a/src/Cortex.Net.Fody/BlazorWeavingContext.cs +++ b/src/Cortex.Net.Fody/BlazorWeavingContext.cs @@ -31,8 +31,8 @@ public class BlazorWeavingContext : WeavingContext public BlazorWeavingContext(CortexWeaver moduleWeaver) : base(moduleWeaver) { - this.CortexNetBlazorObserverAttribute = this.TryResolveFromReference(moduleWeaver, "Cortex.Net.Blazor.ObserverAttribute", "Cortex.Net.Blazor"); - this.CortexNetBlazorObserverObject = this.TryResolveFromReference(moduleWeaver, "Cortex.Net.Blazor.ObserverObject", "Cortex.Net.Blazor"); + this.CortexNetBlazorObserverAttribute = TryResolveFromReference(moduleWeaver, "Cortex.Net.Blazor.ObserverAttribute", "Cortex.Net.Blazor"); + this.CortexNetBlazorObserverObject = TryResolveFromReference(moduleWeaver, "Cortex.Net.Blazor.ObserverObject", "Cortex.Net.Blazor"); } /// diff --git a/src/Cortex.Net.Fody/ComputedWeaver.cs b/src/Cortex.Net.Fody/ComputedWeaver.cs index a9d9b1d..1df9e1d 100644 --- a/src/Cortex.Net.Fody/ComputedWeaver.cs +++ b/src/Cortex.Net.Fody/ComputedWeaver.cs @@ -461,18 +461,13 @@ private void EmitComputedMemberAdd( FieldDefinition observableObjectField) { var module = methodDefinition.Module; - var functionType = methodDefinition.GetFunctionType(); + var functionType = methodDefinition.GetFunctionType(this.WeavingContext); var observableObjectType = this.WeavingContext.CortexNetTypesObservableObject.Resolve(); var observableObjectAddComputedMethod = new GenericInstanceMethod(observableObjectType.Methods.FirstOrDefault(m => m.Name == "AddComputedMember")); observableObjectAddComputedMethod.GenericArguments.Add(methodDefinition.ReturnType); - // workaround for fody bug. - var genericActionDefinition = (functionType is GenericInstanceType) ? - this.ParentWeaver.FindStandardType($"System.Func`{(functionType as GenericInstanceType).GenericArguments.Count}") - : this.ParentWeaver.FindStandardType("System.Func"); - - MethodReference functionTypeConstructorReference = genericActionDefinition.Methods.Single(x => x.IsConstructor); + MethodReference functionTypeConstructorReference = functionType.Resolve().Methods.Single(x => x.IsConstructor); functionTypeConstructorReference = module.ImportReference(functionTypeConstructorReference.GetGenericMethodOnInstantance(functionType)); var computedValueOptionsType = this.WeavingContext.CortexNetComputedValueOptions.Resolve(); @@ -528,7 +523,7 @@ private void EmitComputedMemberAdd( var setEqualityComparerMethod = computedValueOptionsType.Methods.Single(x => x.Name == "set_EqualityComparer"); var setEqualityComparerReference = module.ImportReference(setEqualityComparerMethod.GetGenericMethodOnInstantance(computedValueOptionsInstanceType)); MethodReference equalityComparerConstructorReference = equalityComparerType.Resolve().Methods.SingleOrDefault(x => x.IsConstructor && x.Parameters.Count == 0); - + // The equalitycomparer needs to have a parameterless constructor. if (equalityComparerConstructorReference == null) { @@ -557,14 +552,9 @@ private void EmitComputedMemberAdd( { var setSetterMethod = computedValueOptionsType.Methods.Single(x => x.Name == "set_Setter"); var setSetterReference = module.ImportReference(setSetterMethod.GetGenericMethodOnInstantance(computedValueOptionsInstanceType)); - var actionType = setMethodDefinition.GetActionType(); - - // workaround for fody bug. - genericActionDefinition = (actionType is GenericInstanceType) ? - this.ParentWeaver.FindStandardType($"System.Action`{(actionType as GenericInstanceType).GenericArguments.Count}") - : this.ParentWeaver.FindStandardType("System.Action"); + var actionType = setMethodDefinition.GetActionType(this.WeavingContext); - MethodReference actionTypeConstructorReference = genericActionDefinition.Methods.Single(x => x.IsConstructor); + MethodReference actionTypeConstructorReference = actionType.Resolve().Methods.Single(x => x.IsConstructor); actionTypeConstructorReference = module.ImportReference(actionTypeConstructorReference.GetGenericMethodOnInstantance(actionType)); diff --git a/src/Cortex.Net.Fody/Cortex.Net.Fody.xml b/src/Cortex.Net.Fody/Cortex.Net.Fody.xml index 1be4aa2..ec80eb5 100644 --- a/src/Cortex.Net.Fody/Cortex.Net.Fody.xml +++ b/src/Cortex.Net.Fody/Cortex.Net.Fody.xml @@ -359,18 +359,20 @@ The instantiated type. A new method reference. - + Gets the Action type for the private field that is added to the class for the private method. The method definition for the action. + The weaving context. A type reference. - + Gets the Function type for the computed method that is passed. The method definition for the function. + The weaving context. A type reference. @@ -766,6 +768,16 @@ Gets type reference to System.Diagnostics.DebuggerBrowsableAttribute. + + + Gets action type references. + + + + + Gets func type references. + + Tries to resolve a type from a preference. diff --git a/src/Cortex.Net.Fody/CortexWeaver.cs b/src/Cortex.Net.Fody/CortexWeaver.cs index 7b5989c..083c3bc 100644 --- a/src/Cortex.Net.Fody/CortexWeaver.cs +++ b/src/Cortex.Net.Fody/CortexWeaver.cs @@ -30,20 +30,6 @@ namespace Cortex.Net.Fody /// public class CortexWeaver : BaseModuleWeaver { - private string NetStandardReferencePath - { - get - { - var splitReferences = this.References.Split(';'); - return splitReferences.Single(x => Path.GetFileNameWithoutExtension(x) == "netstandard"); - } - } - - internal TypeDefinition FindStandardType(string name) - { - return this.FindType(name); - } - /// /// Executes the . /// @@ -55,9 +41,10 @@ public override void Execute() new WeavingContext(this); var reactiveObjectInterfaceWeaver = new ReactiveObjectInterfaceWeaver(this, weavingContext); - var enumerableWeaver = new EnumerableInterfaceWeaver(this, reactiveObjectInterfaceWeaver, weavingContext); + var actionWeaver = new ActionWeaver(this, reactiveObjectInterfaceWeaver, weavingContext); + var observableWeaver = new ObservableWeaver(this, enumerableWeaver, reactiveObjectInterfaceWeaver, weavingContext); var computedWeaver = new ComputedWeaver(this, reactiveObjectInterfaceWeaver, weavingContext); @@ -81,8 +68,14 @@ public override void Execute() public override IEnumerable GetAssembliesForScanning() { yield return "mscorlib"; + yield return "System"; + yield return "System.Runtime"; + yield return "System.Core"; yield return "netstandard"; - yield return "Microsoft.AspNetCore.Components"; + yield return "System.Collections"; + yield return "System.ObjectModel"; + yield return "System.Threading"; + yield return "FSharp.Core"; } } } diff --git a/src/Cortex.Net.Fody/MethodReferenceExtensions.cs b/src/Cortex.Net.Fody/MethodReferenceExtensions.cs index 43d06c4..158fff9 100644 --- a/src/Cortex.Net.Fody/MethodReferenceExtensions.cs +++ b/src/Cortex.Net.Fody/MethodReferenceExtensions.cs @@ -20,6 +20,7 @@ namespace Cortex.Net.Fody using System.Collections.Generic; using System.Globalization; using System.Linq; + using System.Runtime.CompilerServices; using System.Text; using Cortex.Net.Fody.Properties; using Mono.Cecil; @@ -85,72 +86,33 @@ public static MethodReference GetGenericMethodOnInstantance(this MethodReference /// Gets the Action type for the private field that is added to the class for the private method. /// /// The method definition for the action. + /// The weaving context. /// A type reference. - public static TypeReference GetActionType(this MethodDefinition methodDefinition) + public static TypeReference GetActionType(this MethodDefinition methodDefinition, WeavingContext weavingContext) { if (methodDefinition is null) { throw new ArgumentNullException(nameof(methodDefinition)); } + if (weavingContext is null) + { + throw new ArgumentNullException(nameof(weavingContext)); + } + var moduleDefinition = methodDefinition.Module; if (methodDefinition.Parameters == null || !methodDefinition.Parameters.Any()) { - return moduleDefinition.ImportReference(typeof(Action)); + return moduleDefinition.ImportReference(weavingContext.SystemAction[0]); } TypeReference genericActionType; switch (methodDefinition.Parameters.Count) { - case 1: - genericActionType = moduleDefinition.ImportReference(typeof(Action<>)); - break; - case 2: - genericActionType = moduleDefinition.ImportReference(typeof(Action<,>)); - break; - case 3: - genericActionType = moduleDefinition.ImportReference(typeof(Action<,,>)); - break; - case 4: - genericActionType = moduleDefinition.ImportReference(typeof(Action<,,,>)); - break; - case 5: - genericActionType = moduleDefinition.ImportReference(typeof(Action<,,,,>)); - break; - case 6: - genericActionType = moduleDefinition.ImportReference(typeof(Action<,,,,,>)); - break; - case 7: - genericActionType = moduleDefinition.ImportReference(typeof(Action<,,,,,,>)); - break; - case 8: - genericActionType = moduleDefinition.ImportReference(typeof(Action<,,,,,,,>)); - break; - case 9: - genericActionType = moduleDefinition.ImportReference(typeof(Action<,,,,,,,,>)); - break; - case 10: - genericActionType = moduleDefinition.ImportReference(typeof(Action<,,,,,,,,,>)); - break; - case 11: - genericActionType = moduleDefinition.ImportReference(typeof(Action<,,,,,,,,,,>)); - break; - case 12: - genericActionType = moduleDefinition.ImportReference(typeof(Action<,,,,,,,,,,,>)); - break; - case 13: - genericActionType = moduleDefinition.ImportReference(typeof(Action<,,,,,,,,,,,,>)); - break; - case 14: - genericActionType = moduleDefinition.ImportReference(typeof(Action<,,,,,,,,,,,,,>)); - break; - case 15: - genericActionType = moduleDefinition.ImportReference(typeof(Action<,,,,,,,,,,,,,,>)); - break; - case 16: - genericActionType = moduleDefinition.ImportReference(typeof(Action<,,,,,,,,,,,,,,,>)); + case int i when i > 0 && i <= 16: + genericActionType = moduleDefinition.ImportReference(weavingContext.SystemAction[i]); break; default: throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.MoreThan16Parameters, methodDefinition.Name)); @@ -170,70 +132,28 @@ public static TypeReference GetActionType(this MethodDefinition methodDefinition /// Gets the Function type for the computed method that is passed. /// /// The method definition for the function. + /// The weaving context. /// A type reference. - public static TypeReference GetFunctionType(this MethodDefinition methodDefinition) + public static TypeReference GetFunctionType(this MethodDefinition methodDefinition, WeavingContext weavingContext) { if (methodDefinition is null) { throw new ArgumentNullException(nameof(methodDefinition)); } + if (weavingContext is null) + { + throw new ArgumentNullException(nameof(weavingContext)); + } + var moduleDefinition = methodDefinition.Module; TypeReference genericFunctionType; switch (methodDefinition.Parameters.Count) { - case 0: - genericFunctionType = moduleDefinition.ImportReference(typeof(Func<>)); - break; - case 1: - genericFunctionType = moduleDefinition.ImportReference(typeof(Func<,>)); - break; - case 2: - genericFunctionType = moduleDefinition.ImportReference(typeof(Func<,,>)); - break; - case 3: - genericFunctionType = moduleDefinition.ImportReference(typeof(Func<,,,>)); - break; - case 4: - genericFunctionType = moduleDefinition.ImportReference(typeof(Func<,,,,>)); - break; - case 5: - genericFunctionType = moduleDefinition.ImportReference(typeof(Func<,,,,,>)); - break; - case 6: - genericFunctionType = moduleDefinition.ImportReference(typeof(Func<,,,,,,>)); - break; - case 7: - genericFunctionType = moduleDefinition.ImportReference(typeof(Func<,,,,,,,>)); - break; - case 8: - genericFunctionType = moduleDefinition.ImportReference(typeof(Func<,,,,,,,,>)); - break; - case 9: - genericFunctionType = moduleDefinition.ImportReference(typeof(Func<,,,,,,,,,>)); - break; - case 10: - genericFunctionType = moduleDefinition.ImportReference(typeof(Func<,,,,,,,,,,>)); - break; - case 11: - genericFunctionType = moduleDefinition.ImportReference(typeof(Func<,,,,,,,,,,,>)); - break; - case 12: - genericFunctionType = moduleDefinition.ImportReference(typeof(Func<,,,,,,,,,,,,>)); - break; - case 13: - genericFunctionType = moduleDefinition.ImportReference(typeof(Func<,,,,,,,,,,,,,>)); - break; - case 14: - genericFunctionType = moduleDefinition.ImportReference(typeof(Func<,,,,,,,,,,,,,,>)); - break; - case 15: - genericFunctionType = moduleDefinition.ImportReference(typeof(Func<,,,,,,,,,,,,,,,>)); - break; - case 16: - genericFunctionType = moduleDefinition.ImportReference(typeof(Func<,,,,,,,,,,,,,,,,>)); + case int i when i >= 0 && i <= 16: + genericFunctionType = moduleDefinition.ImportReference(weavingContext.SystemFunc[i]); break; default: throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.MoreThan16Parameters, methodDefinition.Name)); diff --git a/src/Cortex.Net.Fody/TypeDefinitionExtenions.cs b/src/Cortex.Net.Fody/TypeDefinitionExtenions.cs index 5684ce0..fd3dde0 100644 --- a/src/Cortex.Net.Fody/TypeDefinitionExtenions.cs +++ b/src/Cortex.Net.Fody/TypeDefinitionExtenions.cs @@ -191,7 +191,7 @@ public static MethodDefinition CreateDefaultSetter( var moduleDefinition = classType.Module; - var voidType = moduleDefinition.ImportReference(typeof(void)); + var voidType = moduleDefinition.TypeSystem.Void; var splittedName = name.Split('.'); diff --git a/src/Cortex.Net.Fody/WeavingContext.cs b/src/Cortex.Net.Fody/WeavingContext.cs index 1e6eb55..1c9620e 100644 --- a/src/Cortex.Net.Fody/WeavingContext.cs +++ b/src/Cortex.Net.Fody/WeavingContext.cs @@ -16,6 +16,7 @@ namespace Cortex.Net.Fody { + using System.Collections.Generic; using System.Globalization; using System.Linq; using Cortex.Net.Fody.Properties; @@ -33,85 +34,97 @@ public class WeavingContext /// Moduleweaver to use. public WeavingContext(CortexWeaver moduleWeaver) { - this.CortexNetISharedState = this.TryResolveFromReference(moduleWeaver, "Cortex.Net.ISharedState", "Cortex.Net"); - this.CortexNetApiActionAttribute = this.TryResolveFromReference(moduleWeaver, "Cortex.Net.Api.ActionAttribute", "Cortex.Net"); - this.CortexNetIReactiveObject = this.TryResolveFromReference(moduleWeaver, "Cortex.Net.IReactiveObject", "Cortex.Net"); - this.CortexNetApiActionExtensions = this.TryResolveFromReference(moduleWeaver, "Cortex.Net.Api.ActionExtensions", "Cortex.Net"); - this.CortexNetApiComputedAttribute = this.TryResolveFromReference(moduleWeaver, "Cortex.Net.Api.ComputedAttribute", "Cortex.Net"); - this.CortexNetTypesDeepEnhancer = this.TryResolveFromReference(moduleWeaver, "Cortex.Net.Types.DeepEnhancer", "Cortex.Net"); - this.CortexNetTypesObservableObject = this.TryResolveFromReference(moduleWeaver, "Cortex.Net.Types.ObservableObject", "Cortex.Net"); - this.CortexNetComputedValueOptions = this.TryResolveFromReference(moduleWeaver, "Cortex.Net.ComputedValueOptions`1", "Cortex.Net"); - this.CortexNetTypesObservableCollection = this.TryResolveFromReference(moduleWeaver, "Cortex.Net.Types.ObservableCollection`1", "Cortex.Net"); - this.CortexNetApiObservableAttribute = this.TryResolveFromReference(moduleWeaver, "Cortex.Net.Api.ObservableAttribute", "Cortex.Net"); - this.CortexNetCoreActionExtensions = this.TryResolveFromReference(moduleWeaver, "Cortex.Net.Core.ActionExtensions", "Cortex.Net"); - this.SystemRuntimeCompilerServicesCompilerGeneratedAttribute = this.TryResolveFromScannedAssemblies(moduleWeaver, "System.Runtime.CompilerServices.CompilerGeneratedAttribute"); - this.SystemDiagnosticsDebuggerBrowsableAttribute = this.TryResolveFromScannedAssemblies(moduleWeaver, "System.Diagnostics.DebuggerBrowsableAttribute"); + this.CortexNetISharedState = TryResolveFromReference(moduleWeaver, "Cortex.Net.ISharedState", "Cortex.Net"); + this.CortexNetApiActionAttribute = TryResolveFromReference(moduleWeaver, "Cortex.Net.Api.ActionAttribute", "Cortex.Net"); + this.CortexNetIReactiveObject = TryResolveFromReference(moduleWeaver, "Cortex.Net.IReactiveObject", "Cortex.Net"); + this.CortexNetApiActionExtensions = TryResolveFromReference(moduleWeaver, "Cortex.Net.Api.ActionExtensions", "Cortex.Net"); + this.CortexNetApiComputedAttribute = TryResolveFromReference(moduleWeaver, "Cortex.Net.Api.ComputedAttribute", "Cortex.Net"); + this.CortexNetTypesDeepEnhancer = TryResolveFromReference(moduleWeaver, "Cortex.Net.Types.DeepEnhancer", "Cortex.Net"); + this.CortexNetTypesObservableObject = TryResolveFromReference(moduleWeaver, "Cortex.Net.Types.ObservableObject", "Cortex.Net"); + this.CortexNetComputedValueOptions = TryResolveFromReference(moduleWeaver, "Cortex.Net.ComputedValueOptions`1", "Cortex.Net"); + this.CortexNetTypesObservableCollection = TryResolveFromReference(moduleWeaver, "Cortex.Net.Types.ObservableCollection`1", "Cortex.Net"); + this.CortexNetApiObservableAttribute = TryResolveFromReference(moduleWeaver, "Cortex.Net.Api.ObservableAttribute", "Cortex.Net"); + this.CortexNetCoreActionExtensions = TryResolveFromReference(moduleWeaver, "Cortex.Net.Core.ActionExtensions", "Cortex.Net"); + this.SystemRuntimeCompilerServicesCompilerGeneratedAttribute = TryResolveFromScannedAssemblies(moduleWeaver, "System.Runtime.CompilerServices.CompilerGeneratedAttribute"); + this.SystemDiagnosticsDebuggerBrowsableAttribute = TryResolveFromScannedAssemblies(moduleWeaver, "System.Diagnostics.DebuggerBrowsableAttribute"); + this.SystemAction = Enumerable.Range(0, 16).Select(x => TryResolveFromScannedAssemblies(moduleWeaver, x == 0 ? "System.Action" : $"System.Action`{x}")).ToList().AsReadOnly(); + this.SystemFunc = Enumerable.Range(0, 16).Select(x => TryResolveFromScannedAssemblies(moduleWeaver, $"System.Func`{x + 1}")).ToList().AsReadOnly(); } /// /// Gets type reference to Cortex.Net.ISharedState. /// - internal TypeReference CortexNetISharedState { get; private set; } + public TypeReference CortexNetISharedState { get; private set; } /// /// Gets type reference to Cortex.Net.Api.ActionAttribute. /// - internal TypeReference CortexNetApiActionAttribute { get; private set; } + public TypeReference CortexNetApiActionAttribute { get; private set; } /// /// Gets type reference to Cortex.Net.IReactiveObject. /// - internal TypeReference CortexNetIReactiveObject { get; private set; } + public TypeReference CortexNetIReactiveObject { get; private set; } /// /// Gets type reference to Cortex.Net.Api.ActionExtensions. /// - internal TypeReference CortexNetApiActionExtensions { get; private set; } + public TypeReference CortexNetApiActionExtensions { get; private set; } /// /// Gets type reference to Cortex.Net.Api.ComputedAttribute. /// - internal TypeReference CortexNetApiComputedAttribute { get; private set; } + public TypeReference CortexNetApiComputedAttribute { get; private set; } /// /// Gets type reference to Cortex.Net.Types.DeepEnhancer. /// - internal TypeReference CortexNetTypesDeepEnhancer { get; private set; } + public TypeReference CortexNetTypesDeepEnhancer { get; private set; } /// /// Gets type reference to Cortex.Net.Types.ObservableObject. /// - internal TypeReference CortexNetTypesObservableObject { get; private set; } + public TypeReference CortexNetTypesObservableObject { get; private set; } /// /// Gets type reference to Cortex.Net.ComputedValueOptions`1. /// - internal TypeReference CortexNetComputedValueOptions { get; private set; } + public TypeReference CortexNetComputedValueOptions { get; private set; } /// /// Gets type reference to Cortex.Net.Types.ObservableCollection`1. /// - internal TypeReference CortexNetTypesObservableCollection { get; private set; } + public TypeReference CortexNetTypesObservableCollection { get; private set; } /// /// Gets type reference to Cortex.Net.Api.ObservableAttribute. /// - internal TypeReference CortexNetApiObservableAttribute { get; private set; } + public TypeReference CortexNetApiObservableAttribute { get; private set; } /// /// Gets type reference to Cortex.Net.Core.ActionExtensions. /// - internal TypeReference CortexNetCoreActionExtensions { get; private set; } + public TypeReference CortexNetCoreActionExtensions { get; private set; } /// /// Gets type reference to System.Runtime.CompilerServices.CompilerGeneratedAttribute. /// - internal TypeReference SystemRuntimeCompilerServicesCompilerGeneratedAttribute { get; private set; } + public TypeReference SystemRuntimeCompilerServicesCompilerGeneratedAttribute { get; private set; } /// /// Gets type reference to System.Diagnostics.DebuggerBrowsableAttribute. /// - internal TypeReference SystemDiagnosticsDebuggerBrowsableAttribute { get; private set; } + public TypeReference SystemDiagnosticsDebuggerBrowsableAttribute { get; private set; } + + /// + /// Gets action type references. + /// + public IReadOnlyList SystemAction { get; } + + /// + /// Gets func type references. + /// + public IReadOnlyList SystemFunc { get; } /// /// Tries to resolve a type from a preference. @@ -120,8 +133,13 @@ public WeavingContext(CortexWeaver moduleWeaver) /// The fullname of the type. /// The assembly name. /// A type reference. - protected TypeReference TryResolveFromReference(CortexWeaver moduleWeaver, string fullName, string assemblyName) + protected static TypeReference TryResolveFromReference(CortexWeaver moduleWeaver, string fullName, string assemblyName) { + if (moduleWeaver is null) + { + throw new System.ArgumentNullException(nameof(moduleWeaver)); + } + try { var assembly = moduleWeaver.ModuleDefinition.AssemblyResolver.Resolve(moduleWeaver.ModuleDefinition.AssemblyReferences.FirstOrDefault(asm => asm.Name == assemblyName)); @@ -129,6 +147,7 @@ protected TypeReference TryResolveFromReference(CortexWeaver moduleWeaver, strin } catch { + throw; throw new WeavingException(string.Format(CultureInfo.CurrentCulture, Resources.AssemblyOrTypeNotFound, fullName)); } } @@ -139,11 +158,18 @@ protected TypeReference TryResolveFromReference(CortexWeaver moduleWeaver, strin /// The module weaver to use. /// The fullname of the type. /// A type reference. - protected TypeReference TryResolveFromScannedAssemblies(CortexWeaver moduleWeaver, string fullName) + protected static TypeReference TryResolveFromScannedAssemblies(CortexWeaver moduleWeaver, string fullName) { + if (moduleWeaver is null) + { + throw new System.ArgumentNullException(nameof(moduleWeaver)); + } + try { - return moduleWeaver.ModuleDefinition.ImportReference(moduleWeaver.FindStandardType(fullName)); + var type = moduleWeaver.FindType(fullName); + var result = moduleWeaver.ModuleDefinition.ImportReference(type); + return result; } catch {