C# - How To Create A Extension Method To Sum Up A Column Of A Generic Constrained Type In A Datatable

Oct 1, 2010

Is something like the below possible?

public static T Sum<T>(this DataTable dt, string columnName)
where T : IEnumerable<decimal>, IComparable<decimal>[code]....

It feels like i'm almost there, but not quite :/

Just trying to sum up either decimal or int values in a column in datatable. Currently getting a compile error, however think this is due to the incorrect generic constraint.

View 3 Replies


Similar Messages:

MVC :: Strongly Typed View With Constrained Generic?

Mar 17, 2010

Can my strongly typed view use a generic with a constraint? The type I want to pass to the view is

RoleGrantedToPerson<T> where T: Aggregate I don't know what T is at design time, only that it is a child of the base class 'Aggregate' I have tried using

System.Web.Mvc.ViewUserControl<RoleGrantedToPerson<Aggregate>>

but at runtime I get an error that the type of the view model supplied does not match the type required.

Is there some syntax/method to accomplish this?

View 8 Replies

C# - How To Create A Generic/parent Type That You Could Send To Methods Without Having To Define An Overload For Each Type

Mar 5, 2011

I'm trying to create a validation layer that will contain methods to validate all my objects (in my Business Objects layer) .. but when I try to reference both the validation and business objects to each other I get a circular dependency error .. so I've decided to create a new layer (BLL) to validate the objects for me and I'll be able to reference both the validation and the object layers.

so I want to build some kind of class/interface -I don't know what fits more- to be like a generic type or a parent type that my method could accept it as a parameter and check for it's Name/ID property. Instead of defining a new method overload for each object type I have
Simplification

View 1 Replies

Custom Server Controls :: Using The Generic Type 'System.Collections.Generic.IEnumerable' Requires '1' Type Arguments

Nov 25, 2010

I'm trying to create a control out of a class I found, and one of the overridden functions is the following:

protected override void PerformDataBinding(IEnumerable data)

However, when I try to build the control I'm getting the error as shown in the subject. I've tried searching, and it seems the signature for the original function matches the one I have, and all other solutions I've seen uses the same signature.

View 3 Replies

Data Controls :: Generic Method To Bind DropDownList With DataTable Or DataSet

Sep 4, 2012

i have 2 dropdown list and i need to create a Generic method so that I an reuse it...

View 1 Replies

Using Custom Class With Method That Takes Generic Type Parameter

Apr 23, 2010

I have several custom classes that derive from a common base class so they share several members in common. I would like to be able to pass objecs from any of these three classes to a function that will "look at" common properties. However, it seems there is a catch 22 -- When I try to access a member (.FirstName) of the passed object, the computer reports an error that it thinks the member doesn't exist.

It seems to be a sort of contradiction -- since I didn't declare the type, the computer can't confirm existence, but it seems that it should have to take it on faith since the generic character of the type is specified by the code. Possibly there is something I don't know about that would fix this. I'm showing VB code for what I have so far. I went ahead and hardcoded an instance to confirm that the object exists and has the needed property. I commented out the line that had the code that resulted in the computer reporting an error.

[Code]....

View 2 Replies

DataSource Controls :: Objectdatasource With A Generic Select Method - How To Pass The Type

Mar 14, 2011

[Code]....

[Code]....

The GetList method is as folllowing:

[Code]....

Now i can populate my gridview trough code by this: //gvwDiensten.DataSource = new BindingList<diensten>(dataManager.GetList<diensten>().ToList());But i would like to use an objectdatasource, so i created this:

[Code]....

</asp:ObjectDataSource>

But when running the page i get:

ObjectDataSource 'dsDiensten' could not find a non-generic method 'GetList' that has no parameters.

View 5 Replies

How To Create A CheckBoxListFor Extension Method In MVC

Oct 8, 2010

I know there is a ListBoxFor extension method among the ASP.NET MVC Html helper extension methods, but I always thought that a checkbox list is more user-friendly than a list box.

There was a very convenient CheckBoxList control in good old WebForms, but obviously that is out of the picture now. The question is, why is there no way in ASP.NET MVC to create a check box list? How can I write my own extension method that creates a check box list and behaves in a similar way ListBoxFor behaves?

View 3 Replies

Adding Duplicate Type Of Column To A Datatable?

Jan 9, 2011

How can i add same fields for columns in a datatable. I wan to make a datatable which repeate column name of same type multiple times, but dot net dont allow me to add that, but i want to do that hw can i do that?

table.Columns.Add("S.NO", typeof(int));
table.Columns.Add("DC", typeof(string));
table.Columns.Add("DC", typeof(string));
table.Columns.Add("DC", typeof(string));
table.Columns.Add("ST", typeof(string));
table.Columns.Add("ST", typeof(string));
table.Columns.Add("AD", typeof(string));
table.Columns.Add("AD", typeof(string));

View 1 Replies

MVC :: Create A Customized Dropdownlist Using "HtmlHelper" Extension Method?

Jun 8, 2010

i have defined a dropdown list in the controller

[Code]....

then i can show this dropdownlist in my "about" view <%=Html.DropDownList("a") %>.

BUT, now i want to define this dropdown list at my back end. what i want to do is to create a new "Helper".cs file in my project, and create a function within it. so every time if i want to show this dropdown list, i can just simply call this function instead of Add new SelectListItems one by one. is there anyone tell me how to do it?? and is it a good way to create a dropdownlist at the back end?

View 3 Replies

Razor Support Of Generic Extension Methods?

Feb 11, 2011

With regards to the Razor view engine, say I want to render Html.TextBoxFor<SomeModel>(i => i.Name), it doesn't seem that the inline syntax works as in:

