Posted by: [deleted]
Posting time: 5.4 years ago on 7/14/2015 9:12:32 PM
Last edit time: never edited.
Archived on: 2/12/2017 1:51:00 AM
Views: 508
SCP: 1
1 upvotes, 0 downvotes (100% upvoted it)
~1 user(s) here now
Welcome to the Voat subverse for the C# programming language!
C# is a multi-paradigm programming language made for general-purpose programming, web development, mobile, and more. Created and controlled by Microsoft, the language is now open source and is soon coming to Linux and Mac with official support (and already has third-party support with tools like Xamarin and Mono).
Got a suggestion for a blog (or want us to add yours)? Or an e-book / tutorial? Send the mod team a message! The more the merrier!
NSFW: No Authorized: No Anon: No Private: No Type: Default
Content violates spam guidelines
Content contains or links to content that is illegal
Content contains personal information that relates to a Voat users real world or online identity
Content or User violates User Agreement
Hi, it looks like you're new. Welcome to Voat!
Voat is a censorship-free community platform where content is submitted, organized, moderated and voted on (ranked) by the users.
Archived I recently implemented a data-driven version of FluentValidation using csscript.net. Is there a way of using generics to accomplish the same thing? (github.com)
submitted 5.4 years ago by [deleted]
[–] verifex 0 points 0 points 0 points (+0|-0) 5.4 years ago (edited 5.4 years ago)
As an example, I am implementing an AbstractValidator<T> using CSSCRIPT using something like this:
using System; using System.Collections.Generic; using System.Linq; using CSScriptLibrary; public object CreateClass(Type typeToValidate, string rulestoLoad); public readonly string Namespaces = @" using System; using System.Linq; using FluentValidation;" public readonly string Template = @" {0} public class DynamicRuleValidatorFor{1} : AbstractValidator<{2}> {{ public DynamicRuleValidatorFor{1}() {{ {3} }} }}"; var codeToLoad = string.Format(Template, Namespaces, typeToValidate.Name, typeToValidate.FullName, rulesToLoad); return CSScript.LoadCode(codeToLoad).CreateObject("*"); }
using System;
using System.Collections.Generic;
using System.Linq;
using CSScriptLibrary;
public object CreateClass(Type typeToValidate, string rulestoLoad); public readonly string Namespaces = @"
using FluentValidation;"
public readonly string Template = @"
{0}
public class DynamicRuleValidatorFor{1} : AbstractValidator<{2}>
{{
public DynamicRuleValidatorFor{1}() {{ {3} }}
}}";
var codeToLoad = string.Format(Template, Namespaces, typeToValidate.Name, typeToValidate.FullName, rulesToLoad);
return CSScript.LoadCode(codeToLoad).CreateObject("*");
}
Sort: Top
[–] verifex ago (edited ago)
As an example, I am implementing an AbstractValidator<T> using CSSCRIPT using something like this: