Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
beyaz committed Feb 10, 2024
1 parent f92dd67 commit befd904
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
8 changes: 5 additions & 3 deletions ReactWithDotNet/ElementSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -596,14 +596,16 @@ static async Task<object> GetPropertyValueOfHtmlElement(ElementSerializerContext
throw HandlerMethodShouldBelongToReactComponent(propertyDefinition.name, handlerDelegateTarget);
}

var handlerMethod = handlerDelegate.Method.GetCalculated();

var remoteMethodInfo = new RemoteMethodInfo
{
IsRemoteMethod = true,
remoteMethodName = handlerDelegate.Method.GetNameWithToken(),
remoteMethodName = handlerMethod.NameWithToken,
HandlerComponentUniqueIdentifier = handlerComponentUniqueIdentifier,
FunctionNameOfGrabEventArguments = propertyDefinition.GrabEventArgumentsByUsingFunction,
StopPropagation = handlerDelegate.Method.GetCustomAttributes<ReactStopPropagationAttribute>().Any(),
KeyboardEventCallOnly = handlerDelegate.Method.GetCustomAttributes<ReactKeyboardEventCallOnlyAttribute>().FirstOrDefault()?.Keys
StopPropagation = handlerMethod.HasStopPropagationAttribute,
KeyboardEventCallOnly = handlerMethod.KeyboardEventCallOnlyAttribute
};
if (propertyDefinition.isScrollEvent)
{
Expand Down
47 changes: 35 additions & 12 deletions ReactWithDotNet/ReflectionCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ public static MethodInfoNode Cached(this MethodInfo methodInfo)

if (!assemblyNode.Methods.TryGetValue(new(methodInfo), out var node))
{
node = new(methodInfo);

node.Initialize();
node = new(methodInfo)
{
Calculated = MethodInfoCalculated.From(methodInfo)
};

assemblyNode.Methods.Add(node);
}
Expand Down Expand Up @@ -44,16 +45,9 @@ public MethodInfoNode(MethodInfo methodInfo)
_methodInfo = methodInfo;
}

public bool HasStopPropagationAttribute { get; private set; }
public IReadOnlyList<string> KeyboardEventCallOnlyAttribute { get; private set; }
public string NameWithToken { get; private set; }
public MethodInfoCalculated Calculated { get; set; }

public void Initialize()
{
HasStopPropagationAttribute = _methodInfo.GetCustomAttributes<ReactStopPropagationAttribute>().Any();
KeyboardEventCallOnlyAttribute = _methodInfo.GetCustomAttributes<ReactKeyboardEventCallOnlyAttribute>().FirstOrDefault()?.Keys;
NameWithToken = _methodInfo.GetNameWithToken();
}


class Comparer : IComparer<MethodInfoNode>
{
Expand All @@ -73,4 +67,33 @@ class AssemblyNode
{
public readonly SortedSet<MethodInfoNode> Methods = new(MethodInfoNode.ComparerInstance);
}
}

sealed class MethodInfoCalculated
{
// todo: cache more accessed values

public required MethodInfo MethodInfo { get; init; }
public required bool HasStopPropagationAttribute { get; init; }
public required IReadOnlyList<string> KeyboardEventCallOnlyAttribute { get; init; }
public required string NameWithToken { get; init; }

public static MethodInfoCalculated From(MethodInfo methodInfo)
{
return new()
{
MethodInfo = methodInfo,
HasStopPropagationAttribute = methodInfo.GetCustomAttributes<ReactStopPropagationAttribute>().Any(),
KeyboardEventCallOnlyAttribute = methodInfo.GetCustomAttributes<ReactKeyboardEventCallOnlyAttribute>().FirstOrDefault()?.Keys,
NameWithToken = methodInfo.GetNameWithToken(),
};
}
}

partial class Mixin
{
internal static MethodInfoCalculated GetCalculated(this MethodInfo methodInfo)
{
return methodInfo.Cached().Calculated;
}
}

0 comments on commit befd904

Please sign in to comment.