我正在使用Microsoft Exchange Web服務(EWS)託管API 1.2從使用C3的Exchange郵箱訪問數據。返回的對象的某些屬性很難訪問,因爲它們是自定義屬性。函數返回類型A,使其類型B(從A繼承)
爲了簡化訪問這些屬性,我寫了一個名爲Contact2的類,它擴展了EWS給我的Contact類。
當調用一個返回Contact對象的函數時,如何將其升級到Contact2?
這裏是Contact2 I類寫道:
namespace ExchangeContacts
{
class Contact2 : Microsoft.Exchange.WebServices.Data.Contact
{
public ExchangeService ex = new ExchangeService();
public Dictionary<string, ExtendedPropertyDefinition> propDefs = new Dictionary<string, ExtendedPropertyDefinition>();
public PropertySet myPropSet = new PropertySet();
public Contact2(ExchangeService service)
: base(service)
{
propDefs.Add("MarketingGuid", new ExtendedPropertyDefinition(new Guid("3694fe54-daf0-49bf-9e37-734cfb8521e1"), "MarketingGuid", MapiPropertyType.String));
myPropSet = new PropertySet(BasePropertySet.FirstClassProperties) { propDefs["MarketingGuid"] };
ex = service;
}
new public void Load()
{
base.Load(myPropSet);
}
new public void Load(PropertySet propertySet)
{
propertySet.Add(propDefs["MarketingGuid"]);
base.Load(propertySet);
}
public string MarketingGuid
{
get
{
string g;
if (TryGetProperty(propDefs["MarketingGuid"], out g))
return g;
else
return "";
}
set
{
SetExtendedProperty(propDefs["MarketingGuid"], value);
}
}
}
}
如何包裝現有的聯繫人實例?我發現的所有示例代碼只是將Contact對象分配給Contact2對象的屬性。有沒有辦法來包裝它,以便我不必通過Contact2對象的屬性調用方法和屬性? – longneck
@longneck:您可以將屬性和方法添加到'Contact2',以傳遞給'Contact'中的屬性和方法。 – SLaks