Skip to content

Commit

Permalink
Try to resolve issue #44 via wrapper for objects that don't properly …
Browse files Browse the repository at this point in the history
…implement COM compatibility
  • Loading branch information
rhuijben committed May 2, 2022
1 parent 980004b commit 65075f6
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/Ankh.Scc/Native/ICOMPropertyBag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal PropertyBag(ICOMPropertyBag bag)

[CLSCompliant(false)]
public PropertyBag(IPropertyBag bag)
: this((ICOMPropertyBag)bag)
: this(bag as ICOMPropertyBag ?? new MyComPropertyBag(bag))
{
}

Expand Down Expand Up @@ -162,5 +162,41 @@ public bool WrittenKey(string key)
{
return _toWrite.ContainsKey(key);
}

private sealed class MyComPropertyBag : ICOMPropertyBag
{
private readonly IPropertyBag _bag;

public MyComPropertyBag(IPropertyBag bag)
{
this._bag = bag;
}
public int Read(string pszPropName, out object pVar, IErrorLog pErrorLog, uint VARTYPE, object pUnkObj)
{
try
{
_bag.Read(pszPropName, out pVar, pErrorLog, VARTYPE, pUnkObj);
return VSConstants.S_OK;
}
catch(Exception e)
{
pVar = null;
return Marshal.GetHRForException(e);
}
}

public int Write(string pszPropName, ref object pVar)
{
try
{
_bag.Write(pszPropName, pVar);
return VSConstants.S_OK;
}
catch (Exception e)
{
return Marshal.GetHRForException(e);
}
}
}
}
}

0 comments on commit 65075f6

Please sign in to comment.