我正在开发一个项目,它是一个相当大的经典ASP项目的.NET扩展,使用了许多C++ COM对象,这些对象永远存在于我们的代码库中.不幸的是,在C++方面有很多hack-ish代码,我担心我没有足够的经验来解决我遇到的问题.
简而言之,我可以实例化有问题的COM对象,Visual Studio告诉我,我应该能够调用它的"方法"(在引号中,因为它们实际上是作为参数化属性公开的).但是,我尝试调用的任何方法都给出了错误"索引属性'CoreAspLib.IComUser.LoginUser'具有必须提供的非可选参数." 问题是,我使用的是与传统ASP世界中使用的完全相同的参数,甚至属性的IntelliSense帮助告诉我我正在使用正确的参数集.例如,"LoginUser"属性的签名是"dynamic IComUser.get_LoginUser(string username,string password)",我用两个字符串调用它,但我仍然得到"非可选参数"错误.
这是一些相关的代码 - 首先,我正在尝试进行方法调用的类.CComUtils
是一个辅助类,它只接受COM的GUID和对目标对象的引用,创建所需COM对象的实例,并将目标引用分配给新对象.
public static class CurrentUser
{
public static void Authenticate(string userName, string password)
{
CoreAspLib.ComUser userObject = Cache.Request<CoreAspLib.ComUser>("UserComObject");
if (userObject == null) {
Guid userGuid = new Guid("BF748C0A-450D-4EAF-8C39-A36F6B455587");
CComUtils.CreateCOMInstance(userGuid, ref userObject);
Cache.Request("UserComObject", userObject);
}
var result = userObject.LoginUser(sUserName:"foo", sPassword:"bar");
if (result.Failed) {
throw (new System.Security.Authentication.InvalidCredentialException("Bad username or password".tr()));
} else {
FormsAuthentication.SetAuthCookie(userName, false);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是COM对象源的实际方法签名:
STDMETHODIMP CComUser::get_LoginUser(BSTR bsUserName, BSTR bsPassword, IDispatch ** pResult)
Run Code Online (Sandbox Code Playgroud)
这是IDL的接口定义:
[
object, …
Run Code Online (Sandbox Code Playgroud) 我有两个 Lit 元素 Web 组件 - 一个是units-list
,其中包含许多units-list-item
元素。这些units-list-item
元素有两种不同的显示模式:紧凑和详细。因为列表元素支持无限滚动(因此可能包含数千个单位),我们需要任何在两种模式之间切换的机制来尽可能提高性能。
这就是为什么我认为一个理想的解决方案是:host-context()
在units-list-item
元素的样式中使用伪选择器,因为这样每个units-list-item
元素都可以通过更改应用于祖先的类(这将在阴影内)在两种显示模式之间切换units-list
元素的DOM )。
详细说明,这里是units-list
元素的相关标记。请注意,“触发器”类正在应用于#list-contents
div,它是units-list
模板的一部分。
<div id="list-contents" class="${showDetails ? 'detail-view table' : 'compact-view table'}">
${units.map(unit => html`<units-list-item .unit="${unit}"></units-list-item>`)}
</div>
Run Code Online (Sandbox Code Playgroud)
如您所见,该showDetails
标志控制是将“detail-view”还是“compact-view”类应用于包含所有units-list-item
元素的 div 。这些类肯定被正确应用。
这是units-list-item
元素的完整渲染方法(删除了不必要的标记):
render() {
const {unit} = this;
// the style token below injects the processed stylesheet contents into the template
return html`
${style}
<div class="row compact">
<!-- …
Run Code Online (Sandbox Code Playgroud)