C# 将属性添加到框架类



>我使用 Lync SDK 2013 并希望扩展特定的类Contact。联系人对象能够通过以下方式获取显示的名称

string displayName = contact.GetContactInformation(ContactInformationType.DisplayName);

我想创建一个名为User的新类来扩展这个联系类。例如,User将有一个属性

public object DisplayName { get { return GetContactInformation(ContactInformationType.DisplayName); } }

其他人只需要写

user.DisplayName

以获取联系人的显示名称。不幸的是,从Contact继承时我必须设置一个构造函数

public User() : base()
{
}

Contact的构造函数需要一些参数。但是我不明白基构造函数需要哪些参数。

是否可以在不知道参数的情况下编写"使用相同的构造函数"?

否则我不知道在哪里可以找到构造函数

#region Assembly Microsoft.Lync.Model, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c
// projectPathpackagesLync2013SDK.15.0.4466.1000libnet40Microsoft.Lync.Model.dll
#endregion
using System;
using System.Collections.Generic;
using Microsoft.Lync.Model.Conversation;
using Microsoft.Lync.Model.Group;
using Microsoft.Lync.Model.Internal;
namespace Microsoft.Lync.Model
{
//
// Summary:
//     Represents a contact within the Lync client. A contact can be person, bot or
//     phone number.
public class Contact : UCWFull
{
//
~Contact();
//
// Summary:
//     Gets the contact URI.
public string Uri { get; }
//
// Summary:
//     Returns the Unified Communication type of this contact.
public UnifiedCommunicationType UnifiedCommunicationType { get; }
//
// Summary:
//     Gets a collection of contact settings.
public IDictionary<ContactSetting, object> Settings { get; }
//
// Summary:
//     Gets the list of all groups of which this contact is a member of.
public GroupCollection CustomGroups { get; }
//
// Summary:
//     Gets the parent Contact and Group Manager of this contact.
public ContactManager ContactManager { get; }
//
// Summary:
//     Occurs when one or more pieces of contact information are changed.
//
// Hints:
//     Application logic must subscribe to contact information publication before the
//     ContactInformationChanged event can be received. Call the CreateSubscription
//     method on the ContactManager object and then add the Contact to be subscribed
//     and the ContactInformationTypes that you are interested in. Finally, call the
//     Subscribe method on the ContactSubscription object.
public event EventHandler<ContactInformationChangedEventArgs> ContactInformationChanged;
//
// Summary:
//     Occurs when the value of a contact property changes.
public event EventHandler<ContactSettingChangedEventArgs> SettingChanged;
//
// Summary:
//     Occurs when the contact URI is changed.
public event EventHandler<UriChangedEventArgs> UriChanged;
//
// Summary:
//     Sets a setting associated with this contact.
public IAsyncResult BeginChangeSetting(ContactSetting contactSettingType, object contactSettingValue, AsyncCallback contactCallback, object state);
//
// Summary:
//     Gets the Organization Info of this contact.
public IAsyncResult BeginGetOrganizationInformation(OrganizationStructureTypes orgInfoTypes, AsyncCallback contactCallback, object state);
//
// Summary:
//     Moves this contact from a source group to a target group.
public IAsyncResult BeginMoveToGroup(Group.Group targetGroup, Group.Group sourceGroup, AsyncCallback contactCallback, object state);
//
// Summary:
//     Checks if the setting can be set for this contact.
//
// Returns:
//     System.Boolean
public bool CanChangeSetting(ContactSetting contactSetting);
//
// Summary:
//     Checks if this contact can be moved from a source group to a target group.
//
// Returns:
//     System.Boolean
public bool CanMoveToGroup(Group.Group targetGroup, Group.Group sourceGroup);
//
// Summary:
//     Checks if this contact can start a given mode of communication (modality
//
// Returns:
//     System.Boolean
public bool CanStart(ModalityTypes modalityTypes);
//
// Summary:
//     Creates a collaboration endpoint object from a telephone number.
public ContactEndpoint CreateContactEndpoint(string telephoneUri);
//
// Summary:
//     Sets a setting associated with this contact.
public void EndChangeSetting(IAsyncResult asyncResult);
//
// Summary:
//     Gets the Organization Info of this contact.
public void EndGetOrganizationInformation(out ContactCollection managers, out ContactCollection peers, out ContactCollection directors, IAsyncResult asyncResult);
//
// Summary:
//     Moves this contact from a source group to a target group.
public void EndMoveToGroup(IAsyncResult asyncResult);
//
// Summary:
//     Gets a single contact information from this contact.
//
// Returns:
//     System.Object
public object GetContactInformation(ContactInformationType contactInformationType);
//
// Summary:
//     Gets contact information from this contact.
public IDictionary<ContactInformationType, object> GetContactInformation(IEnumerable<ContactInformationType> contactInformationTypes);
}
}

您没有考虑从类继承,而是考虑创建扩展方法

public static string DisplayName(this Contact contact)
{
return contact.GetContactInformation(ContactInformationType.DisplayName).ToString();
}

最新更新