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


Similar Messages:

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

MVC :: Generic List With Default Value As Method Parameter?

Jun 1, 2010

In one of the methods I'm using in my MVC app, there's a param that accepts a list collection of strings. If I have a string parameter, I can give it a default value of an empty string, but I cannot seem to give the list collection a default value of a new, empty list collection. I get the error that's beginning to seriously grate on my nerves about requiring a compile-time constant. getting the generic list to work with a default empty set?

View 5 Replies

Generic Parameter - Pass Another Control Type And Execute Exact Same Logic

Nov 30, 2010

I have a class constructor which accepts a Listbox.

[Code]....

I need to be able to pass another control type and execute the exact same logic in one of the methods... Seems like a use for Generics... I'm not so sure about the syntax... The type of control that I will pass is a rad combo box which has many of the same properties of the listBox control. However, RadComboBox does not inherit from listBox or dropDown so I am unable to cast. When changing the signature of the constructor to As RadComboBox as well as the property and field the method works as expected. I am trying to avoid duplicating code here.

View 1 Replies

Getting Child Class Type From Parent Class Parameter In C#

Jul 6, 2010

I am going to have multiple "types" of an object and I am really not sure how best to retrieve/save those multiple types without having a separate save/retrieve for each type.

My classes:

[Code]....

I hope this makes sense. I'd rather not add a "type" column as I have this in another part of my database and I am not really liking it too much

UPDATE

Here's more info/questions for clarification, if necessary.

I'm really at a loss for how to incorporate them into my repository pattern.

When I call getEvaluation, I want it to return an abstract Evaluation, but I'm struggling with this code. Same with Saving - any insight on this would be excellent

UPDATE 2

Database:
Evaluations
Id (PK)
Comment
EvaluationType1
Id (FK to Evaluations.Id)
Field
EvaluationType1
Id (FK to Evaluations.Id)
Field

So, in getEvaluation(int id), I need to figure out what type of Evaluation they want. Does this mean I should pass in a type? Same is true in saveEvaluation, But I can do a switch/function map to see what Type it is.

View 6 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

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

MVC Generic Base View Class / Error Parsing Attribute 'something': Type 'System.Web.Mvc.ViewPage'

Feb 5, 2010

I can have a base class for views in an MVC project like this:

public class BaseViewPage : System.Web.Mvc.ViewPage
{
public string Something { get; set; }
}

And then in the ASPX I can do this:

<%@ Page Something="foo" Language="C#" Inherits="MyNamespace.BaseViewPage" %>

This works fine; the problem is when I try to do the same with the generic version:

public class BaseViewPage<TModel> : System.Web.Mvc.ViewPage<TModel> where TModel : class
{
public string Something { get; set; }
}

When I try to use this from the ASPX, like this:

<%@ Page Something="foo" Language="C#" Inherits="MyNamespace.BaseViewPage<SomeClass>" %>

I get the error message:

Error parsing attribute 'something': Type 'System.Web.Mvc.ViewPage' does not have a public property named 'something'.

Notice how it tries to use System.Web.Mvc.ViewPage rather than my BaseViewPage class. To make it more interesting, if I remove the "Something" attribute from the Page directive and put some code in the generic version of BaseViewPage (OnInit for example) the class is actually called / used / instantiated.

So, am I doing something wrong or is this a limitation.

View 1 Replies

Is There A Way To Call Custom Method Of Custom Role Provider Class

Apr 21, 2010

I have created my own custom role provider class "SGI_RoleProvider" and configured properly.

Everything is working fine.

Suppose that I have added a public method say "SayHello()", then how can i call that. Because if i am using Roles then the method is not displayed. If i am forcefully using that Roles.SayHello() then compiler gives the error.

how can i call this. Because creating a new instance of SGI_RoleProvider is meaningless.

View 1 Replies

How To Get The Value Of A Parameter Passed To A Method In A Custom Rule In FxCop

Aug 16, 2010

Due to certain reasons, in our ASP.NET web application, it is not recommended to use Response.Redirect("something", True). It should be used with False for the endResponse parameter. We want to enforce this with a custom FxCop rule. I've managed to find the usages of Response.Redirect, but now I want to find the value of the endResponse argument. How can I do this?

