Dear All,
I eventually found out my own way of doing the proxy without using a wrapper class. (with some helps from proxygen, but will require one to edit and append some codes into the generated file)
Step 1:
For example, the proxy is generated using MyApplication.UI assembly, If I were to add an external type that was in MyApplication.DAL assembly, I create this class in my proxy.cs file.
Eg.
public partial class MyBaseClass : global::Microsoft.VisualStudio.Tools.Applications.IProxy
{
private global::Microsoft.VisualStudio.Tools.Applications.RemoteObject remoteObject;
private global::System.Type remoteType;
private global::System.Reflection.MemberInfo @__vstaCacheMyBaseVar01;
internal virtual global::System.Type RemoteType
{
get
{
return remoteType;
}
set
{
if (remoteType == null)
{
remoteType = value;
if (string.CompareOrdinal(remoteType.FullName, "MyApplication.DAL.MyBaseClass") != 0)
{
remoteType = remoteType.BaseType;
}
}
}
}
protected virtual string PrimaryCookie
{
get
{
return "";
}
}
global::System.AddIn.Contract.IContract global::Microsoft.VisualStudio.Tools.Applications.IProxy.Contract
{
get
{
return ((global::Microsoft.VisualStudio.Tools.Applications.IProxy)this.RemoteObject).Contract;
}
}
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
[global::System.ComponentModel.BrowsableAttribute(false)]
public MyBaseClass()
{
}
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
[global::System.ComponentModel.BrowsableAttribute(false)]
public MyBaseClass(global::System.AddIn.Contract.IContract contract, global::Microsoft.VisualStudio.Tools.Applications.TypeInfrastructureManager typeInfrastructureManager)
{
this.remoteObject = null;
if (contract == null)
throw new global::System.ArgumentNullException("contract");
if (typeInfrastructureManager == null)
throw new global::System.ArgumentNullException("typeInfrastructureManager");
global::System.AddIn.Contract.Automation.IRemoteObjectContract remoteObjectContract =
(global::System.AddIn.Contract.Automation.IRemoteObjectContract)contract.QueryContract(typeof(global::System.AddIn.Contract.Automation.IRemoteObjectContract).AssemblyQualifiedName);
remoteType = null;
this.RemoteObject = new global::Microsoft.VisualStudio.Tools.Applications.RemoteObject(remoteObjectContract, typeInfrastructureManager);
this.RemoteType = this.RemoteObject.GetType();
}
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
[global::System.ComponentModel.BrowsableAttribute(false)]
protected virtual global::Microsoft.VisualStudio.Tools.Applications.RemoteObject RemoteObject
{
get
{
return this.remoteObject;
}
set
{
this.remoteObject = value;
}
}
public int MyBaseVar
{
get
{
object[] _param = new object[0];
int retVal_param;
if ((this.@__vstaCacheMyBaseVar01 == null))
{
this.@__vstaCacheMyBaseVar01 = this.remoteType.GetProperty("MyBaseVar", (((global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance)
| global::System.Reflection.BindingFlags.GetProperty)
| global::System.Reflection.BindingFlags.Default), null, typeof(int), new global::System.Type[0], null);
}
retVal_param = ((int)(((global::System.Reflection.PropertyInfo)(this.@__vstaCacheMyBaseVar01)).GetValue(this, _param)));
return retVal_param;
}
}
}
Step 2:
Ensure it has been added into the TypesMap in this function.
public static global::Microsoft.VisualStudio.Tools.Applications.TypeInfrastructureManager AddTypesToMap(global::Microsoft.VisualStudio.Tools.Applications.TypeInfrastructureManager typeInfrastructureManager).
Example: (Lines in Bold)
namespace Microsoft.VisualStudio.Tools.Applications.ProxyServices.Helper {
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
[global::System.ComponentModel.BrowsableAttribute(false)]
public sealed partial class CMyApplication_UIInitializer {
public static global::Microsoft.VisualStudio.Tools.Applications.TypeInfrastructureManager AddTypesToMap(global::Microsoft.VisualStudio.Tools.Applications.TypeInfrastructureManager typeInfrastructureManager) {
typeInfrastructureManager.CanonicalNameToTypeMap.Add("MyApplication.UI, MyApplication.UI.ApplicationModel", typeof(global::MyApplication.Proxy.ApplicationModel));
typeInfrastructureManager.TypeToCanonicalNameMap.Add(typeof(global::MyApplication.Proxy.ApplicationModel), "MyApplication.UI, MyApplication.UI.ApplicationModel");
typeInfrastructureManager.CanonicalNameToTypeMap.Add("MyApplication.UI, MyApplication.UI.ApplicationMainForm", typeof(global::MyApplication.Proxy.ApplicationMainForm));
typeInfrastructureManager.TypeToCanonicalNameMap.Add(typeof(global::MyApplication.Proxy.ApplicationMainForm), "MyApplication.UI, MyApplication.UI.ApplicationMainForm");
typeInfrastructureManager.CanonicalNameToTypeMap.Add("MyApplication.UI, MyApplication.UI.FrameworkModel", typeof(global::MyApplication.Proxy.FrameworkModel));
typeInfrastructureManager.TypeToCanonicalNameMap.Add(typeof(global::MyApplication.Proxy.FrameworkModel), "MyApplication.UI, MyApplication.UI.FrameworkModel");
typeInfrastructureManager.CanonicalNameToTypeMap.Add("MyApplication.UI, MyApplication.UI.WorksetModel", typeof(global::MyApplication.Proxy.WorksetModel));
typeInfrastructureManager.TypeToCanonicalNameMap.Add(typeof(global::MyApplication.Proxy.WorksetModel), "MyApplication.UI, MyApplication.UI.WorksetModel");
typeInfrastructureManager.CanonicalNameToTypeMap.Add("MyApplication.UI, MyApplication.UI.AlgebraModel", typeof(global::MyApplication.Proxy.AlgebraModel));
typeInfrastructureManager.TypeToCanonicalNameMap.Add(typeof(global::MyApplication.Proxy.AlgebraModel), "MyApplication.UI, MyApplication.UI.AlgebraModel");
typeInfrastructureManager.CanonicalNameToTypeMap.Add("MyApplication.DAL, MyApplication.DAL.MyBaseClass", typeof(global::MyApplication.Proxy.MyBaseClass));
typeInfrastructureManager.TypeToCanonicalNameMap.Add(typeof(global::MyApplication.Proxy.MyBaseClass), "MyApplication.DAL, MyApplication.DAL.MyBaseClass");
typeInfrastructureManager.CanonicalNameToTypeMap.Add("MyApplication.Data, MyApplication.Data.MyClass", typeof(global::MyApplication.Proxy.MyClass));
typeInfrastructureManager.TypeToCanonicalNameMap.Add(typeof(global::MyApplication.Proxy.MyClass), "MyApplication.Data, MyApplication.Data.MyClass");
return typeInfrastructureManager;
}
internal static global::Microsoft.VisualStudio.Tools.Applications.TypeInfrastructureManager GetMap() {
global::Microsoft.VisualStudio.Tools.Applications.TypeInfrastructureManager typeInfrastructureManager = new global::Microsoft.VisualStudio.Tools.Applications.TypeInfrastructureManager();
global::Microsoft.VisualStudio.Tools.Applications.ProxyServices.Helper.CMyApplication_UIInitializer.AddTypesToMap(typeInfrastructureManager);
return typeInfrastructureManager;
}
}
}
Step 3:
In your Extension.cs file, add in the similar entry like how they are done in bold.
private void InitializeTypeInfrastructureManager()
{
if (_typeInfrastructureManager == null)
{
_typeInfrastructureManager = new global::Microsoft.VisualStudio.Tools.Applications.TypeInfrastructureManager();
global::System.Type hostType;
global::System.Type proxyType;
hostType = typeof(global::MyApplication.UI.ApplicationModel);
proxyType = typeof(NonProxiableType<global::MyApplication.UI.ApplicationModel>);
_typeInfrastructureManager.CanonicalNameToTypeMap.Add("MyApplication.UI, MyApplication.UI.ApplicationModel", proxyType);
_typeInfrastructureManager.TypeToCanonicalNameMap.Add(hostType, "MyApplication.UI, MyApplication.UI.ApplicationModel");
hostType = typeof(global::MyApplication.UI.ApplicationMainForm);
proxyType = typeof(NonProxiableType<global::MyApplication.UI.ApplicationMainForm>);
_typeInfrastructureManager.CanonicalNameToTypeMap.Add("MyApplication.UI, MyApplication.UI.ApplicationMainForm", proxyType);
_typeInfrastructureManager.TypeToCanonicalNameMap.Add(hostType, "MyApplication.UI, MyApplication.UI.ApplicationMainForm");
hostType = typeof(global::MyApplication.UI.FrameworkModel);
proxyType = typeof(NonProxiableType<global::MyApplication.UI.FrameworkModel>);
_typeInfrastructureManager.CanonicalNameToTypeMap.Add("MyApplication.UI, MyApplication.UI.FrameworkModel", proxyType);
_typeInfrastructureManager.TypeToCanonicalNameMap.Add(hostType, "MyApplication.UI, MyApplication.UI.FrameworkModel");
hostType = typeof(global::MyApplication.UI.WorksetModel);
proxyType = typeof(NonProxiableType<global::MyApplication.UI.WorksetModel>);
_typeInfrastructureManager.CanonicalNameToTypeMap.Add("MyApplication.UI, MyApplication.UI.WorksetModel", proxyType);
_typeInfrastructureManager.TypeToCanonicalNameMap.Add(hostType, "MyApplication.UI, MyApplication.UI.WorksetModel");
hostType = typeof(global::MyApplication.UI.AlgebraModel);
proxyType = typeof(NonProxiableType<global::MyApplication.UI.AlgebraModel>);
_typeInfrastructureManager.CanonicalNameToTypeMap.Add("MyApplication.UI, MyApplication.UI.AlgebraModel", proxyType);
_typeInfrastructureManager.TypeToCanonicalNameMap.Add(hostType, "MyApplication.UI, MyApplication.UI.AlgebraModel");
hostType = typeof(global::MyApplication.DAL.MyBaseClass);
proxyType = typeof(NonProxiableType<global::MyApplication.DAL.MyBaseClass>);
_typeInfrastructureManager.CanonicalNameToTypeMap.Add("MyApplication.DAL, MyApplication.DAL.MyBaseClass", proxyType);
_typeInfrastructureManager.TypeToCanonicalNameMap.Add(hostType, "MyApplication.DAL, MyApplication.DAL.MyBaseClass");
hostType = typeof(global::MyApplication.Data.MyClass);
proxyType = typeof(NonProxiableType<global::MyApplication.Data.MyClass>);
_typeInfrastructureManager.CanonicalNameToTypeMap.Add("MyApplication.Data, MyApplication.Data.MyClass", proxyType);
_typeInfrastructureManager.TypeToCanonicalNameMap.Add(hostType, "MyApplication.Data, MyApplication.Data.MyClass");
}
}
public sealed partial class CMyApplication_UIInitializer
{
public static global::Microsoft.VisualStudio.Tools.Applications.TypeInfrastructureManager CreateTypeInfrastructureManager()
{
global::Microsoft.VisualStudio.Tools.Applications.TypeInfrastructureManager typeInfrastructureManager = new global::Microsoft.VisualStudio.Tools.Applications.TypeInfrastructureManager();
global::System.Type hostType;
global::System.Type proxyType;
hostType = typeof(global::MyApplication.UI.ApplicationModel);
proxyType = typeof(NonProxiableType<global::MyApplication.UI.ApplicationModel>);
typeInfrastructureManager.CanonicalNameToTypeMap.Add("MyApplication.UI, MyApplication.UI.ApplicationModel", proxyType);
typeInfrastructureManager.TypeToCanonicalNameMap.Add(hostType, "MyApplication.UI, MyApplication.UI.ApplicationModel");
hostType = typeof(global::MyApplication.UI.ApplicationMainForm);
proxyType = typeof(NonProxiableType<global::MyApplication.UI.ApplicationMainForm>);
typeInfrastructureManager.CanonicalNameToTypeMap.Add("MyApplication.UI, MyApplication.UI.ApplicationMainForm", proxyType);
typeInfrastructureManager.TypeToCanonicalNameMap.Add(hostType, "MyApplication.UI, MyApplication.UI.ApplicationMainForm");
hostType = typeof(global::MyApplication.UI.FrameworkModel);
proxyType = typeof(NonProxiableType<global::MyApplication.UI.FrameworkModel>);
typeInfrastructureManager.CanonicalNameToTypeMap.Add("MyApplication.UI, MyApplication.UI.FrameworkModel", proxyType);
typeInfrastructureManager.TypeToCanonicalNameMap.Add(hostType, "MyApplication.UI, MyApplication.UI.FrameworkModel");
hostType = typeof(global::MyApplication.UI.WorksetModel);
proxyType = typeof(NonProxiableType<global::MyApplication.UI.WorksetModel>);
typeInfrastructureManager.CanonicalNameToTypeMap.Add("MyApplication.UI, MyApplication.UI.WorksetModel", proxyType);
typeInfrastructureManager.TypeToCanonicalNameMap.Add(hostType, "MyApplication.UI, MyApplication.UI.WorksetModel");
hostType = typeof(global::MyApplication.UI.AlgebraModel);
proxyType = typeof(NonProxiableType<global::MyApplication.UI.AlgebraModel>);
typeInfrastructureManager.CanonicalNameToTypeMap.Add("MyApplication.UI, MyApplication.UI.AlgebraModel", proxyType);
typeInfrastructureManager.TypeToCanonicalNameMap.Add(hostType, "MyApplication.UI, MyApplication.UI.AlgebraModel");
hostType = typeof(global::MyApplication.DAL.MyBaseClass);
proxyType = typeof(NonProxiableType<global::MyApplication.DAL.MyBaseClass>);
typeInfrastructureManager.CanonicalNameToTypeMap.Add("MyApplication.DAL, MyApplication.DAL.MyBaseClass", proxyType);
typeInfrastructureManager.TypeToCanonicalNameMap.Add(hostType, "MyApplication.DAL, MyApplication.DAL.MyBaseClass"); hostType = typeof(global::MyApplication.Data.MyClass);
proxyType = typeof(NonProxiableType<global::MyApplication.Data.MyClass>);
typeInfrastructureManager.CanonicalNameToTypeMap.Add("MyApplication.Data, MyApplication.Data.MyClass", proxyType);
typeInfrastructureManager.TypeToCanonicalNameMap.Add(hostType, "MyApplication.Data, MyApplication.Data.MyClass");
return typeInfrastructureManager;
}
}
After all, we're done.
:)