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 910129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:59:34+00:00 2026-05-15T16:59:34+00:00

I am new about attributes. I just try it on my console application. So

  • 0

I am new about attributes. I just try it on my console application.

So how can i validate my person instance below example ?

class Person
    {
        [StringLength(8,ErrorMessage="Please less then 8 character")]
        public string Name { get; set; }

    }
  • 1 1 Answer
  • 4 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-15T16:59:35+00:00Added an answer on May 15, 2026 at 4:59 pm

    Here is simple code example without reflection.

    class Program
    {
        static void Main(string[] args)
        { 
            var invalidPerson = new Person { Name = "Very long name" };
            var validPerson = new Person { Name = "1" };
    
            var validator = new Validator<Person>();
    
            Console.WriteLine(validator.Validate(validPerson).Count);
            Console.WriteLine(validator.Validate(invalidPerson).Count);
    
            Console.ReadLine();
        }
    }
    
    public class Person
    {
        [StringLength(8, ErrorMessage = "Please less then 8 character")]
        public string Name { get; set; }
    }
    
    public class Validator<T> 
    {
        public IList<ValidationResult> Validate(T entity)
        {
            var validationResults = new List<ValidationResult>();
            var validationContext = new ValidationContext(entity, null, null);
            Validator.TryValidateObject(entity, validationContext, validationResults, true);
            return validationResults;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the example code below, I have a question about the List. My prof
Is there something new about row-level security in SQL Server 2012? In 2008 and
I have been asked to post a new question about how to correctly sort
I'm developer moving from C# to Java. Heard about new ASP net feature. <%:
I heard about the new entity framework for .net, and decided to modify my
I have a general question about the new Django 1.3 static file framework. I
I want to ask something about the new module 'Domain' in node v0.8. var
I'm relatively new to C++ (about one year of experience, on and off). I'm
The team talks about one new effect released in jQUery UI 1.8. Which one
I found a great explanation about the new RTTI in Delphi ,but I don't

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.