We're using the following code:

[Code]....

I've used Introspector and thought the endResponse parameter was an integer behind the scenes, but I'm not so sure anymore. Anyway, there don't seem to be any booleans in the methodCall.Operands.

need to check the actual value of a parameter that's passed to a method?

View 1 Replies

Custom Server Controls : Want To Pass Control A Value To One Of Its Parameter Of Type DropDownList

Mar 4, 2011

I want to pass to my control a value to one of its parameter of type DropDownList. Something like:

<uc1:MyControl Id="01" runat="server" OtherControl="ddl1" />

Where "ddl1" is a DropDownList defined in the same page my control resides. How to create this kind of property?

View 2 Replies

C# - Map Class To Get The Db's Records With A Custom Method?

Apr 1, 2010

I'm developing a website with ASP.NET MVC, NHibernate and Fluent NHibernate and want to know how can I customize my Map to get records using a custom Method.

My entities:

public class ImageGallery {
public virtual int Id { get; set; }
public virtual string Titulo { get; set; }
public virtual IList<Image> Images { get; set; }
ublic virtual bool IsActive { get; set; }
}
public class Image {
public virtual int Id { get; set; }
public virtual ImageGallery ImageGallery { get; set; }
public virtual string Low { get; set; }
public virtual bool IsActive { get; set; }
}


My Fluent NHibernate Maps:

public class ImageGalleryMap:ClassMap<ImageGallery> {
public ImageGalleryMap() {
Id(x => x.Id);
Map(x => x.Titulo);
HasMany(x => x.Images)
.KeyColumn("ImageGalleryID");
Map(x => x.IsActive);
}
}
public class ImageMap:ClassMap<Image> {
public ImageMap() {
Id(x => x.Id);
References(x => x.ImageGallery);
Map(x => x.Low);
Map(x => x.IsActive);
}
}

And, a method on my ImageRepository class:

public IList<Image> ListActive() {
return this.Session.CreateCriteria<Image>()
.Add(Restrictions.Eq("IsActive", true))
.List<Image>();
}

If I create an object this way:

ImageGallery ig = new ImageGallery();

I can access my the Image's list using:

foreach(Image img in ig.Images) {
...
}

However, ig.Images give me access to all images records and I would like to access just active records (or another criteria), using ListActive()'s repository methods.

View 1 Replies

Custom Server Controls :: Custom Server Control Rendering Method In Multiple Class?

May 17, 2010

I am creating custom server control. I have two classes in project. One is main class that render control and another will be used to render content based on condition.I just want to know how to render content from other classes in main class.For example. This isjust an example.My main class code

[Code]....

My TopLeftPane class

[Code]....

My page code on page load event

[Code]....

When I run the page, Header title always getting null. This is a just sample code. I will have more than 20 classes so I dont want to write a code in main class to render whole control.I hope all of you understand my problem.

View 3 Replies

C# - List <Class> New Class Takes Up Memory - Can Set C=null; In The Code

Jul 23, 2010

List New Class takes up memory?Do I need C=null; in the code below?

