private void ExtractFromFields(ProviderRegistrationContext context, Type 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); } } } } } }
private void ExtractFromType(ProviderRegistrationContext context, Type 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)) { try { context.DefineProvider(qn, pa.ProviderType, type, pa); } catch (Exception ex) { RuntimeWarning.InvalidProviderDeclared(type.FullName, ex); } } } } } }
private void ExtractFromMethods(ProviderRegistrationContext context, Type 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)) { context.DefineProvider(qn, pa.ProviderType, method, pa); } } } }