Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotations to mark FromDoc, PostDoc? #52

Open
grahamboree opened this issue May 30, 2023 · 0 comments
Open

Annotations to mark FromDoc, PostDoc? #52

grahamboree opened this issue May 30, 2023 · 0 comments
Labels
📈enhancement A useful improvement or extension to existing behavior 💡 idea

Comments

@grahamboree
Copy link
Contributor

There may be cases where a user wants to use DarkConfig on a type that already has static methods named PostDoc or FromDoc. This would cause issues with DarkConfig's method name reflection-based search, and would require the client code to rename the existing methods to avoid a conflict. This is significantly less likely if we're checking the argument types, since one argument type must be DarkConfig.DocNode, but it's still possible.

Instead, the more canonical approach is likely to mark those special functions with annotations:

class Sample {
  int foo = 42;
  
  [DarkConfig.PostDoc]
  public static Sample PostDoc(Sample sample) {
    sample.foo = 99;
    return sample;
  }
  
  [DarkConfig.FromDoc]
  public static Sample FromDoc(Sample sample, DarkConfig.DocNode doc) {
    return new Sample { foo = doc.As<int>(); };
  }
}
@grahamboree grahamboree added 📈enhancement A useful improvement or extension to existing behavior ❓question 💡 idea and removed ❓question labels May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📈enhancement A useful improvement or extension to existing behavior 💡 idea
Projects
None yet
Development

No branches or pull requests

1 participant