PluginFramework.AddIn.Core.Framework.GetServiceReferences C# (CSharp) Method

GetServiceReferences() public method

public GetServiceReferences ( string clazz, string filterString, IBundleContext context, bool allservices ) : IServiceReference[]
clazz string
filterString string
context IBundleContext
allservices bool
return IServiceReference[]
        public IServiceReference[] GetServiceReferences(string clazz, string filterString,
            IBundleContext context, bool allservices)
        {
            Filter filter = string.IsNullOrEmpty(filterString) ? null : new Filter(filterString);
            IServiceReference[] services = null;

            lock (serviceRegistry)
            {
                services = serviceRegistry.LookupServiceReferences(clazz, filter);
                if (services == null)
                {
                    return null;
                }
                int removed = 0;
                for (int i = services.Length - 1; i >= 0; i--)
                {
                    ServiceReference reference = (ServiceReference)services[i];
                    string[] classes = reference.GetClasses();
                    if (allservices || context.IsAssignableTo((ServiceReference)services[i]))
                    {
                        if (clazz == null)
                            try
                            { /* test for permission to the classes */
                                //checkGetServicePermission(classes);
                            }
                            catch (SecurityException)
                            {
                                services[i] = null;
                                removed++;
                            }
                    }
                    else
                    {
                        services[i] = null;
                        removed++;
                    }
                }
                if (removed > 0)
                {
                    IServiceReference[] temp = services;
                    services = new ServiceReference[temp.Length - removed];
                    for (int i = temp.Length - 1; i >= 0; i--)
                    {
                        if (temp[i] == null)
                            removed--;
                        else
                            services[i - removed] = temp[i];
                    }
                }

            }
            return services == null || services.Length == 0 ? null : services;
        }