Format:
Recent snippets matching tags of DataAnnotation
// 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);
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)
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?
646 Views
no comments
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 }); }
275 Views
no comments
namespace System.DataAnnotations { using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel; using System.Reflection; using System.Globalization;
959 Views
no comments
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search
