private static void ExtractFromFields(ProviderRegistrationContext context, TypeInfo type)
        {
            foreach (FieldInfo field in type.GetFields())
            {
                if (!field.IsStatic)
                {
                    continue;
                }

                ProviderAttribute[] attrs = (ProviderAttribute[])field.GetCustomAttributes(typeof(ProviderAttribute), false);
                if (attrs.Length == 0)
                {
                    context.DefineProvider(null, field.FieldType, field, null);
                }
                else
                {
                    foreach (var pa in attrs)
                    {
                        foreach (var qn in pa.GetNames(field.DeclaringType, field.Name))
                        {
                            try {
                                context.DefineProvider(qn, pa.ProviderType, field, pa);
                            }
                            catch (Exception ex) {
                                var fullName = field.DeclaringType.FullName + "." + field.Name;
                                RuntimeWarning.InvalidProviderDeclared(fullName, ex);
                                break;
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        static IEnumerable <Type> GetRootProviderTypes(Assembly a)
        {
            IProviderRegistration       registration = AssemblyInfo.GetAssemblyInfo(a).GetProviderRegistration();
            ProviderRegistrationContext context      = new ProviderRegistrationContext(a);

            registration.RegisterRootProviderTypes(context);

            return(context.EnumerateRoots());
        }
        public override void RegisterRootProviderTypes(ProviderRegistrationContext context)
        {
            var attrs = (ProvidesAttribute[])context.Assembly.GetCustomAttributes(typeof(ProvidesAttribute), false);

            foreach (var attr in attrs)
            {
                context.DefineRootProvider(attr.ProviderType);
            }
        }
Exemple #4
0
        private static IEnumerable <ProviderValueSource> ExtractFromTypes(Assembly a)
        {
            IProviderRegistration       registration = AssemblyInfo.GetAssemblyInfo(a).GetProviderRegistration();
            ProviderRegistrationContext context      = new ProviderRegistrationContext(a);

            registration.RegisterProviderTypes(context);

            return(context.EnumerateValueSources());
        }
 public override void RegisterProviderTypes(ProviderRegistrationContext context)
 {
     foreach (TypeInfo type in context.Assembly.GetTypesHelper())
     {
         if (type.IsDefined(typeof(ProvidersAttribute), false))
         {
             ExtractProvidersClass(context, type);
         }
         ExtractFromType(context, type);
     }
 }
        public override void RegisterProviderTypes(ProviderRegistrationContext context)
        {
            var startClasses = context.Assembly.GetStartClasses("ProviderRegistration");

            ProviderRegistration registrar;

            if (startClasses.Any())
            {
                registrar = StartClassProviderRegistration.Instance;
            }
            else
            {
                registrar = SlowProviderRegistration.Instance;
            }

            registrar.RegisterProviderTypes(context);
        }
        private static void ExtractFromMethods(ProviderRegistrationContext context, TypeInfo type)
        {
            foreach (MethodInfo method in type.GetMethods())
            {
                if (!method.IsStatic)
                {
                    continue;
                }

                ProviderAttribute[] attrs = (ProviderAttribute[])method.GetCustomAttributes(typeof(ProviderAttribute), false);
                foreach (var pa in attrs)
                {
                    foreach (var qn in pa.GetNames(type.AsType()))
                    {
                        context.DefineProvider(qn, pa.ProviderType, method, pa);
                    }
                }
            }
        }
        public override void RegisterProviderTypes(ProviderRegistrationContext context)
        {
            foreach (var type in context.StartClasses)
            {
                // Look for Register methods
                // Register(ProviderRegistrationContext)

                foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static))
                {
                    var pms = method.GetParameters();
                    if (method.ReturnType == typeof(void) && pms.Length == 1 && pms[0].ParameterType == typeof(ProviderRegistrationContext))
                    {
                        LateBoundLog.Try(
                            SR.ProblemExecutingProviderRegistrationMethod(type, method.Name),
                            () => method.Invoke(null, new object[] { context })
                            );
                    }
                }

                // Also treat like a [Providers] class
                SlowProviderRegistration.ExtractProvidersClass(context, type.GetTypeInfo());
            }
        }
        private void ExtractFromType(ProviderRegistrationContext context, TypeInfo type)
        {
            if (type.IsPublic)
            {
                ProviderAttribute[] attrs = (ProviderAttribute[])type.GetCustomAttributes(typeof(ProviderAttribute), false);

                if (attrs.Length > 0)
                {
                    foreach (var pa in attrs)
                    {
                        foreach (var qn in pa.GetNames(type.AsType()))
                        {
                            try {
                                context.DefineProvider(qn, pa.ProviderType, type.AsType(), pa);
                            }
                            catch (Exception ex) {
                                RuntimeWarning.InvalidProviderDeclared(type.FullName, ex);
                                break;
                            }
                        }
                    }
                }
            }
        }
 public void RegisterProviderTypes(ProviderRegistrationContext context)
 {
     ForEach(m => m.RegisterProviderTypes(context));
 }
 public override void RegisterRootProviderTypes(ProviderRegistrationContext context)
 {
     SlowProviderRegistration.Instance.RegisterRootProviderTypes(context);
 }
 public virtual void RegisterProviderTypes(ProviderRegistrationContext context)
 {
 }
 internal static void ExtractProvidersClass(ProviderRegistrationContext context, TypeInfo type)
 {
     ExtractFromFields(context, type);
     ExtractFromMethods(context, type);
 }