Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Add invocation helpers for (generic) methods (on generic types) #89

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

Banane9
Copy link
Contributor

@Banane9 Banane9 commented Mar 11, 2023

Currently still without documentation, but the first goal would be to have other people look over the API.

And add a proper matcher for GenericTypeMethodsInvoker.GetGenericMethodOfConcreteTypeDefault 😂

@zkxs
Copy link
Collaborator

zkxs commented Mar 11, 2023

Dang, that's more code than I expected. At a glance it doesn't look like any of your classes are public. Not sure if that's the intent?

Anyways, I'll take a more in-depth look a bit later.

Copy link
Member

@ljoonal ljoonal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docs/examples, which IMO makes having these as shared utilities in NML for mods pretty pointless.... Though I guess NML's API doesn't have proper generated docs to begin with, but IDEs usually can at least show the special C# doc comment XML monstrosities...

Overall I can at least say that I wouldn't be able to maintain this code as I have no real idea of what it does, other than some funny dynamic invocations & seemingly caching... Not that that should block it from being merged if others find it useful & understand it ofc

NeosModLoader/NeosModLoader.csproj Outdated Show resolved Hide resolved
NeosModLoader/Utility/GenericTypeMethodsInvoker.cs Outdated Show resolved Hide resolved
NeosModLoader/Utility/GenericTypeMethodsInvoker.cs Outdated Show resolved Hide resolved
NeosModLoader/Utility/GenericTypeMethodsInvoker.cs Outdated Show resolved Hide resolved
@Banane9
Copy link
Contributor Author

Banane9 commented Mar 12, 2023

Missing docs/examples, which IMO makes having these as shared utilities in NML for mods pretty pointless.... Though I guess NML's API doesn't have proper generated docs to begin with, but IDEs usually can at least show the special C# doc comment XML monstrosities...

As I said in the original post, I wanted to get people's feedback on the capabilities / interface before spending time on documenting it extensively. However if you have any questions as to what it does I'd be happy to explain / go on discord

@zkxs
Copy link
Collaborator

zkxs commented Mar 12, 2023

Though I guess NML's API doesn't have proper generated docs to begin with, but IDEs usually can at least show the special C# doc comment XML monstrosities...

takes off C# developer mask
I was actually a Java guy the WHOLE TIME! I've got no idea how to generate fancy docs from the scary XML comments. Also I hate XML and enjoy markdown.

As I said in the original post, I wanted to get people's feedback on the capabilities / interface before spending time on documenting it extensively. However if you have any questions as to what it does I'd be happy to explain / go on discord

I think the most helpful thing here would be an example or two on what a typical usage of this API would look like. No need to go crazy with the scary XML comments yet... especially because I'm pretty sure like 95% of mod devs don't actually know how to see the XML docs in their IDE. At least that's the vibe I get with some of the questions asked on the Discord.

@ljoonal
Copy link
Member

ljoonal commented Mar 12, 2023

especially because I'm pretty sure like 95% of mod devs don't actually know how to see the XML docs in their IDE. At least that's the vibe I get with some of the questions asked on the Discord.

...usually just hovering over the methods should show a popup of the details if the comment is formed correctly.

I've got no idea how to generate fancy docs from the scary XML comments.

There's a few choices, though only one out of these that I've used before is doxygen... DocFX looks more modern though from a quick investigation.

@Banane9
Copy link
Contributor Author

Banane9 commented Mar 12, 2023

I think the most helpful thing here would be an example or two on what a typical usage of this API would look like.

Here's one for the GenericMethodInvoker: https://github.com/Banane9/NeosDynamicVariableLogger/blob/fa0f21ee2cf0c50af83770c47448a54cea2febc9/DynamicVariableLogger/DynamicVariableLogger.cs#L132

I've used it some more in the CustomEntityFramework to help with the invocation of Methods<> on DynamicVariableSpace and while patching DynamicImpulseTriggerWithValue<>, but @KyuubiYoru still need's to set that repo to public.

@Banane9
Copy link
Contributor Author

Banane9 commented Mar 12, 2023

...usually just hovering over the methods should show a popup of the details if the comment is formed correctly.

that only works in the same project, otherwise you need to enable the Documentation file option under Build > Output in the Properties and have it along side the file.
Option in VS

Generating the pdb information (and embedding it?) may also be a helpful idea (for a dev version anyways).

NeosModLoader/Utility/GenericMethodInvoker.cs Outdated Show resolved Hide resolved
NeosModLoader/Utility/GenericMethodInvoker.cs Outdated Show resolved Hide resolved
NeosModLoader/Utility/GenericMethodInvoker.cs Outdated Show resolved Hide resolved
NeosModLoader/Utility/GenericMethodInvoker.cs Outdated Show resolved Hide resolved
NeosModLoader/Utility/GenericMethodInvoker.cs Outdated Show resolved Hide resolved
NeosModLoader/Utility/GenericMethodInvoker.cs Show resolved Hide resolved
NeosModLoader/Utility/GenericTypeMethodsInvoker.cs Outdated Show resolved Hide resolved
NeosModLoader/Utility/TypeDefinition.cs Outdated Show resolved Hide resolved
//if (checkType && hayParameter.ParameterType.FullName != needleParameter.ParameterType.FullName)
// return false;

// TODO: Do a proper type check? lol
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

return InvokeInternal(method, instanceTypes, null, new TypeDefinition(), parameters);
}

private static MethodInfo GetGenericMethodOfConcreteTypeDefault(MethodInfo needleMethod, Type concreteType)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few things I'm confused about.

  1. Wouldn't something like this be equivalent? AccessTools.Method(needleMethod.Name, needleMethod.GetParameters()) Or is there something I'm not seeing?
  2. Needle and Hay are some bonkers variable names. I had a tough time grokking all this code.
  3. If this works consistently then why is there a constructor that lets users pass a custom getGenericMethodOfConcreteType implementation? If this doesn't work consistently then why have it at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Wouldn't something like this be equivalent? AccessTools.Method(needleMethod.Name, needleMethod.GetParameters()) Or is there something I'm not seeing?

I have no idea how that handles instances of the generic parameters of the containing type or the method 🤔

2. Needle and Hay are some bonkers variable names. I had a tough time grokking all this code.

Went with the needle and haystack metaphor for searching something, but I guess it's not super clear in this context lol

3. If this works consistently then why is there a constructor that lets users pass a custom getGenericMethodOfConcreteType implementation? If this doesn't work consistently then why have it at all?

I'm not sure, having the Func is kind of just what I first came up with

@Banane9
Copy link
Contributor Author

Banane9 commented Mar 13, 2023

there you go @ljoonal, I made sure the doc will actually be useful now, too ;)

Comment on lines +12 to +15
/// <summary>
/// Represents a generic method invoker that invokes potentially generic methods on generic types.
/// </summary>
public sealed class GenericTypeMethodsInvoker
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could a short <example><code>, since this seems to be the "entry point" of this utility API? 😜 But yeah at least some docs is better than no docs 👍

@XDelta XDelta added the enhancement New feature or request label Mar 20, 2023
@ljoonal ljoonal requested a review from zkxs March 21, 2023 17:46
@ljoonal ljoonal added the .NET Pull requests that update .net code label Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request .NET Pull requests that update .net code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants