Esempio n. 1
0
 static public void GetExcelAddIns(ExportedAssembly assembly, Type t, bool loadRibbons, List <ExcelAddInInfo> addIns)
 {
     // NOTE: We probably should have restricted this to public types, but didn't. Now it's too late.
     //       So internal classes that implement IExcelAddIn are also loaded.
     try
     {
         Type addInType = t.GetInterface("ExcelDna.Integration.IExcelAddIn");
         bool isRibbon  = IsRibbonType(t);
         if (addInType != null || (isRibbon && loadRibbons))
         {
             ExcelAddInInfo info = new ExcelAddInInfo();
             if (addInType != null)
             {
                 info.AutoOpenMethod  = addInType.GetMethod("AutoOpen");
                 info.AutoCloseMethod = addInType.GetMethod("AutoClose");
             }
             info.IsCustomUI = isRibbon;
             // TODO: Consider how to handle exception from constructors here.
             info.Instance         = Activator.CreateInstance(t);
             info.ParentDnaLibrary = assembly.ParentDnaLibrary;
             addIns.Add(info);
             Logger.Registration.Verbose("GetExcelAddIns - Created add-in object of type: {0}", t.FullName);
         }
     }
     catch (Exception e) // I think only CreateInstance can throw an exception here...
     {
         Logger.Initialization.Warn("GetExcelAddIns CreateInstance problem for type: {0} - exception: {1}", t.FullName, e);
     }
 }
Esempio n. 2
0
 static public void GetExcelAddIns(ExportedAssembly assembly, Type t, bool loadRibbons, List <ExcelAddInInfo> addIns)
 {
     try
     {
         Type addInType = t.GetInterface("ExcelDna.Integration.IExcelAddIn");
         bool isRibbon  = IsRibbonType(t);
         if (addInType != null || (isRibbon && loadRibbons))
         {
             ExcelAddInInfo info = new ExcelAddInInfo();
             if (addInType != null)
             {
                 info.AutoOpenMethod  = addInType.GetMethod("AutoOpen");
                 info.AutoCloseMethod = addInType.GetMethod("AutoClose");
             }
             info.IsCustomUI = isRibbon;
             // TODO: Consider how to handle exception from constructors here.
             info.Instance         = Activator.CreateInstance(t);
             info.ParentDnaLibrary = assembly.ParentDnaLibrary;
             addIns.Add(info);
         }
     }
     catch (Exception e) // I think only CreateInstance can throw an exception here...
     {
         Debug.Print("GetExcelAddIns CreateInstance problem for type: {0} - exception: {1}", t.FullName, e);
     }
 }
Esempio n. 3
0
        // DOCUMENT: We register ComVisible types that
        //           (implement IRtdServer OR are in ExternalLibraries marked ComServer='true'
        static public void GetComClassTypes(ExportedAssembly assembly, Type type, object[] attributes, bool isRtdServer, List <ExcelComClassType> comClassTypes)
        {
            if (!Marshal.IsTypeVisibleFromCom(type))
            {
                return;
            }

            if (isRtdServer || assembly.ComServer)
            {
                string progId;
                Guid   clsId;

                // Check for public default constructor
                if (type.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, Type.EmptyTypes, null) == null)
                {
                    // No use to us here - won't be able to construct.
                    return;
                }

                if (assembly.IsDynamic)
                {
                    // Check that we have an explicit Guid attribute
                    object[] attrs = type.GetCustomAttributes(typeof(GuidAttribute), false);
                    if (attrs.Length == 0)
                    {
                        // No Guid attribute - skip this type.
                        return;
                    }
                    else
                    {
                        GuidAttribute guidAtt = (GuidAttribute)attrs[0];
                        clsId = new Guid(guidAtt.Value);
                    }
                }
                else
                {
                    clsId = Marshal.GenerateGuidForType(type);
                }

                progId = Marshal.GenerateProgIdForType(type);

                ExcelComClassType comClassType = new ExcelComClassType
                {
                    Type        = type,
                    ClsId       = clsId,
                    ProgId      = progId,
                    IsRtdServer = isRtdServer,
                    TypeLibPath = assembly.TypeLibPath
                };
                comClassTypes.Add(comClassType);
                Logger.Initialization.Verbose("GetComClassTypes - Found type {0}, with ProgId {1}", type.FullName, progId);
            }
        }
