Metalama CommunityMC
Metalama Community3y ago
5 replies
Andreu

Override property with BuildAspect

I create exceptions inheriting from Exception and putting the
[BusinessException]
attribute.

I want to override the Message property using string.Format with the primary constructor parameters. For example, the next class:

[BusinessException]
public class UserAlreadyExistsException(int age, string email) : Exception;


I started with
[Introduce]
, but later I noticed I need
BuildAspect
to access constructors. I've tried with this, but I don't know how to do complete the code.

The goal is to have:
string.Format("The user with age {0} and email {1} already exists", age, email);


Code:
https://try.metalama.net/#N4IgZiBcDaoHZRABQE4HsDmKCGBbAdAMYDOIANCIYgK7ECWcGABALICmALtgDZ7b4AxHLjYB3NCgDW+AILEADm0IdiAbgA6cWg2bsuvXPyF4xE6QGE0AEzYat9Rq048+g4aan4AotzoY6AEZ0vhwAnnaacCYK2IRsrKEAMoE4KOGamvLUAb6ETIS8xMRMAELacGxFXgAecfIcdGhwMhwcKIHUHPGQTAAqoYpyisqawJpME0zQAJJwbdbUcQAUAOoAFmxwNXTEKkwAvEwA8gBubCjtNgDKbdhdGKH4p+eXbACUALrjk1k5dHm7dqOdhFbAYNjfCZjOCTWFMcEcSFw6Fw1FME7YFBMLq4eS8LoHJjqEC9DZMWjnJiiOgcNZMMHxYAABgAvvS4FYmGxDMEmMAAIxsngoNjYKyhLnVHYqYl2NFwkUcagoGGAnSCCSGDhLHF4u5sMhEkDEw3E4lvOVollI60wyZI365JhoM4XOg2dFod2lajBKxDJTa6YB5RlP3nAA80wAciYrP1FAA+JgBX3cGwoN5IlFogLYYhsfBh9Mh7Wp8OZiJ21EYrEiUHg1BoRQoMKE8vp874XqYhFI+X4JsthqVftowR0FC7JbVA7J6r4WMiA6HYkg4gM82WmuYpjyTEmLpT9tpjPd3ucMeo-CWOCAxYcCTEK9widT7VZ6vypiDg8iI9qBkX6wmAEiioQdJLLWe5-pwlIMDB7gAZ+8o5t+Kanl2MhWCc-yFrM8xWIsbBDucYRLCh6EYRWsg4XhTyuq8Sz1hujboMOoSGpRqK2rCtosuQICSIgHAgCyHwskAA
Was this page helpful?