将两个 lambda 转换为读/写属性访问器的绑定器。 lambda 必须保留通过值捕获所引用的外部对象的引用。
用法:BindProperty(get_lambda、set_lambda)
语法
Microsoft::WRL::ComPtr<IModelPropertyAccessor> BindProperty(
const TGet & getFunctor,
const TSet & setFunctor
);
参数
getFunctor
签名的 functor(PCWSTR,IModelObject *, IModelObject **),它将充当新创建的属性访问器的 getter。
setFunctor
签名(PCWSTR、IModelObject *、IModelObject *)的 functor,它将充当新创建的属性访问器的 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 |