2017-02-16 91 views
0

我用asp.net MVC應用程序並在該應用有一個接口擴展接口,如果接口是外部DLL

但該接口是一個第三方的DLL工作。所以我不能修改界面。

#region Assembly Sana.Commerce, Version=9.1.3.0, Culture=neutral, PublicKeyToken=2b26dc7ce8e04e9f 
// D:\visualstudio2015\Sana Training\SDK\SDK\Libraries\Sana.Commerce.dll 
#endregion 

using System; 
using System.Collections.Generic; 
using Sana.Commerce.Customer; 
using Sana.Commerce.Shop; 

namespace Sana.Commerce.Order 
{ 
    // 
    // Summary: 
    //  This interface represents an order in the ERP system. This can be an order that 
    //  still has to be placed or an order that is already in the ERP (for example order 
    //  history). There are several types of orders like regular orders, invoice and 
    //  quotes. The type of order is stored in the document type property. 
    public interface IOrder : IEntity, IVersionedItem 
    { 
     // 
     // Summary: 
     //  ID of the account that placed the order. 
     string AccountId { get; set; } 
     // 
     // Summary: 
     //  The type of account that placed this order. 
     AccountType AccountType { get; set; } 
     // 
     // Summary: 
     //  Gets or sets the list of order attachments. 
     IList<IAttachment> Attachments { get; set; } 
     // 
     // Summary: 
     //  Gets or sets the status of order authorization. 
     OrderAuthorizationStatus AuthorizationStatus { get; set; } 
     // 
     // Summary: 
     //  Address that will recieve the invoice. 
     ICustomerAddress BillingAddress { get; set; } 
     // 
     // Summary: 
     //  Gets or sets bill-to name. 
     string BillToName { get; set; } 
     // 
     // Summary: 
     //  Gets or sets the comment. 
     string Comment { get; set; } 
     // 
     // Summary: 
     //  Name of the Contact that placed this order. 
     string Contact { get; set; } 
     // 
     // Summary: 
     //  ID of the Contact that placed this order. 
     string ContactId { get; set; } 
    } 
} 

但在IOrder我已經把一個額外的屬性ProjectNumber

但如何擴展IOrder接口,如果它在另一個DLL?

我嘗試這樣的:

public interface IOrderProjectNumber:IOrder 
{ 
    string ProjectNumber { get; set; } 

} 

但後來我有一個方法,像這樣:

public override IOrder SaveOrder(IOrder order) 
{ 

    IOrderProjectNumber orderNumber= new OrderoverviewModel_ProjectNumber(); 
    orderNumber.ProjectNumber = "hallo";  

    return base.SaveOrder(order); 
} 

所以我改變方法,採用這樣的:

public override IOrder SaveOrder(IOrderProjectNumber order) 
{ 

    IOrderProjectNumber orderNumber= new OrderoverviewModel_ProjectNumber(); 
    orderNumber.ProjectNumber = "hallo";  

    return base.SaveOrder(order); 
} 

但那麼我得到的錯誤:

Code Description Project File Line Column Suppression State CS0115 'ExtendedOrderManager.SaveOrder(IOrderProjectNumber)': no suitable method found to override Sana.Commerce.Sdk D:\visualstudio2015\Sana Training\SDK\SDK\Sana.Commerce.Sdk\Customization\Order\ExtendedOrderManager.cs 19 32 Active

它將被保存,如XML:

<Order> 
    <field name="BlanketOrderId" type="System.String, mscorlib" storeWithEntity="True"> 
    <string>BO1</string> 
    </field> 
    <field name="CustomField" type="System.String, mscorlib" storeWithEntity="False"> 
    <string>myvalue</string> 
    </field> 
    <field name="PaymentStatus" type="System.String, mscorlib"> 
    <string>new</string> 
    </field> 
    <field name="ProjectNumber" type="Null" /> 
    <field name="BillingAddress" type="Sana.Commerce.Customer.CustomerAddress, Sana.Commerce.Sdk"> 
    <CustomerAddress> 
     <field name="CustomerId" type="System.String, mscorlib"> 
     <string>01454545</string> 
     </field> 
     <field name="Address" type="System.String, mscorlib"> 
     <string>705 West Peachtree Street</string> 
     </field> 
     <field name="Address2" type="System.String, mscorlib"> 
     <string /> 
     </field> 
     <field name="ZipCode" type="System.String, mscorlib"> 
     <string>US-GA 31772</string> 
     </field> 
     <field name="City" type="System.String, mscorlib"> 
     <string>Atlanta</string> 
     </field> 
     <field name="CountryId" type="System.String, mscorlib"> 
     <string>US</string> 
     </field> 
     <field name="CountryName" type="System.String, mscorlib"> 
     <string>Verenigde Staten</string> 
     </field> 
     <field name="State" type="System.String, mscorlib"> 
     <string /> 
     </field> 
     <field name="PhoneNo" type="System.String, mscorlib"> 
     <string /> 
     </field> 
     <field name="FaxNo" type="System.String, mscorlib"> 
     <string /> 
     </field> 
     <field name="Contact" type="System.String, mscorlib"> 
     <string>Ms. Tammy L. McDonald</string> 
     </field> 
     <field name="ContactId" type="Null" /> 
     <field name="Name" type="System.String, mscorlib"> 
     <string>New Concepts Furniture</string> 
     </field> 
     <field name="Id" type="Null" /> 
     <field name="WebsiteId" type="Null" /> 
    </CustomerAddress> 
    </field> 