//class Category
public List<Category> SelectAll()
{
List<Category> LV = new List<Category>();
string command = "SELECT * from categories";
SqlCommand sc = new SqlCommand(command, new SqlConnection(GlobalFunction.Function.GetConnectionString()));
sc.Connection.Open();
SqlDataReader dr = sc.ExecuteReader();
using(dr)
{
[code]...

View 5 Replies

AJAX :: Is It Possible To Call A Custom Method Or Class Before Accessing Webmethod From PageMethods

Jan 19, 2010

is it possible to call a custom method or class before accessing webmethod from pageMethods ?

View 2 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

ADO.NET :: No Overload For Method 'EndExecuteNonQuery' Takes '0' Arguments?

Sep 21, 2010

i'm getting this error when i run the code MY CODE:

public bool Insert_employee(EmployeeData empdat)
{
try

[code]...

View 2 Replies

Web Forms :: No Overload For Method 'editprofile' Takes '1' Arguments?

Feb 21, 2011

got this error.. I'm using SQL helper .Not able to figure out my error

[Code]....

View 1 Replies

MVC :: Getting Error: The Parameter Conversion From Type 'System.String' To Type 'Models.Organization' Failed?

Oct 15, 2010

I seem to be having issues with posting forms with DropDownLists. I've looked all over the net and tried various solutions, but none seem to work for me.

I'm getting the following error: The parameter conversion from type 'System.String' to type 'Models.Organization' failed because no type converter can convert between these types.

Here's my ViewModel:

[Code]....

Here's my controller:

[Code]....

The objects are generated by ADO.NET Entity Framework. Organizations is its own object, but also a property of Profile (each user belongs to one organization). Now I understand what the error message is saying, just not sure how else I'm supposed to do this.

View 7 Replies

Web Forms :: CS1501 / No Overload For Method 'newAccount' Takes '38' Arguments?

Jun 9, 2010

I just added new variable to my asp page but i have compiler error.

Line 346: fcd_hesapList hesap = new fcd_hesapList(); Line 347: return_values ret = ret = hesap.newAccount
Line 348: (
Line 349: // "sixtyday", //account type Line 350: acctType,
 
Source File: d:inetpubwwwrootdirectAppStep6.aspx.cs Line: 348

Original code is

[Code]....

View 5 Replies

Web Forms :: No Overload For Method GetImagess Takes 2 Arguments Error

Apr 27, 2016

Into below code i am using it to check if the user  had uploaded images before or not if yes then keep the old and update if the user has new files into fileuploads controls.

But what i am looking for to update the code and delete UID and use AdsID column  " column data type is: Int" which is passed by query string QADNUM.

I tried to delete UID and use QADNUM instaed of UID but it dosent work and i tried to add QADNUM but i faced an error with code line:

 string[] images = GetImagess(Convert.ToString(QADNUM), QADNUM); 

The error message with below line under the above line : No overload for method 'GetImagess' takes 2 arguments

private string[] GetImagess(string UID) {
string QADNUM = Request.QueryString["AID"];
SqlConnection EdPersInfoCon = new SqlConnection(ssc);
EdPersInfoCon.Open();
SqlCommand EdPersInfocmd = new SqlCommand();

[Code] ....

View 1 Replies

Web Forms :: Error - No Overload For Method Send Takes 5 Arguments

Nov 29, 2013

i have a problem in my project which was developed by Asp.net with c# language.

i got a given below error in my code below....

error: No overload for method 'Send' takes '5' arguments

Aspx.cs code is: 

protected void ImgBtnSubmit_Click(object sender, ImageClickEventArgs e). {
try {
string toadd = "info@abc.co.uk";
var fromAddress = "info@abc.co.uk";
var toAddress = toadd;
const string fromPassword = "abc";

[code].....

View 1 Replies

C# - How To Return A Value Based On The Type Of The Generic T

Jun 16, 2010

I have a method like:

public T Get<T>(string key)
{
}

Now say I want to return "hello" if the type is a string, and 110011 if it is type int.

how can I do that?

typeof(T) doesn't seem to work.

I ideally want to do a switch statement, and return something based on the Type of the generic (string/int/long/etc).

View 5 Replies

C# - SOAP Generic Type Serialization?

Apr 4, 2011

We have created a class to wrap the payload of web service response with common information as follows.

public class ItemResponse<T> : Response
{
/// <summary>

[code]...

View 2 Replies

C# - Deployment / Compiler Error Message: CS1501: No Overload For Method 'UpdateBookInfo' Takes '5' Arguments?

Apr 5, 2011

I already published my client's site and i received problem during loading page.

here's the error.

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1501: No overload for method 'UpdateBookInfo' takes '5' arguments

Source Error:

Line 33: //Update Book Info
Line 34: Book BookProcess = new Book();
Line 35: BookProcess.UpdateBookInfo(SKU, Title, Description, Price, Status);
Line 36:
Line 37: //Update Book Picture

View 1 Replies







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