If we take a look at the documentation (or here), it really doesn't show any constructors for the type Microsoft.Exchange.WebServices.Data.Item
, but, if you take a look at all the types inherited from Item
, they all implement the following constructor:
public InheritedFromItem(
ExchangeService service
)
So I would guess that maybe you should implement it too.
Just confirmed looking the source code of Item
type:
ews-managed-api/Item.cs at master · OfficeDev/ews-managed-api - GitHub
https://github.com/OfficeDev/ews-managed-api/blob/master/Core/ServiceObjects/Items/Item.cs
namespace Microsoft.Exchange.WebServices.Data
{
using System;
using System.Collections.Generic;
using System.Linq;
/// <summary>
/// Represents a generic item. Properties available on items are defined in the ItemSchema class.
/// </summary>
[Attachable]
[ServiceObjectDefinition(XmlElementNames.Item)]
public class Item : ServiceObject
{
private ItemAttachment parentAttachment;
/// <summary>
/// Initializes an unsaved local instance of <see cref="Item"/>. To bind to an existing item, use Item.Bind() instead.
/// </summary>
/// <param name="service">The ExchangeService object to which the item will be bound.</param>
internal Item(ExchangeService service)
: base(service)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Item"/> class.
/// </summary>
/// <param name="parentAttachment">The parent attachment.</param>
internal Item(ItemAttachment parentAttachment)
: this(parentAttachment.Service)
{
// [...]
}
// [...]
See that it actually has two internal constructors, one receiving an ExchangeService
object and the other an ItemAttachment
object.
Taking a look in Contact
, that inherits from Item
, as an example, it implements the ExchangeService
constructor as public and the ItemAttachment
constructor as internal:
ews-managed-api/Contact.cs at master · OfficeDev/ews-managed-api - GitHub
https://github.com/OfficeDev/ews-managed-api/blob/master/Core/ServiceObjects/Items/Contact.cs
namespace Microsoft.Exchange.WebServices.Data
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
/// <summary>
/// Represents a contact. Properties available on contacts are defined in the ContactSchema class.
/// </summary>
[Attachable]
[ServiceObjectDefinition(XmlElementNames.Contact)]
public class Contact : Item
{
private const string ContactPictureName = "ContactPicture.jpg";
/// <summary>
/// Initializes an unsaved local instance of <see cref="Contact"/>. To bind to an existing contact, use Contact.Bind() instead.
/// </summary>
/// <param name="service">The ExchangeService object to which the contact will be bound.</param>
public Contact(ExchangeService service)
: base(service)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Contact"/> class.
/// </summary>
/// <param name="parentAttachment">The parent attachment.</param>
internal Contact(ItemAttachment parentAttachment)
: base(parentAttachment)
{
}
// [...]
So, try to mimic that on your code:
using Microsoft.Exchange.WebServices.Data;
public class ItemEx : Item
{
public ItemEx(ExchangeService service)
: base(service)
{
}
internal ItemEx(ItemAttachment parentAttachment)
: base(parentAttachment)
{
}
}
But then you cannot instantiate an object of your class like this:
ItemEx myItem = new ItemEx();
You should do it like this:
ExchangeService service = new ExchangeService();
ItemEx myItem = new ItemEx(service);
UPDATE
Sorry for my previous ignorance. The internal access modifier on the constructors of Item
class makes them accessible only within files in the same assembly.
So, that means that this Item
class cannot be subclassed / inherited from others, outside Microsoft.Exchange.WebServices.dll
assembly. Some reference: