473,378 Members | 1,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Argument '1': cannot convert from 'BaseObject<T>' to 'T'

Hi All,

I have this piece of code :

public interface IBase<T>
where T : BaseObject<T>, IBase<T>
{
public DataRow ObjectToDataRow(T Source);
}

public class BaseObject<T>
where T : BaseObject<T>, IBase<T>
{
public virtual DataRow ObjectToDataRow(T Source) { return null; }

public void Add(T Object)
{ innerData.Rows.Add(ObjectToDataRow(Object)); }

public void Save()
{
if (theDataRow == null)
ObjectToDataRow(this);
}

}
In Save() when I want to call ObjectToDataRow(this); I get that compile
error.
Why? [this] is already the type BaseObject!!! :-s
I want in the override function ObjectToDataRow in T to fill itself...

tia


Sep 13 '06 #1
2 2101
When I try this code I get:

Error 1 'T' is a 'type parameter' but is used like a 'variable'
public class BaseObject<T>

where T : BaseObject<T>

{

public virtual DataRow ObjectToDataRow(T Source) { return null; }

public void Save()

{

if (theDataRow == null)

ObjectToDataRow(T);


"Klaas" <No****@klaas.comschreef in bericht
news:u7**************@TK2MSFTNGP06.phx.gbl...
Hi All,

I have this piece of code :

public interface IBase<T>
where T : BaseObject<T>, IBase<T>
{
public DataRow ObjectToDataRow(T Source);
}

public class BaseObject<T>
where T : BaseObject<T>, IBase<T>
{
public virtual DataRow ObjectToDataRow(T Source) { return null; }

public void Add(T Object)
{ innerData.Rows.Add(ObjectToDataRow(Object)); }

public void Save()
{
if (theDataRow == null)
ObjectToDataRow(this);
}

}
In Save() when I want to call ObjectToDataRow(this); I get that compile
error.
Why? [this] is already the type BaseObject!!! :-s
I want in the override function ObjectToDataRow in T to fill itself...

tia


Sep 13 '06 #2
Found it myself! :-)))

Thanks anyway

"Klaas" <No****@klaas.comschreef in bericht
news:u7**************@TK2MSFTNGP06.phx.gbl...
Hi All,

I have this piece of code :

public interface IBase<T>
where T : BaseObject<T>, IBase<T>
{
public DataRow ObjectToDataRow(T Source);
}

public class BaseObject<T>
where T : BaseObject<T>, IBase<T>
{
public virtual DataRow ObjectToDataRow(T Source) { return null; }

public void Add(T Object)
{ innerData.Rows.Add(ObjectToDataRow(Object)); }

public void Save()
{
if (theDataRow == null)
ObjectToDataRow(this);
}

}
In Save() when I want to call ObjectToDataRow(this); I get that compile
error.
Why? [this] is already the type BaseObject!!! :-s
I want in the override function ObjectToDataRow in T to fill itself...

tia


Sep 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Eshrath | last post by:
Hi, What I am trying to do: ======================= I need to form a table in html using the xsl but the table that is formed is quite long and cannot be viewed in our application. So we are...
4
by: ESPNSTI | last post by:
Hi, Please don't shoot me if the answer is simple, I'm new to .Net and C# :) .. I'm attempting to convert a nullable type to it's "non-nullable" type in a generic way (without knowing what...
4
by: matty.hall | last post by:
I have two classes: a base class (BaseClass) and a class deriving from it (DerivedClass). I have a List<DerivedClass> that for various reasons needs to be of that type, and not a List<BaseClass>....
9
by: Simple Simon | last post by:
Java longs are 8 bytes. I have a Java long that is coming in from the network, and that represents milliseconds since Epoch (Jan 1 1970 00:00:00). I'm having trouble understanding how to get it...
3
by: Varangian | last post by:
Hello, there I have a problem with regards to System.Collections.Generic.List<T> I need to pass a class with implements an interface - TestClass : IPerson I put this class in a...
1
by: Robert Dodier | last post by:
Hello, Sorry for asking what must be a FAQ, but I wasn't able to find the answer. I have an XML document fragment which I want to store as a text string. I want a function to convert any XML...
7
by: Andrew Robinson | last post by:
I have a method that needs to return either a Dictionary<k,vor a List<v> depending on input parameters and options to the method. 1. Is there any way to convert from a dictionary to a list...
2
by: -Karl | last post by:
Couls someone please advise me on this error. What I am trying to do is be able to convert an XML document into arrays. I read that the subs & functions have to be in <scripttags. Thanks! ...
6
by: Peter | last post by:
I have a WebService which returns a List of RunningReport class How do I read this XML data on the client side. How do I convert List<RunningReportfrom the WebService side to List<RunningReporton...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.