ICustomAttributesProvider patch

853 views
Skip to first unread message

vitalya

unread,
Sep 29, 2009, 1:16:23 PM9/29/09
to AutoMapper-users
Hello,

We're going to use AutoMapper to map our model entities to DTO's, but
faced a problem with translating validation rules defined on the
entity with Castle.Validator attributes. To perform such transition we
should be able to get custom attributes from source property. The
possible solution for this is to inherit IMemberGetter interface from
ICustomAttributesProvider. It seems to be a nice feature, so i've
uploaded a patch to group files.

member_getter_implements_i_custom_attribute_provider.patch

What do you think about this?

Thanks in advance

Jimmy Bogard

unread,
Oct 18, 2009, 6:40:30 PM10/18/09
to automapp...@googlegroups.com
Hi Vitalya,

It looks interesting, but I can't figure out what adding this information to the IMemberGetter will do for anyone.  How would this help with the Castle.Validator issue?

vitalya

unread,
Oct 23, 2009, 3:27:13 AM10/23/09
to AutoMapper-users
Hi Jimmy,

To build our views we're using strongly typed helpers that accept
lambda expressions for Dto properties. For example we have the
following model:
public class Person
{
[ValidateNonEmpty]
public string FirstName {get;set;}
}
public class PersonDto : IDto<Person>
{
public string FirstName {get;set;}
}

In the view the helper looks like this:
Html<PersonDto>.TextboxWitValidationFor(p => p.FirstName)

So our helper needs somehow to access original properties to get
original validation attributes. From IDto<> interface we know original
type, but we don't know from which property validation definition
should be taken. I've already implemented this via reflection:
IValueResolver modelPropertyAccessor = GetModelPropertyAccessor
(dtoType, dtoPropertyName);
return ReflectionHelper
.GetFieldValue<PropertyInfo>(modelPropertyAccessor, "_propertyInfo")
.GetCustomAttributes(typeof(AbstractValidationAttribute), true)
.Cast<AbstractValidationAttribute>();

But having this in API seems to be more natural, so i've provided a
patch.

Hopefully it makes sense

On Oct 19, 1:40 am, Jimmy Bogard <jimmy.bog...@gmail.com> wrote:
> Hi Vitalya,
>
> It looks interesting, but I can't figure out what adding this information to
> the IMemberGetter will do for anyone.  How would this help with the
> Castle.Validator issue?
>

Jimmy Bogard

unread,
Oct 29, 2009, 10:25:18 PM10/29/09
to automapp...@googlegroups.com
Ah yes, that makes more sense.  Thanks for the explanation!

Jimmy Bogard

unread,
Nov 26, 2009, 11:57:36 AM11/26/09
to automapp...@googlegroups.com
I finally got this one in, in R142.  Thanks for the patch!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AutoMapper-users" group.
To post to this group, send email to automapp...@googlegroups.com
To unsubscribe from this group, send email to automapper-use...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/automapper-users?hl=en
-~----------~----~----~----~------~----~------~--~---



maverick su

unread,
Jun 20, 2013, 11:16:09 AM6/20/13
to automapp...@googlegroups.com
Hi,

Just wondering where can I obtain the member_getter_implements_i_custom_attribute_provider.patch file?

Thanks in advance

Jimmy Bogard

unread,
Aug 23, 2013, 6:14:05 PM8/23/13
to automapper-users
Man i've looked everywhere. That was 4 years ago, I think it's gone :(


--
You received this message because you are subscribed to the Google Groups "AutoMapper-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to automapper-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages