Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4623894
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:03:11+00:00 2026-05-22T03:03:11+00:00

I have a formatter public class ColorFormatter : IValueFormatter { public string FormatValue(ResolutionContext context)

  • 0

I have a formatter

    public class ColorFormatter : IValueFormatter
    {
        public string FormatValue(ResolutionContext context)
        {
            return "green"
        }
    }

Mapper.CreateMap<MyClass, MyViewModel>().ForMember(dest => dest.color, opt => opt.AddFormatter<ColorFormatter>());

MyClass has nothing called bgColor but MyViewModel does and I want all of the bgColors to have “green”.

So why is it not being triggered?

Everything else in MYClass gets successfully mapped to MyViewModel.

List<MyViewModel> vm = Mapper.Map<List<MyClass>, List<MyViewModel>>(myClasses);

[Serializable]
    public class MyClass
    {
        public virtual int Id { get; private set; }
        public virtual string Title { get; set; }
        public virtual DateTime Start { get; set; }
        public virtual DateTime End { get; set; }
        public virtual string Description { get; set; }
        public virtual string Where { get; set; }
        public virtual bool AllDay { get; set; }
        public virtual AnotherClass AnotherClass { get; set; }
        public virtual int RepeatingId { get; set; }
    }


     public class MyViewModel
    {
        public int id { get; set; }
        public string title { get; set; }
        public bool allDay { get; set; }
        public string start { get; set; }
        public string end { get; set; }
        public string color { get; set; }
        public string appointmentId { get; set; }
        public string textColor { get; set; }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:03:12+00:00Added an answer on May 22, 2026 at 3:03 am

    The ValueFormatter is only applied when it has a source value to format. If you add a Color property onto the MyClass class then you will see the color “green” get applied. I’m not sure if this is an AutoMapper bug as it would normally complain if there is no source value to map from. I’m guessing that it assumes when you apply .ForMember() then it can no longer automatically check these things and it is relying on you to ensure that the mapping is correct. Rather than using a ValueFormatter, use a ValueResolver that returns a string like this:

    Mapper.CreateMap<MyClass, MyViewModel>().ForMember(dest => dest.color, opt => opt.ResolveUsing<ColorResolver>());
    
    public class ColorResolver : ValueResolver<MyClass, string>
    {
        protected override string ResolveCore(MyClass source)
        {
            return "green";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class with an attribute and getter method: public Class MyClass {
I have applied a Formatter to a JFormattedTextField using a FormatterFactory , when a
In Eclipse IDE how do you customize the Java code style formatter to have
I'm using Eclipse 3.4 and have configured the Java code formatter with all of
I want to have a PHP script send a XML formatted string to another
I have created the following class that extends JSpinner to iterate over dd/mm/yyy values.
I have a Person class with a BornDate property in my model defined as
I have a somewhat messily-formatted Objective-C code base. Is there a way to have
I have a case where i'm getting formatted text with <a href ...> ,
I have a table which is full of arbitrarily formatted phone numbers, like this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.