Esempio n. 4
0
        // DOCUMENT: We register ComVisible types that
        //           (implement IRtdServer OR are in ExternalLibraries marked ComServer='true'
        public static void GetComClassTypes(ExportedAssembly assembly, Type type, object[] attributes, bool isRtdServer, List<ExcelComClassType> comClassTypes)
        {
            if (!Marshal.IsTypeVisibleFromCom(type))
            {
                return;
            }

            if (isRtdServer || assembly.ComServer)
            {
                string progId;
                Guid clsId;

                // Check for public default constructor
                if (type.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, Type.EmptyTypes, null) == null)
                {
                    // No use to us here - won't be able to construct.
                    return;
                }

                if (assembly.IsDynamic)
                {
                    // Check that we have an explicit Guid attribute
                    object[] attrs = type.GetCustomAttributes(typeof(GuidAttribute), false);
                    if (attrs.Length == 0)
                    {
                        // No Guid attribute - skip this type.
                        return;
                    }
                    else
                    {
                        GuidAttribute guidAtt = (GuidAttribute)attrs[0];
                        clsId = new Guid(guidAtt.Value);
                    }
                }
                else
                {
                    clsId = Marshal.GenerateGuidForType(type);
                }

                progId = Marshal.GenerateProgIdForType(type);

                ExcelComClassType comClassType = new ExcelComClassType
                {
                    Type = type,
                    ClsId = clsId,
                    ProgId = progId,
                    IsRtdServer = isRtdServer,
                    TypeLibPath = assembly.TypeLibPath
                };
                comClassTypes.Add(comClassType);
                Logger.Initialization.Verbose("GetComClassTypes - Found type {0}, with ProgId {1}", type.FullName, progId);
            }
        }
 public static void GetExcelAddIns(ExportedAssembly assembly, Type t, bool loadRibbons, List<ExcelAddInInfo> addIns)
 {
     try
     {
         Type addInType = t.GetInterface("ExcelDna.Integration.IExcelAddIn");
         bool isRibbon = IsRibbonType(t);
         if (addInType != null || (isRibbon && loadRibbons) )
         {
             ExcelAddInInfo info = new ExcelAddInInfo();
             if (addInType != null)
             {
                 info.AutoOpenMethod = addInType.GetMethod("AutoOpen");
                 info.AutoCloseMethod = addInType.GetMethod("AutoClose");
             }
             info.IsCustomUI = isRibbon;
             // TODO: Consider how to handle exception from constructors here.
             info.Instance = Activator.CreateInstance(t);
             info.ParentDnaLibrary = assembly.ParentDnaLibrary;
             addIns.Add(info);
         }
     }
     catch (Exception e) // I think only CreateInstance can throw an exception here...
     {
         Debug.Print("GetExcelAddIns CreateInstance problem for type: {0} - exception: {1}", t.FullName, e);
     }
 }
Esempio n. 6
0
 public static void GetExcelAddIns(ExportedAssembly assembly, Type t, bool loadRibbons, List<ExcelAddInInfo> addIns)
 {
     // NOTE: We probably should have restricted this to public types, but didn't. Now it's too late.
     //       So internal classes that implement IExcelAddIn are also loaded.
     try
     {
         Type addInType = t.GetInterface("ExcelDna.Integration.IExcelAddIn");
         bool isRibbon = IsRibbonType(t);
         if (addInType != null || (isRibbon && loadRibbons) )
         {
             ExcelAddInInfo info = new ExcelAddInInfo();
             if (addInType != null)
             {
                 info.AutoOpenMethod = addInType.GetMethod("AutoOpen");
                 info.AutoCloseMethod = addInType.GetMethod("AutoClose");
             }
             info.IsCustomUI = isRibbon;
             // TODO: Consider how to handle exception from constructors here.
             info.Instance = Activator.CreateInstance(t);
             info.ParentDnaLibrary = assembly.ParentDnaLibrary;
             addIns.Add(info);
             Logger.Registration.Verbose("GetExcelAddIns - Created add-in object of type: {0}", t.FullName);
         }
     }
     catch (Exception e) // I think only CreateInstance can throw an exception here...
     {
         Logger.Initialization.Warn("GetExcelAddIns CreateInstance problem for type: {0} - exception: {1}", t.FullName, e);
     }
 }