,並在Order類。我把額外的特性:

​​

該系統與依賴注入和您註冊您的模型和控制器的地方。註冊新課程將在Addone類來完成,像這樣:

public class Addon : IAddon 
    { 
     public int Order 
     { 
      get { return 0; } 
     } 

     public void Initialize() 
     { 
      ObjectManager.RegisterType<IController, ReturnOrdersController>("ReturnOrders"); 
      ObjectManager.RegisterType<OrderOverviewModel, OrderoverviewModel_ProjectNumber>(); 
     } 
    } 

,這是OrderoverViewModel:

// 
    // Summary: 
    //  The order overview page model. 
    public class OrderOverviewModel : CheckoutBaseViewModel 
    { 
     public OrderOverviewModel(); 

     // 
     // Summary: 
     //  Gets or sets a value indicating that the terms and conditions is confirmed. 
     [MustBeTrue(ErrorMessageResourceName = "OrderOverview_AgreeTermsError")] 
     public virtual System.Boolean AcceptTerms { get; set; } 
     // 
     // Summary: 
     //  Gets or sets the comments. 
     [AllowHtml] 
     [DataType(DataType.MultilineText)] 
     [Display(Name = "Comments")] 
     [MaxLength(2048, ErrorMessageResourceName = "Validation_MaxLength")] 
     public virtual System.String Comments { get; set; } 
     // 
     // Summary: 
     //  Gets or sets the delivery date. 
     [Display(Name = "RequestedDeliveryDate")] 
     [GreaterThanToday(ErrorMessageResourceName = "Validation_InvalidField")] 
     public virtual Date? DeliveryDate { get; set; } 
     // 
     // Summary: 
     //  Gets or sets a value indicating that the order will be paid online. 
     public virtual System.Boolean IsPaidOnline { get; set; } 
     // 
     // Summary: 
     //  Gets or sets the reference number. 
     [AllowHtml] 
     [Display(Name = "ReferenceNumber")] 
     [MaxLength(20, ErrorMessageResourceName = "Validation_MaxLength")] 
     public virtual System.String ReferenceNumber { get; set; } 
     // 
     // Summary: 
     //  Gets or sets a value indicating whether additional information will be visible. 
     public virtual System.Boolean ShowAdditionalInformation { get; set; } 

     // 
     // Summary: 
     //  Applies the model changes to the specified basket. 
     // 
     // Parameters: 
     // basket: 
     //  The basket to update. 
     // 
     // Returns: 
     //  Returns a value indicating whether any changes have been done to the basket. 
     public virtual System.Boolean ApplyChanges(IBasket basket); 
     // 
     // Summary: 
     //  Initializes the model using the specified basket. 
     // 
     // Parameters: 
     // basket: 
     //  The basket. 
     public virtual void Initialize(IBasket basket); 
     // 
     // Summary: 
     //  Initializes the model. 
     // 
     // Parameters: 
     // context: 
     //  The shop context. 
     // 
     // generalInfo: 
     //  The checkout general info model. 
     public virtual void InitializeGeneral(ShopContext context, CheckoutGeneralInfo generalInfo); 
    } 

這仍然是空:

public interface IOrderProjectNumber : IOrder 
    { 
     string ProjectNumber { get; set; } 
     //public virtual IOrder SaveOrder(IOrder order); 

    } 

var orderObject = order as DomainModel.Order.IOrderProjectNumber; 

orderObject仍然是空。我不明白這一點。

+0

你必須使用指定的IOrder接口?你可以改爲subclas並在你的子類接口中聲明你需要的成員。 –

+0

謝謝。我更新了帖子 –

+0

您無法用其他類型參數覆蓋。你還必須接受'IOrder'。您可以通過檢查它是否實現該接口來爲重寫的方法中的其他接口「搜索」,但不幸的是,您不能*要求參數是您的新接口類型。總之,你不能真正得到你想要的完整型安全。 –

回答

0

你SaveOrder方法應該是這樣的:

public override IOrder SaveOrder(IOrder order) 
{  
    var orderObject = order as Order; 

    if(orderObject != null) 
    { 
     orderObject.ProjectNumber = "hallo";  
    } 

    return base.SaveOrder(order); 
} 
+0

謝謝你的評論。但是orderNumber現在爲空 –

+0

仍爲空我的意思是 –

+0

我也更新了文章 –