473,387 Members | 1,628 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,387 software developers and data experts.

Operator Overloading?

Hello All,

I'm wondering if the following is possible. I'm explicitly overloading
SqlParameter, but get the following error when I try to convert to and from
arrays.

Cannot convert type 'EntityPersistence.DataFieldParameter[]' to
'System.Data.SqlClient.SqlParameter[]'

Thanks,
JP
Nov 16 '05 #1
4 1274
How does your overloading code look like?

Sounds like you're trying to do an invalid cast in the operator logic.

--
Patrik Löwendahl [C# MVP]
www.cshrp.net - "Elegant code by witty programmers"

"JP Wrye" <jp*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello All,

I'm wondering if the following is possible. I'm explicitly overloading SqlParameter, but get the following error when I try to convert to and from arrays.

Cannot convert type 'EntityPersistence.DataFieldParameter[]' to
'System.Data.SqlClient.SqlParameter[]'

Thanks,
JP

Nov 16 '05 #2
static public explicit operator SqlParameter(DataFieldParameter
dataFieldParameter)

{

SqlParameter _sqlParameter = new SqlParameter();

_sqlParameter.DbType = dataFieldParameter.DbType;

_sqlParameter.Direction = dataFieldParameter.Direction;

_sqlParameter.ParameterName = dataFieldParameter.ParameterName;

_sqlParameter.Precision = dataFieldParameter.Precision;

_sqlParameter.Scale = dataFieldParameter.Scale;

_sqlParameter.Size = dataFieldParameter.Size;

_sqlParameter.SourceColumn = dataFieldParameter.SourceColumn;

_sqlParameter.SourceVersion = dataFieldParameter.SourceVersion;

_sqlParameter.Value = dataFieldParameter.Value;

return _sqlParameter;

}

----------------------------------------------------------------------------
-------

DataFieldParameter _dataFieldParameter = new DataFieldParameter();

DataFieldParameter[] _dataFieldParameters =
EntityBuilder.GetParameters(obeject);

SqlParameter _sqlParameter = (SqlParameter)_dataFieldParameter; //Works.

SqlParameter[] _sqlParameter = (SqlParameter[])_dataFieldParameters;
//Doesn't Work.



"Patrik Löwendahl [C# MVP]" <pa**************@csharpsweden.com> wrote in
message news:es**************@TK2MSFTNGP12.phx.gbl...
How does your overloading code look like?

Sounds like you're trying to do an invalid cast in the operator logic.

--
Patrik Löwendahl [C# MVP]
www.cshrp.net - "Elegant code by witty programmers"

"JP Wrye" <jp*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello All,

I'm wondering if the following is possible. I'm explicitly

overloading
SqlParameter, but get the following error when I try to convert to and

from
arrays.

Cannot convert type 'EntityPersistence.DataFieldParameter[]' to
'System.Data.SqlClient.SqlParameter[]'

Thanks,
JP


Nov 16 '05 #3
JP Wrye <jp*****@hotmail.com> wrote:
I'm wondering if the following is possible. I'm explicitly overloading
SqlParameter, but get the following error when I try to convert to and from
arrays.

Cannot convert type 'EntityPersistence.DataFieldParameter[]' to
'System.Data.SqlClient.SqlParameter[]'


Just because a conversion is possible between type A and type B doesn't
mean there's a conversion between A[] and B[]. You'll need to create a
new array and copy the entries from one into the other.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
The type SqlParameter and SqlParameter[] is not treated as equal types.

SqlParameter[] is an array with ElementType of SqlParameter, that differs
from the type SqlParameter.

You will have to explicitly write code for that conversion.

--
Patrik Löwendahl [C# MVP]
www.cshrp.net - "Elegant code by witty programmers"
"JP Wrye" <jp*****@hotmail.com> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
static public explicit operator SqlParameter(DataFieldParameter
dataFieldParameter)

{

SqlParameter _sqlParameter = new SqlParameter();

_sqlParameter.DbType = dataFieldParameter.DbType;

_sqlParameter.Direction = dataFieldParameter.Direction;

_sqlParameter.ParameterName = dataFieldParameter.ParameterName;

_sqlParameter.Precision = dataFieldParameter.Precision;

_sqlParameter.Scale = dataFieldParameter.Scale;

_sqlParameter.Size = dataFieldParameter.Size;

_sqlParameter.SourceColumn = dataFieldParameter.SourceColumn;

_sqlParameter.SourceVersion = dataFieldParameter.SourceVersion;

_sqlParameter.Value = dataFieldParameter.Value;

return _sqlParameter;

}

-------------------------------------------------------------------------- -- -------

DataFieldParameter _dataFieldParameter = new DataFieldParameter();

DataFieldParameter[] _dataFieldParameters =
EntityBuilder.GetParameters(obeject);

SqlParameter _sqlParameter = (SqlParameter)_dataFieldParameter; //Works.

SqlParameter[] _sqlParameter = (SqlParameter[])_dataFieldParameters;
//Doesn't Work.



"Patrik Löwendahl [C# MVP]" <pa**************@csharpsweden.com> wrote in
message news:es**************@TK2MSFTNGP12.phx.gbl...
How does your overloading code look like?

Sounds like you're trying to do an invalid cast in the operator logic.

--
Patrik Löwendahl [C# MVP]
www.cshrp.net - "Elegant code by witty programmers"

"JP Wrye" <jp*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello All,

I'm wondering if the following is possible. I'm explicitly

overloading
SqlParameter, but get the following error when I try to convert to and

from
arrays.

Cannot convert type 'EntityPersistence.DataFieldParameter[]' to
'System.Data.SqlClient.SqlParameter[]'

Thanks,
JP



Nov 16 '05 #5

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

Similar topics

16
by: Edward Diener | last post by:
Is there a way to override the default processing of the assignment operator for one's own __value types ? I realize I can program my own Assign method, and provide that for end-users of my class,...
34
by: Pmb | last post by:
I've been working on creating a Complex class for my own learning purpose (learn through doing etc.). I'm once again puzzled about something. I can't figure out how to overload the assignment...
16
by: gorda | last post by:
Hello, I am playing around with operator overloading and inheritence, specifically overloading the + operator in the base class and its derived class. The structure is simple: the base class...
2
by: pmatos | last post by:
Hi all, I'm overloading operator<< for a lot of classes. The question is about style. I define in each class header the prototype of the overloading as a friend. Now, where should I define the...
67
by: carlos | last post by:
Curious: Why wasnt a primitive exponentiation operator not added to C99? And, are there requests to do so in the next std revision? Justification for doing so: C and C++ are increasingly used...
3
by: karthik | last post by:
The * operator behaves in 2 different ways. It is used as the value at address operator as well as the multiplication operator. Does this mean * is overloaded in c?
5
by: Jerry Fleming | last post by:
As I am newbie to C++, I am confused by the overloading issues. Everyone says that the four operators can only be overloaded with class member functions instead of global (friend) functions: (), ,...
3
by: y-man | last post by:
Hi, I am trying to get an overloaded operator to work inside the class it works on. The situation is something like this: main.cc: #include "object.hh" #include "somefile.hh" object obj,...
9
by: sturlamolden | last post by:
Python allows the binding behaviour to be defined for descriptors, using the __set__ and __get__ methods. I think it would be a major advantage if this could be generalized to any object, by...
8
by: Wayne Shu | last post by:
Hi everyone, I am reading B.S. 's TC++PL (special edition). When I read chapter 11 Operator Overloading, I have two questions. 1. In subsection 11.2.2 paragraph 1, B.S. wrote "In particular,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.