Using Type Inference With Fluent Interfaces?

Feb 17, 2012

I have a class /interface hierarchy. On the interface side I have

IQuery
ISelect (inherits IQuery)
IUpdate (inherits IQuery)

[code].....

View 2 Replies


ADVERTISEMENT

Java - Relying On Type Inference Affect Code Maintainability

Apr 15, 2012

I've only used type inference when using LINQ in VB.NET. However, I'm aware that type inference can be used in other parts of the language, as demonstrated below:

Dim i = 1 'i is inferred to be an Integer
Dim s = "Hoi" 's is inferred to be a string
Dim Temperatures(10) as Double

[code]....

I can see how type inference reduces the amount of typing I would need to write a piece of code and can also make it quicker to change the type of a base variable (such as Temperatures(10) above) as you wouldn't need to change the types of all other variables that access it (such as T). However, I was concerned that the lack of an explicit declaration of type might make the code harder to read, say during a code inspection, as it may not be immediately obvious what type a variable is. For example, by looking at just the For loop above, you might correclty assume that T is some floating point value, but wouldn't be able to tell if it's single- or double-precision without looking back at the declaration of Temperatures. Depending on how the code is written, Temperatures could be declared much earlier and would thus require the reader to go back and find the declaration and then resume reading. Admittedly, when using a good IDE, this is not so much of an issue, as a quick hover of the mouse cursor over the variable name reveals the type.

Also, I would imagine that using type inference in some situations could introduce some bugs when attempting to change the code. Consider the following (admittedly contrived) example, assuming that the classes A and B do completely different things.

Class A
Public Sub DoSomething()
End Sub
End Class

[code]....

It is possible to change the type of ObjectList from A to B and the code would compile, but would function differently, which could manifest as a bug in other parts of the code.With some examples of type inference, I would imagine that most people would agree that its use has no negative affect on readability or maintainability. For example, in Java 7, the following can be used:

ArrayList<String> a = new ArrayList<>(); // The constructor type is inferred from the declaration.

instead of

ArrayList<String> a = new ArrayList<String>();

View 3 Replies

Interfaces, Type Identity, Extending .net Native Classes?

Jun 18, 2010

So in a lot of frameworks there is usually some base type that you tend to extend a lot because well, it is what enables the "visual" aspect of the framework. Here in .Net it's the Control/Form... you tend to be inheriting these frequently for different things, and despite the suggestions otherwise, the team always agrees to extend explicitly and forget about composition.So now say you want to create some relationship between all of these... just a simple interface that uncovers some basic properties that all your forms and controls should have. In this case lets call it 'IProjControl'

Code:
Public Interface IProjControl
Property ProjControlId() As String

[code]....

So this interface is something you expect all your windows and dialog boxes and other some other controls implement. They all don't extend the same exact type, they all just happen to be controls.In there lies the problem... you want to enforce the contract with this interface that not only is it a 'IProjControl', but it's also a 'Control'. But we can't exactly have our interface extend Control (that doesn't make sense), and there isn't an 'IControl' interface to require implementing.

So the method I've always used is something like this:

Code:
Public Interface IProjControl
ReadOnly Property ProjControlComponent() As Control
Property ProjControlId() As String

[code]....

(if there is actually a language/compiler specific feature that allows you to require an interface implementation to be implemented by a class extending a specific type... please, do tell... but I highly doubt there is because for all intensive purposes that sounds weird).

View 12 Replies

.net - Fluent NHibernate Duplicate Columns?

Dec 28, 2011

I am having some redundant primary key issues.I have an Item which contains many reports. I have mapped them as shown below. I can do Session.QueryOver(Of Item).List and there are no extra columns generated. I can also do Session.QueryOver(Of Report).List and there are no extra columns generated.

However, once I try to traverse the relationship from Item to Reports, I get the SQL query shown below. Can anyone tell me why?

[Code]...

View 2 Replies

C# - Executing Sql Statements With Fluent NHibernate

May 12, 2009

Basically I want to be able to do this:

session.ExecuteSql("...");

I don't need it to map to any entities or return any values.

View 1 Replies

Ignoring Properties In Fluent NHibernate With (2.0)?

Jul 29, 2010

