fluent-interface

Do fluent interfaces significantly impact runtime performance of a .NET application?

好久不见. 提交于 2019-12-04 02:49:30
I'm currently occupying myself with implementing a fluent interface for an existing technology, which would allow code similar to the following snippet: using (var directory = Open.Directory(@"path\to\some\directory")) { using (var file = Open.File("foobar.html").In(directory)) { // ... } } In order to implement such constructs, classes are needed that accumulate arguments and pass them on to other objects. For example, to implement the Open.File(...).In(...) construct, you would need two classes: // handles 'Open.XXX': public static class OpenPhrase { // handles 'Open.File(XXX)': public

Entity Framework Code First - One-to-Many with a join/link table

*爱你&永不变心* 提交于 2019-12-03 20:23:17
Is it possible to create a One-to-Many relationship with Code First that uses a link/join table between them? public class Foo { public int FooId { get; set; } // ... public int? BarId { get; set; } public virtual Bar Bar { get; set; } } public class Bar { public int BarId { get; set; } // ... public virtual ICollection<Foo> Foos { get; set; } } I want this to map as follows: TABLE Foo FooId INT PRIMARY KEY ... TABLE Bar BarId INT PRIMARY KEY TABLE FooBar FooId INT PRIMARY KEY / FOREIGN KEY BarId INT FOREIGN KEY With this, I would have the ability to make sure Foo only has one Bar, but that

Generic 'TThis' for fluent classes

ⅰ亾dé卋堺 提交于 2019-12-03 17:07:18
问题 I'm constructing a fluent interface where I have a base class that contains the bulk of the fluent logic, and a derived class that add some specialized behavior. The problem I'm facing is the return type of the fluent methods in the base class when called from an instance of the derived type. After invoking a method of the base class, only methods of the base class remain available for further fluent invocations. Changing the order in which the methods are invoked will help it to compile, but

Implementing conditional in a fluent interface

*爱你&永不变心* 提交于 2019-12-03 15:41:32
I've been trying to implement a fluent interface for a set of rules in my system. What I am trying to accomplish is this TicketRules .RequireValidation() .When(quartType => quartType == QuartType.Before).TotalMilageIs(64) .When(quartType => quartType == QuartType.After).TotalMilageIs(128); However, I have trouble implementing the When conditional how I intended to be. Currently, I need to call When() twice like in this snippet: rules.When(param => param.Remarque == "Test").TotalMilageIs(100); rules.When(param => param.Remarque == "Other").TotalMilageIs(50); var params1 = new

PHP OOP: Chainable objects?

非 Y 不嫁゛ 提交于 2019-12-03 12:54:04
I have tried to find a good introduction on chainable OOP objects in PHP, but without any good result yet. How can something like this be done? $this->className->add('1','value'); $this->className->type('string'); $this->classname->doStuff(); Or even: $this->className->add('1','value')->type('string')->doStuff(); Thanks a lot! The key is to return the object itself within each method: class Foo { function add($arg1, $arg2) { // … return $this; } function type($arg1) { // … return $this; } function doStuff() { // … return $this; } } Every method, that returns the object itself, can be used as

Inheritance EF Code-First

梦想与她 提交于 2019-12-03 12:37:10
I have a base object that I dont want to be mapped in DB as an entity, I only want the properties to be added to the object that is mapped in the DB : Not mapped object (dont know if it matters but baseobject is in another assembly): public class BaseObject { public virtual string Prop1 { get; set; } public virtual string Prop2 { get; set; } } Mapped object: public class ChildObject : BaseObject { public virtual string Prop3 { get; set; } public virtual string Prop4 { get; set; } public virtual string Prop5 { get; set; } } What is registered in DbContext public DbSet<ChildObject> ChildObjects

Does Entity Framework Code First allow for fluent mappings in separate files?

荒凉一梦 提交于 2019-12-03 12:26:05
I am developing a rather large database schema using Entity Framework Code First. I prefer the Fluent API over the Data Annotations approach, as it leaves my domain objects as simple POCOs. In order to use Fluent API, I have to override OnModelCreating in the class that inherits from DbContext. I don't like that all mappings for all of my entities are in this one method. I have used things like FluentNHibernate before, where each entity has it's own mapping class. Does EF have anything similar? I suppose I could create my own interface to implement a mapping class and call them all within the

EF 4.1 RC Many to many relationship in EF CF

a 夏天 提交于 2019-12-03 09:07:33
I have two entities with many to many relationship like this: class author { public int AuthorID{get;set;} public string Name{get;set;} public virtual ICollection<book> books{get;set;} } class book { public int BookID{get;set;} public string Name{get;set;} public virtual ICollection<author> authors{get;set;} } and I have an intermediate table named Bookauthor defined like this: BookAuthor: int int AuthorID int BookID How to map this using FluentAPI Thanks!! This was problematic with EDMX but with EF 4.1 fluent API you can map it : modelBuilder.Entity<book>() .HasMany(b => b.authors) .WithMany

What conventions/idioms/patterns are you using configuring IOC Containers using the new Fluent Interfaces

笑着哭i 提交于 2019-12-03 03:26:59
I am in the middle of moving over a large body of code to Castle Trunk which includes the new fluent interface for configuring the container. Since the project has a huge windsorConfig xml file that is beyond maintainable, I thought I would start to take advantage of this new feature. I know other containers (e.g. StructureMap 2.0) also contain fluent interfaces for container configuration, so this question isn't based around Windsor. My question is what conventions/idioms/patterns are you using for container configuration using the new fluent style interfaces? My first thought was to create a

Design of an Alternative (Fluent?) Interface for Regular Expressions

主宰稳场 提交于 2019-12-03 02:42:38
问题 I've just seen a huge regex for Java that made me think a little about maintainability of regular expressions in general. I believe that most people - except some badass perl mongers - would agree that regular expressions are hardly maintainable. I was thinking about how this situation could be fixed. So far, the most promising idea I have is using a fluent interface. To give an example, instead of: Pattern pattern = Pattern.compile("a*|b{2,5}"); one could write something like this import