@Html.TextBoxFor<SomeModel>(i => i.Name)

This doesn't seem to work because it interprets the generic as an HTML tag. I could use a code-block approach, but then what's the best approach to output the content? The HTML string returned from this method, do I response.write it, or is there a syntax for it, or what's the approach?

View 2 Replies

Forms Data Controls :: Create A Column While The Datatable Is Being Filled?

Jun 17, 2010

What I have is a datatable being constructed from Sharepoint API. We dont need to worry about the sharepoint api.The code where it fills the data is as follows

Datatable dt = new datatable();
Sharepoint.fill(dt);

Write what I want is as the dt is being filled is to create another column called full path which has a formula col1+col2I dont want to do a for next loop after the dt is filled . very slow !

View 1 Replies

Web Forms :: Extension Methods And Customized Generic List Collections

Nov 19, 2011

How to use extension methods and customizes generic list collections??

View 1 Replies

Configuration :: MIME Type For .licx Extension/Error 53 Unable To Resolve Type ' <add Type="TabStrip" Version="7.0" />'...

Nov 12, 2010

I am not sure if I have found the right forum for this one.

the problem is:

I have a .licx file in my rootfolder.

I am getting the error:

Error 53 Unable to resolve type ' <add type="TabStrip" version="7.0" />' C:inetpubwwwrootCrop_ApplicationCrop_Applicationeo_web.licx 7 Crop_Application

,which I get for all the types that are in the xml file(i just gave one of them).

A friend told me that I have to add the type .licx in the MIME type in the IIS .

The problem is that I find the MIME type, I add the extension type .licx but I do not know the MIME type for .licx

View 1 Replies

Forms Data Controls :: How To Create Rows And Column Using Datatable Gridview Itemtemplate With Multi Header

Feb 23, 2010

How to create Rows and Column using Datatable Gridview Itemtemplate with multi header I need to create Datatable Gridview Itemtemplate fixed rows and column such as 7 rows and 7 columns

[Code]....

View 2 Replies

Pass Datatable To The Mvc View Error / CS0246: The Type Or Namespace Name 'DataTable' Could Not Be Found

Sep 28, 2010

I was reading: [URL]

But I have give a compilation error:

CS0246: The type or namespace name 'DataTable' could not be found (are you missing a using directive or an assembly reference?

View 1 Replies

ADO.NET :: Generic List Convert To DataTable

Sep 20, 2010

I have a GenericList and i want to convert that to DataTable My code is here

[Code]....

I am getting Count in "objFinOpRegs". But i want to convert "objFinOpRegs " to DataTable.

View 2 Replies

Forms Data Controls :: Set A Column In A DataTable To Be A Primary Key For An Existing Datatable

Apr 2, 2010

If I am passed a datatable and I cant change the column structure..is there anyway to set an existing column to a Primary key so I can easily Find() the row I am looking for?

View 1 Replies

What Is Extension Method In Net

Feb 12, 2010

i saw the extension method code but i could not understand what it is and what is the utilities of extension method.

View 3 Replies

Forms Data Controls :: Generic List To DataTable

Sep 20, 2010

Generic List to DataTable

View 1 Replies

Add Extension Method To Service?

Mar 12, 2011

I am using Tuple class in WCF Service. When i add reference to my web project I get Tuple class. Now i want to add an extension method to Tuple<> class in my service which will be accessible in my Web project.

View 1 Replies

Extension Method Have Any Limitation In C#?

Feb 22, 2010

I want to ask, does adding extension methods to datatypes works in the same way as Microsoft's methods or do they have any limitaion.

This is relevant to experienced programmers who had find some limitations while using them.

View 3 Replies

Make IE Detect File Type Without Extension?

Nov 10, 2010

I'm trying to let the user download different documents where the data is stored in an SQL DB. In firefox, the filetype is correctly read, but not in IE. I'm trying to do this without having to set the ".pdf" or whatever extension the document has, because I haven't got that information. I only have the filetype.

[Code]....

View 3 Replies

C# - Reasonable Extension Method For Project?

Mar 9, 2010

I recently found out about C# extension methods and wrote this one:

/// <summary>
/// Short-hand for setting the data source and binding it.
/// </summary>
/// <param name="me">The control to set and bind the data source of.</param>
/// <param name="dataSource">The data source.</param>
public static void BindTo(this DataBoundControl me, IEnumerable dataSource)
{
me.DataSource = dataSource;
me.DataBind();
}

What do you guys think? Is this a reasonable extension method to use in a professional ASP.NET project?

View 4 Replies

(VB) Extension Method Not Working As Expected?

Sep 5, 2010

I have the following Extension Method

Imports System.Runtime.CompilerServices
Namespace Extensions
Public Module IntegerExtensions
<Extension()>
Public Function ToCommaDeliminatedNumber(ByVal int As Integer) As String
Dim _input As String = int.ToString
Select Case int
Case Is > 99999 : Return _input.Remove(_input.Length - 3) & "k"
Case Is > 9999 : Return Math.Round(Double.Parse(int / 1000), 1).ToString & "k"
Case Is > 999 : Return String.Format("{0:N0}", int)
Case Else : Return _input
End Select
End Function
End Module
End Namespace

And in one of my classes I'm using user.Reputation.ToCommaDeliminatedNumber I am importing the Extensions Namespace into the Class, but the error I'm getting is...'ToCommaDeliminatedNumber' is not a member of 'Integer?'. I do have other Extension Methods for Strings and Dates that work exactly as expected... I'm just at a loss on this one.

View 1 Replies







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