Because there is so little information about VB.Net and (Fluent) NHibernate to be found, I decided to write this question to all other developers finding themselves looking for more information.On of the things i had to struggle with was how to Ignore properties in NHibernate.The reason i had to ignore properties was because we used a Webserivce which cannot serialize Interface classes (ILists). Which are used a lot with NHibernate.

View 1 Replies

Options Are Available For A Developer When Using Fluent NHibernate?

Jul 9, 2010

I've been using c# for the past year and I enjoy the power you get with Fluent NHibernate. One question that I get from friends is "nice but how can vb.net programmers use this?"So for example- the below is a c# mapping class. How would someone do this with vb.net?

public class PostMap : ClassMap<post>
{
public PostMap()
{
Table("Posts");

[Code]...

View 1 Replies

Mapping Custom GUID With Fluent NHibernate

Dec 6, 2011

I am using Fluent NHibernate to map an Oracle database. It is a legacy database so I cant really change everything I want.There is a GUID field, but the keys are still composite (I will change this as soon as I can so that the keys are not composite, but I cant do it right now). The GUID is a VARCHAR2 field with this layout: 551608b1-275d-49f6-9561-44d01aacf23f. The GUID is not added by a sequence in Oracle, but inserted from code (C# or VB.net)[code]Is the problem that I dont use a sequence to generate my GUID? How can I overcome this?

View 1 Replies

Fluent NHibernate To Ignore Specific Properties Without Automapping?

Dec 21, 2011

I am using Fluent NHibernate to map out an existing database. For this reason - automapping isn't an option for me.How do I tell NHibernate not to map certain properties? Many of them are read-only, and the others do not need to be persisted for other reasons.

I am writing this in VB.Net.I get the typical error message:"The following types may not be used as proxies should be 'public/protected virtual' or 'protected internal virtual'"I have purposely not made my objects Overridable (equivalent to virtual in C#) because I do not want NHibernate to touch them.

View 1 Replies

Fluent NHibernate Not Mapping Child Rows To A Collection Property (DB2 Database)

Nov 4, 2011

The tables described herein both utilize composite keys. I have a parent table that stores eligibility information per "case". The child table stores eligibility information regarding each individual associated with the case. The child records are differentiated by pin number to make them unique in the child table only.

I am using NHibernate v3.1 with Fluent NHibernate v1.2, both acquired via NuGet packages. The entities are mapped in using the Fluent NHibernate auto-mapper functionality. Any custom mapping is done in the mapping override method for each entity.

Another thing to know is that these tables do not have a "primary key" defined in DB2. They only have "unique keys", which are what you see in the composite key definition below (see code).

T0026_AG_ELIG is the name of the parent table and the corresponding POCO class.
T0265_AG_IN_ELIG is the name of the child table and the corresponding POCO class.

Problem:

The problem is that when I execute the query, all the data is queried, the parent record is successfully mapped to the class, but the returned child rows do not map into the collection on the parent class. NHibernate does generate the queries for the parent and child data. When I execute my own query against the database, the correct data for the conditions does come back. For some reason, the child records are just not being bound to the property on the parent (T0026) class.

Question:

What do I need to do to get the multiple rows coming back from T0265_AG_IN_ELIG to map to their corresponding class and load properly into the specified collection property on the parent class (T0026_AG_ELIG)?

Collection Property of Parent (T0026_AG_ELIG):

Public Overridable Property IndividualEligibilityRecords As IList(Of T0265_AG_IN_ELIG)
Mapping Override for Parent (T0026_AG_ELIG):
mapping.CompositeId() _

[Code].....

View 2 Replies

VB - Entity Framework 4.1: Describe Relationship Into The DbContext Definition Using A Fluent Code First Approach?

Dec 5, 2011

I have in my database a table (AccessControl) that describes a sort of users "access control list" for the informations contained in the table Customers and other tables.Example: the entity CUSTOMER is marked by the EntityId #1. If a user belongs to the department #6, he can access the records of customer #16 and #31, but he can't for #14, that can viewed by user in department #3:

[code]...

How can I describe this relationship into the DbContext definition using a fluent Code First approach?

View 1 Replies

Are Interfaces Used Often

Oct 16, 2009

Are Interfaces used often? Need opinions.

View 4 Replies

.net Project With C# Fluent NHibernate Mappings Project?

Sep 30, 2010

Having successfully tried out nHibernate, I would now like to try using Fluent for mapping. My main project is in vb.net but I would really like to use c# for the mappings since the lambda expression capability makes it much cleaner. Can you have a separate project/assembly for your mapping files without creating a circular dependency with domain objects?

View 2 Replies

Project With C# Fluent NHibernate Mappings Project

Dec 2, 2009

Having successfully tried out nHibernate, I would now like to try using Fluent for mapping. My main project is in vb.net but I would really like to use c# for the mappings since the lambda expression capability makes it much cleaner. Can you have a separate project/assembly for your mapping files without creating a circular dependency with domain objects?

View 1 Replies

.net - Casting Interfaces And MEF?

Mar 13, 2009

I have the following problem with MEF: Interface definition to be used by host:

Public Interface IExecuteDoSomething
Inherits IAddinSettings
Event DataReceived As EventHandler(Of DataReceivedEventArgs)
Function DoSomething() As Boolean
End Interface

[Code]...

Everything seems to work fine until the Button2_Click routine is executed, then an InvalidCastException is thrown with the info:Unable to cast object of type 'System.Collections.Generic.List1[SharedLibrary.IExecuteDoSomething]' to type 'System.Collections.Generic.List1[SharedLibrary.IAddinSettings]'.

How can i solve this problem, because the imported object implements both of the interfaces?

View 1 Replies

A To Z Usage Of Interfaces In .NET?

Dec 30, 2011

In this discussion let us discuss every usage of interfaces in .NET. Any real time examples and difficulties in using interfaces can also be discussed here.

View 6 Replies

Multiple Interfaces With .NET?

Aug 6, 2009

Im building a game with VB.NET I designed the core of the game in form1 window But now I need menus. How can I implement this without having 5 or so windows that I show() and hide() ? Doing that slows it down a lot and uses lots of memory. I tried tabs, but I don't want the tabs to appear, just switch. Whats the best way to implement multiple interfaces?

View 1 Replies

Oop - Inheritance And Interfaces ?

Jul 14, 2011

Has someone a hint what I'm doing wrong in VB.Net?

Module Module1

Interface ISearch(Of T As ISearchResult)
Function ids() As List(Of T)
End Interface

[CODE]...

The third cast isn't working. Why? did I miss a oop lesson?

View 2 Replies

Using Dictionary With Interfaces?

Sep 12, 2009

What I would like to do is make an abstract class that will hold objects in a dictionary and manage the adding/deleting/key changes of those items in the dictionary. My problem is that in order to make the class as generic as possible I declared the dictionary as dictionary(of long, of SomeInterface).The problem is when I try to pass a strongly typed dictionary in the constructor using dictionary( of long, ClassThatImplementsSomeInterface) I get a compiler error because it cannot convert to that type.

The reason I want to pass the dictionary in the abstract class's constructor is so that I can use the strongly typed dictionary in the subclass and have the abstract class manage the keys when it needs to. So how can I do something like this? Also- If there is a much better way to manage keys than what I am doing feel free to let me know, but I am much more interested in how to make this work since I have encountered this type of problem a few times before.

Here's the abstract class:
Public MustInherit Class HasChildrenKeys
Protected m_childItems As Dictionary(Of Long, IHasKey)

[code].....

View 7 Replies

.net - Using VB Interfaces, Enums, Etc In C# Code?

Oct 20, 2011

I have a solution with multiple projects, some of the projects are written in VB, some in C#. I am wondering if there's a way to use interfaces and/or enums written in VB in C# classes? My C# code below doesn't compile, however I am able to see the interface in intellisense.

[Code]...

P.S It's a console/service application, not ASP.Net (where I know it's doable).UPD: Sorry guys, was missing a reference to the project with the interface. It's fixed now. I think the thing that in VB projects references are done slightly different than in C# confused me.

View 2 Replies

3 Values To The Serial Interfaces

May 1, 2009

I have a program written in Visual Studio to me 3 values ( 0-255, 0-255, 0-255) to send the serial interfaces, and While assigned to the 3 values of 3 sliders together.[code...]

View 1 Replies

Collections And Interfaces And Casting?

Nov 14, 2010

Say I have a interface called IProperties and I have a collection called colMyProperties that is a collection of IProperties. Then I have an object called clsProperty that implements the IProperty interface. Now, in my code where I add objects to the colMyProperties collection I add a bunch of clsProperty objects. so far so good.

Now when I try to access an object in the collection I can only access properties and methods of the IProperties interface, not the clsProperty object. What am I doing wrong? Do I need to cast the object?

View 2 Replies

DLL Settings - Project That Has Several Different Interfaces ?

Oct 4, 2011

I have a project that has several different interfaces (a website, a local application, and some webservices), that all use the same class library. The library is an API to a database. Some settings, like log level, database connection etc, i want to store in a single place, and I want them editable. What is the best way to accomplish this? I am concerned both about ease of editing, and ease of access for the dll, as there will be a lot of calls to it and a lot of lookups for the values. I have considered using app.config, a standalone XML file, and writing values to the registry, but I cannot find any good comparisons.

View 2 Replies

Equals Operator For Interfaces?

Dec 8, 2009

I have three classes which implement an Interface iComparesWith, and I wish there to be a single function such that each iComparesWith object of any of the three implementing classes should be able to compare itself with any other iComparesWith object, again, of any of the three implementing classes, and know if the two objects are equal. How can I code this so that the comparison code is only written once? Is it the case that I will have to create a top-level MustInherit class which implements the equality comparison, and have MustOverride methods for all of the methods of iComparesWith?

View 1 Replies

How To Singleton Pattern Using Interfaces?

Jul 5, 2010

I am working on creating a customized UI composite control. This control would be a container to several other custom controls.As a first step, i am creating the container UI using a singleton pattern. This is because at any point in time only one isntance of this container is allowed to be created. This is fine.Now i want to practice interface based desgin. So i introduced a sinple interface calleD IdesignSurface which has two properties. I would like my singleton class to implement this interface,so i tried something like this and got an error saying "end of line

NotInheritable
Class DesignSurface
implements IDesignSurface

[code]......

View 2 Replies

How To Use / Implement .NET Controls/interfaces

Aug 25, 2011

I am a VB programmer of some 13 years. I started briefly with VB5 back in the mid-to-late 1990s, but then quickly moved to VB6 which I did for several years on PCs and HPCs (CE 1.x devices).I have done .NET 2002, 2003, 2005, and 2008 each for stints, intermingled with VB6 coding, at various jobs. But, I never got formally trained on VB.NET. In fact, I taught myself VB5/6 too. I have a degree in Computer Science and Mathematics, but the university CS program only had Unix systems. I basically learned everything I know on the fly from various Microsoft Press and other company's books (and the MS website/MSDN CDs too) while doing projects.I was wondering what everyone would suggest to really learn the .NET workings and why they are setup like that for Windows client/server applications. It doesn't have to be technical and brain-numbing.I have recently run into things dealing with MSFlexGrid vs DataGridView and how they link/work with database sources that confounds me. And, I am assuming there's just something I don't know about how/why VB.NET works the way it does...and I want to learn it to become a better developer.I want kind of that fun book that's easy to read, is thorough in that it teaches you a wide range of how to use/implement .NET controls/interfaces, and will fill in the gaps in my knowledge and experience.

View 1 Replies

Inherited Members In Interfaces?

Apr 21, 2010

When I pass an an object 'MyObject' which implements 'IMyInterface' to a method parameter declared as IMyInterface, I understand that this method parameter 'sees MyObject through the eyes of its interface'.

View 2 Replies

Relationship Between Interfaces And Firewall?

May 8, 2010

Can we call firewall an interface?

View 1 Replies

Specify The Interfaces An Argument Must Implement?

Nov 3, 2010

I have an interface called IBaselineControl. Now I'm trying to write a procedure which requires, as an argument, a Control which implements the IBaselineControl interface. However, I don't know the syntax for this. VB.Net allows us to require multiple interface implementations along with class inheritance when writing constraints for generic types. The syntax used there suggests that something like this might work:Public Sub Test(X As {Control, IBaselineControl})Unfortunately, that syntax doesn't work and I'm unable to find any syntax which does.

View 6 Replies

Specify Variable Implementing Two Interfaces Possible?

Mar 13, 2011

Is is possible to implement a type specifier with 2 interfaces in .net? Something like:
Public Sub New(obj as ICollection and INotifyCollectionChanged)
''Initialize Code
End Sub

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved