C# 向框架添加属性 class
C# add properties to framework class
我使用 Lync SDK 2013 并希望扩展特定的 class Contact
。联系人对象可以使用
获取显示名称
string displayName = contact.GetContactInformation(ContactInformationType.DisplayName);
我想创建一个名为 User
的新 class 来扩展此联系人 class。例如 User
会有 属性
public object DisplayName { get { return GetContactInformation(ContactInformationType.DisplayName); } }
别人只需要写
user.DisplayName
获取联系人的显示名称。不幸的是,从 Contact
继承时我必须设置一个构造函数
public User() : base()
{
}
Contact 的构造函数接受一些参数。但是我不知道基本构造函数需要哪些参数。
是否可以在不知道参数的情况下写成"use the same constructor"?
不然我这里不知道构造函数在哪里找
#region Assembly Microsoft.Lync.Model, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c
// projectPath\packages\Lync2013SDK.15.0.4466.1000\lib\net40\Microsoft.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);
}
}
您是否考虑过创建 extension method
而不是从 class 继承
public static string DisplayName(this Contact contact)
{
return contact.GetContactInformation(ContactInformationType.DisplayName).ToString();
}
我使用 Lync SDK 2013 并希望扩展特定的 class Contact
。联系人对象可以使用
string displayName = contact.GetContactInformation(ContactInformationType.DisplayName);
我想创建一个名为 User
的新 class 来扩展此联系人 class。例如 User
会有 属性
public object DisplayName { get { return GetContactInformation(ContactInformationType.DisplayName); } }
别人只需要写
user.DisplayName
获取联系人的显示名称。不幸的是,从 Contact
public User() : base()
{
}
Contact 的构造函数接受一些参数。但是我不知道基本构造函数需要哪些参数。
是否可以在不知道参数的情况下写成"use the same constructor"?
不然我这里不知道构造函数在哪里找
#region Assembly Microsoft.Lync.Model, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c
// projectPath\packages\Lync2013SDK.15.0.4466.1000\lib\net40\Microsoft.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);
}
}
您是否考虑过创建 extension method
而不是从 class 继承public static string DisplayName(this Contact contact)
{
return contact.GetContactInformation(ContactInformationType.DisplayName).ToString();
}