|
Home > Archive > Commerce Server General > September 2006 > Extending/Deriving Product Class
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Extending/Deriving Product Class
|
|
|
| Hello, I am trying to create a new class that extends the MSCS 2007 Product
Class (derives from it).
I need to use Custom Properites like for example: productItem["Weight"] =
value; be accessible directly as a property like productItem.Weight = value
The problem is when extending the Product Class an error is generated
regarding the Constructor:
*** CS0143: The type 'Microsoft.CommerceServer.Catalog.Product' has no
constructors defined ***
I can't find any reference to what the Product Class constructor should be
Here is the class code and what I have for constructor:
public class MyProductItem : Product
{
public MyProductItem() : this(string.Empty, string.Empty)
{
}
public MyProductItem(string _productId, string _catalog)
{
if (string.IsNullOrEmpty(_productId) ||
string.IsNullOrEmpty(_catalog))
{
throw new ArgumentNullException("Invalid Parameters");
}
this = CommerceContext.Current.CatalogSystem.GetProduct(_catalog,
_productId);
}
}
I am not sure if deriving from a class such the Product Class is a safe
procedure.
Any ideas regarding this issue
Thanks
Steve
| |
| Joseph Johnson 2006-09-25, 1:22 pm |
| Steve,
I've had similiar issues attempting to inherit from other classes which do
not expose a constructor (specifically, the Basket class).
The only solution I've ever really seen for this is to use a wrapper pattern
around the product instead of inheriting from it. This isn't nearly as
convenient, and it's annoying to maintain, but I think it's the only design
pattern you can use for something like this. So, using the wrapper pattern,
your code would look as follows (also included your Weight property):
public class MyProductItem
{
private Product;
public MyProductItem(string _productId, string _catalog)
{
if (string.IsNullOrEmpty(_productId) ||
string.IsNullOrEmpty(_catalog))
{
throw new ArgumentNullException("Invalid Parameters");
}
Product = CommerceContext.Current.CatalogSystem.GetProduct(_catalog,
_productId);
}
public object Weight
{
get {return Product["Weight"];}
set {Product["Weight"] = value;}
}
}
Again, not as elegant as inheritance, but if you need to apply custom logic
around the normal API objects, this is one way of doing it.
Joe
"Steve" <Steve@discussions.microsoft.com> wrote in message
news:B271E39F-A24C-4163-95AF-2EAE9FEF89A7@microsoft.com...
> Hello, I am trying to create a new class that extends the MSCS 2007
> Product
> Class (derives from it).
> I need to use Custom Properites like for example: productItem["Weight"] =
> value; be accessible directly as a property like productItem.Weight =
> value
>
> The problem is when extending the Product Class an error is generated
> regarding the Constructor:
> *** CS0143: The type 'Microsoft.CommerceServer.Catalog.Product' has no
> constructors defined ***
>
> I can't find any reference to what the Product Class constructor should be
>
> Here is the class code and what I have for constructor:
>
> public class MyProductItem : Product
> {
>
> public MyProductItem() : this(string.Empty, string.Empty)
> {
> }
>
> public MyProductItem(string _productId, string _catalog)
> {
> if (string.IsNullOrEmpty(_productId) ||
> string.IsNullOrEmpty(_catalog))
> {
> throw new ArgumentNullException("Invalid Parameters");
> }
>
> this = CommerceContext.Current.CatalogSystem.GetProduct(_catalog,
> _productId);
> }
> }
>
> I am not sure if deriving from a class such the Product Class is a safe
> procedure.
> Any ideas regarding this issue
>
> Thanks
> Steve
| |
|
| Joseph,
I understand what you're referring to. It's simply like what MSCS team did
with the StarterSite when they extended the Basket class to create a new
class called "BasketHelper" that includes same and custom added
functions/properties as the ones in Basket class
I wanted however to know whether the product class can be extended like the
"LineItem" class which MS has already provided a source for a class
"MyLineItem" derived from the "LineItem". But I guess that's not the case.
Now I know this not a MSCS question but a C#/.net question. However, why
would the error "CS0143: The type 'Microsoft.CommerceServer.Catalog.Product'
has no constructors defined" exists if I am providing my custom constructor
?? What if I could override the product class original constructor ??
"Joseph Johnson" wrote:
> Steve,
>
> I've had similiar issues attempting to inherit from other classes which do
> not expose a constructor (specifically, the Basket class).
>
> The only solution I've ever really seen for this is to use a wrapper pattern
> around the product instead of inheriting from it. This isn't nearly as
> convenient, and it's annoying to maintain, but I think it's the only design
> pattern you can use for something like this. So, using the wrapper pattern,
> your code would look as follows (also included your Weight property):
>
> public class MyProductItem
> {
>
> private Product;
>
> public MyProductItem(string _productId, string _catalog)
> {
> if (string.IsNullOrEmpty(_productId) ||
> string.IsNullOrEmpty(_catalog))
> {
> throw new ArgumentNullException("Invalid Parameters");
> }
>
> Product = CommerceContext.Current.CatalogSystem.GetProduct(_catalog,
> _productId);
> }
>
> public object Weight
> {
> get {return Product["Weight"];}
> set {Product["Weight"] = value;}
> }
> }
>
> Again, not as elegant as inheritance, but if you need to apply custom logic
> around the normal API objects, this is one way of doing it.
>
> Joe
>
> "Steve" <Steve@discussions.microsoft.com> wrote in message
> news:B271E39F-A24C-4163-95AF-2EAE9FEF89A7@microsoft.com...
>
>
>
| |
| Sudha Raghavan [MSFT] 2006-09-26, 1:19 pm |
| To answer your question on
The type 'Microsoft.CommerceServer.Catalog.Product'
has no constructors defined" exists if I am providing my custom constructor
?? What if I could override the product class original constructor ??
Any derived class would try to call the default constructor of the base
class before calling the derived class constructor. If the base class does
not expose a public default constructor, you would get the above error.
Thanks
Sudha
--------------------
Thread-Topic: Extending/Deriving Product Class
thread-index: AcbhVTCTTnWWjvdfT8KRNwr7ZBKa0w==
X-WBNR-Posting-Host: 80.81.159.10
From: =?Utf-8?B?U3RldmU=?= <Steve@discussions.microsoft.com>
References: <B271E39F-A24C-4163-95AF-2EAE9FEF89A7@microsoft.com>
<uzR7LTL4GHA.3476@TK2MSFTNGP04.phx.gbl>
Subject: Re: Extending/Deriving Product Class
Date: Tue, 26 Sep 2006 03:19:03 -0700
Lines: 105
Message-ID: <E2A5F1B1-D570-43DB-BEB6-26586290F738@microsoft.com>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
Newsgroups: microsoft.public.commerceserver.general
Path: TK2MSFTNGXA01.phx.gbl
Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.commerceserver.general:18534
NNTP-Posting-Host: TK2MSFTNGXA01.phx.gbl 10.40.2.250
X-Tomcat-NG: microsoft.public.commerceserver.general
Joseph,
I understand what you're referring to. It's simply like what MSCS team did
with the StarterSite when they extended the Basket class to create a new
class called "BasketHelper" that includes same and custom added
functions/properties as the ones in Basket class
I wanted however to know whether the product class can be extended like the
"LineItem" class which MS has already provided a source for a class
"MyLineItem" derived from the "LineItem". But I guess that's not the case.
Now I know this not a MSCS question but a C#/.net question. However, why
would the error "CS0143: The type
'Microsoft.CommerceServer.Catalog.Product'
has no constructors defined" exists if I am providing my custom constructor
?? What if I could override the product class original constructor ??
"Joseph Johnson" wrote:
> Steve,
>
> I've had similiar issues attempting to inherit from other classes which
do
> not expose a constructor (specifically, the Basket class).
>
> The only solution I've ever really seen for this is to use a wrapper
pattern
> around the product instead of inheriting from it. This isn't nearly as
> convenient, and it's annoying to maintain, but I think it's the only
design
> pattern you can use for something like this. So, using the wrapper
pattern,
> your code would look as follows (also included your Weight property):
>
> public class MyProductItem
> {
>
> private Product;
>
> public MyProductItem(string _productId, string _catalog)
> {
> if (string.IsNullOrEmpty(_productId) ||
> string.IsNullOrEmpty(_catalog))
> {
> throw new ArgumentNullException("Invalid Parameters");
> }
>
> Product =
CommerceContext.Current.CatalogSystem.GetProduct(_catalog,
> _productId);
> }
>
> public object Weight
> {
> get {return Product["Weight"];}
> set {Product["Weight"] = value;}
> }
> }
>
> Again, not as elegant as inheritance, but if you need to apply custom
logic
> around the normal API objects, this is one way of doing it.
>
> Joe
>
> "Steve" <Steve@discussions.microsoft.com> wrote in message
> news:B271E39F-A24C-4163-95AF-2EAE9FEF89A7@microsoft.com...
=[vbcol=seagreen]
be[vbcol=seagreen]
>
>
>
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. © 2005 Microsoft Corporation. All rights
reserved.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
Have a Commerce Server “How To” question? Help is a click away at our
Chats, Newsgroups and Web logs
Chats (2nd Wednesday of the month from 11 to Noon):
http://www.msdn.microsoft.com/chats/
Public newsgroups:
http://www.microsoft.com/technet/co...r/commerce.mspx
Web logs and community:
http://www.microsoft.com/commercese...ty/default.mspx
Other resources:
http://www.microsoft.com/technet/pr...02/default.mspx
|
|
|
|
|