Hello Everyone,
Is there a way to detect the existence of constraint aspect attributes like I tried :
and :
but in both cases I get only |
Hello Mohammed Sameer, I've investigated the case and noticed that in fact, attributes are applied not on Property itself, but on its getter & setter methods, for example:
As a result, the code in your test project simply can't find the attributes:
But the following code will do what you are expecting:
Hope that helps. |
Are you trying to get runtime aspect instance, or just an attribute? They're different:
But, if you're talking precisely about Its intended usage is clear from
This method will work only if target type was already initialized (i.e. its type initializer was already invoked). Type initialization leads to invocation of
Forgot to add: runtime aspect instances must be more attractive, since only these instances are practically usable (i.e. Aspects provided by reflection might be interested only if you need just to study their fields, but not check the constraints. Hmm - just checked, the way with getting regular .NET attribute won't work. Most of our aspects are't decorated with We'll fix this, where this is desirable (e.g. in this case). Thank you very much. Looking forward to seeing it soon :) BTW, ConstraintRegistry.GetConstraints(Type type) does not seem to be internal but it did not solve my issue I believe because the type is not yet initialized as you said. 1
Ok, I have some good news: since the fix was very easy, I included it into the build we planned to publish today (v4.3.5 build 6015). Quick test with reflector shows it works:
I accepted my own answer (hopefully, this is correct). It did not work for me with neither using GetAttribute or ConstraintRegistry. I rejected the acceptance.
What exactly had happened in case with Concerning Try to open the assembly with such attributes with Reflector - you'll see them there. P.S. There is a newer DO4 build now, although it doesn't change anything related to this issue. The steps to reproduce the issue are: 1) Make a new DataObjects Console app. 2) Add [NotNullOrEmptyConstraint] to MyEntity.Text. 3) Add static class with a static method having code: foreach (var type in domain.Model.Types) foreach (var field in type.Fields) { var a1 = field.UnderlyingProperty.GetAttribute<notnulloremptyconstraint>(); if (a1 != null) //always null Console.WriteLine(field.Name); } 4) Call it in Main after domain.Build and remove all sample code below it. How can I send the sample project to you ? You can send it to support@x-tensive.com I have sent it yesterday. Hello guys, any updates ? Did you receive my sample project? Is there something wrong I am doing? Yes, we've got the project, but were pretty busy with other stuff yet. I'm going to study it today. |