Skip to content

Commit

Permalink
Fixed .NET core build.
Browse files Browse the repository at this point in the history
References #20.
  • Loading branch information
jspuij committed Nov 15, 2019
1 parent b8571b3 commit 6840db3
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 195 deletions.
21 changes: 5 additions & 16 deletions src/Cortex.Net.Fody/ActionWeaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ from m in t.Methods
/// <param name="actionType">The type of the action delegate to invoke.</param>
/// <param name="counterFieldDefinition">The definition of the field that holds the entrance counter.</param>
/// <param name="actionFieldDefinition">The definition of the field that holds the action delegate.</param>
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)
{
Expand Down Expand Up @@ -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++)
{
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
18 changes: 4 additions & 14 deletions src/Cortex.Net.Fody/BlazorObserverWeaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Instruction>
Expand Down
4 changes: 2 additions & 2 deletions src/Cortex.Net.Fody/BlazorWeavingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

/// <summary>
Expand Down
20 changes: 5 additions & 15 deletions src/Cortex.Net.Fody/ComputedWeaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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));

Expand Down
16 changes: 14 additions & 2 deletions src/Cortex.Net.Fody/Cortex.Net.Fody.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 9 additions & 16 deletions src/Cortex.Net.Fody/CortexWeaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,6 @@ namespace Cortex.Net.Fody
/// </summary>
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);
}

/// <summary>
/// Executes the <see cref="CortexWeaver"/>.
/// </summary>
Expand All @@ -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);

Expand All @@ -81,8 +68,14 @@ public override void Execute()
public override IEnumerable<string> 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";
}
}
}
Loading

0 comments on commit 6840db3

Please sign in to comment.