CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Format:
Recent snippets matching tags of DataAnnotation
C#
// Regular usage
 
TypeDescriptor.AddProviderTransparent(
  new AssociatedMetadataTypeTypeDescriptionProvider(typeof(myEntity), 
    typeof(myEntityMetadataClass)), 
  typeof(myEntity));
 
List<ValidationResult> results = new List<ValidationResult>();
ValidationContext context = new ValidationContext(myEntity, null, null)
bool valid = Validator.TryValidateObject(myEntity, context, results, true);
by vinayg   May 20, 2011 @ 8:16am
155 Views
no comments
 
<#
//       Created by Dan Wahlin - http://www.thewahlingroup.com
//     Title: T4 Metadata and Data Annotations template
//       Usage: Generates the initial "buddy" classes to handle data validation across multiple frameworks
//       Description: I got tired of writing my initial "buddy" classes by hand once my EF model was created. This template
//                    handles generating all the classes and generates the primitive and navigation properties. It also
//                    decorates the properties with the [Required] and [StringLength] attributes as appropriate. Once the
//                    template generates the code you can copy it to a new file and make all the tweaks you want to support
//                    custom data annotations.
//       License: UIFAYW - Use it for anything you want (free or commercial)
by Dan Wahlin   February 20, 2011 @ 9:27am
1812 Views
no comments
 
' I watched Karl's video about validation with custom rules, and wondered
' why Silverlight, ASP.NET and ASP.NET MVC had DataAnnotations, and
' WPF only had IDataErrorInfo. So I thought of using EF4 as the model,
' and generating a metadata class like in RIA, MVC, etc for WPF and a
' inheritable generic class to convert the validations between IDataErrorInfo
' and the DataAnnotation attributes. 
'
' This way validation can happen the same way for each type of client!
'
' Let me know what you think please?
by rickrat   July 02, 2010 @ 3:54am
646 Views
no comments
 
C#
public static IEnumerable<ValidationResult> Validate(object component)
{
    return from descriptor in TypeDescriptor.GetProperties(component).Cast<PropertyDescriptor>()
            from validation in descriptor.Attributes.OfType<System.ComponentModel.DataAnnotations.ValidationAttribute>()
            where !validation.IsValid(descriptor.GetValue(component))
            select new ValidationResult(
                validation.ErrorMessage ?? string.Format(CultureInfo.CurrentUICulture, "{0} validation failed.",     
                validation.GetType().Name),
                new[] { descriptor.Name });
}
by Arjan   June 26, 2010 @ 10:28am
275 Views
no comments
 
C#
namespace System.DataAnnotations
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ComponentModel;
    using System.Reflection;
    using System.Globalization;
by Bruno Figueiredo   May 22, 2010 @ 4:50pm
959 Views
no comments
 
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate