BindProperty 函式(get_lambda,set_lambda)(dbgmodel.h)
將兩個 Lambda 轉換成讀取/寫入屬性存取子的系結器。 Lambda 必須在透過值擷取所參考的外部物件上保存參考。
使用方式:BindProperty(get_lambda,set_lambda)
語法
Microsoft::WRL::ComPtr<IModelPropertyAccessor> BindProperty(
const TGet & getFunctor,
const TSet & setFunctor
);
參數
getFunctor
簽章的函式 (PCWSTR, IModelObject *, IModelObject **) 的函式,將做為新建立之屬性存取子的 getter。
setFunctor
簽章的函式 (PCWSTR, IModelObject *, IModelObject *) 的函式,做為新建立之屬性存取子的 setter。
傳回值
此函式會傳回 Microsoft::WRL::ComPtr<IModelPropertyAccessor>。
言論
此範例程式代碼會顯示使用方式。
// Define a native type that we wish to project into the data model
struct MyNativeType
{
std::wstring Name;
int Id;
int WriteableValue;
};
// Declare a type factory for the type
class MyNativeTypeFactory : public TypedInstanceModel<MyNativeType>
{
public:
MyNativeTypeFactory()
{
BindReadOnlyProperty(L"Name", &MyNativeType::Name);
BindReadOnlyProperty(L"Id", &MyNativeType::Id);
BindProperty(L"WriteableValue", &MyNativeType::WriteableValue);
}
};
// Create the type factory and make an instance
MyNativeTypeFactory factory;
Object instance = factory.CreateInstance(MyNativeType { L"Foo", 42, 37 });
// There are "Name/Id" read-only properties on instance and a "WriteableValue" property.
要求
要求 | 價值 |
---|---|
標頭 | dbgmodel.h |