Exemplo n.º 1
0
        public void InitAddon()
        {
            if (m_addon == null)
            {
                Type[] types;
                try
                {
                    types = m_assembly.GetTypes();
                }
                catch (Exception e)
                {
                    throw new Exception(string.Format("Unable to load Addon {0} - " +
                                                      "please make sure that it and it's dependencies were built against the current build and all it's dependencies are available.", this), e);
                }
                foreach (var type in types)
                {
                    var interfaces = type.GetInterfaces();
                    if (interfaces.Contains(typeof(IWCellAddon)))
                    {
                        var addonAttributes = type.GetCustomAttributes <WCellAddonAttribute>();
                        m_attr  = addonAttributes.Length > 0 ? addonAttributes[0] : null;
                        m_addon = (IWCellAddon)Activator.CreateInstance(type);

                        if (m_addon != null)
                        {
                            WCellAddonMgr.RegisterAddon(this);
                        }
                        break;
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void InitAddon()
        {
            if (this.m_addon != null)
            {
                return;
            }
            Type[] types;
            try
            {
                types = this.m_assembly.GetTypes();
            }
            catch (Exception ex)
            {
                throw new Exception(
                          string.Format(
                              "Unable to load Addon {0} - please make sure that it and it's dependencies were built against the current build and all it's dependencies are available.",
                              (object)this), ex);
            }

            foreach (Type type in types)
            {
                if (((IEnumerable <Type>)type.GetInterfaces()).Contains <Type>(typeof(IWCellAddon)))
                {
                    WCellAddonAttribute[] customAttributes = type.GetCustomAttributes <WCellAddonAttribute>();
                    this.m_attr  = customAttributes.Length > 0 ? customAttributes[0] : (WCellAddonAttribute)null;
                    this.m_addon = (IWCellAddon)Activator.CreateInstance(type);
                    if (this.m_addon != null)
                    {
                        WCellAddonMgr.RegisterAddon(this);
                        break;
                    }

                    break;
                }
            }
        }