Пример #1
0
        static void RegisterControlMacro()
        {
            var method = typeof(IntelliSenseServer).GetMethod(nameof(IntelliSenseServerControl), BindingFlags.Static | BindingFlags.NonPublic);
            var name   = RegistrationInfo.GetControlMacroName(_serverId);

            ExcelIntegration.RegisterMethods(new List <MethodInfo> {
                method
            },
                                             new List <object> {
                new ExcelCommandAttribute {
                    Name = name
                }
            },                                                                                               // Macros in .xlls are always hidden
                                             new List <List <object> > {
                new List <object> {
                    null
                }
            });
            // No Unregistration - that will happen automatically (and is only needed) when we are unloaded.
        }
        //#region AppDomain helper
        //static AppDomain GetAppDomain(string friendlyName)
        //{
        //    IntPtr enumHandle = IntPtr.Zero;
        //    mscoree.ICorRuntimeHost host = new mscoree.CorRuntimeHost();

        //    try
        //    {
        //        host.EnumDomains(out enumHandle);

        //        while (true)
        //        {
        //            object domain;
        //            host.NextDomain(enumHandle, out domain);

        //            if (domain == null)
        //                break;

        //            AppDomain appDomain = (AppDomain)domain;
        //            if (appDomain.FriendlyName.Equals(friendlyName))
        //                return appDomain;
        //        }
        //    }
        //    finally
        //    {
        //        host.CloseEnum(enumHandle);
        //        System.Runtime.InteropServices.Marshal.ReleaseComObject(host); // Why??? Pure cargo-culting here...
        //    }

        //    return null;
        //}
        //#endregion

        #region IntelliSense control function registered with Excel

        static void RegisterControlFunction()
        {
            var method = typeof(IntelliSenseServer).GetMethod("IntelliSenseServerControl", BindingFlags.Static | BindingFlags.Public);
            var name   = "IntelliSenseServerControl_" + _serverId.ToString("N");

            ExcelIntegration.RegisterMethods(new List <MethodInfo> {
                method
            },
                                             new List <object> {
                new ExcelCommandAttribute {
                    Name = name
                }
            },
                                             new List <List <object> > {
                new List <object> {
                    null
                }
            });
            // No Unregistration - that will happen automatically (and is only needed) when we are unloaded.
        }
 public override void RegisterMethods(List <MethodInfo> methods, List <object> methodAttributes, List <List <object> > argumentAttributes)
 {
     ExcelIntegration.RegisterMethods(methods, methodAttributes, argumentAttributes);
 }
 public override void RegisterMethods(List <MethodInfo> methods)
 {
     ExcelIntegration.RegisterMethods(methods);
 }