internal static Metadata.MetadataProvider CreateMetadataProvider(Type dataControllerType) { // construct a list of all types in the inheritance hierarchy for the controller var baseTypes = new List <Type>(); var currType = dataControllerType; while (currType != typeof(DataController)) { baseTypes.Add(currType); Debug.Assert(currType != null, "currType != null"); currType = currType.BaseType; } // create our base reflection provider var providerList = new List <Metadata.MetadataProvider>(); var reflectionProvider = new Metadata.ReflectionMetadataProvider(); // Set the IsEntity function which consults the chain of providers. Func <Type, bool> isEntityTypeFunc = type => providerList.Any(metadataProvider => metadataProvider.LookUpIsEntityType(type)); reflectionProvider.SetIsEntityTypeFunc(isEntityTypeFunc); // Now from most derived to base, create any declared metadata providers, // chaining the instances as we progress. Note that ordering from derived to // base is important - we want to ensure that any providers the user has placed on // their DataController directly come before any DAL providers. Metadata.MetadataProvider currProvider = reflectionProvider; providerList.Add(currProvider); // Reflection rather than TD is used here so we only get explicit // Type attributes. TD inherits attributes by default, even if the // attributes aren't inheritable. foreach (var providerAttribute in baseTypes.SelectMany(type => type.GetCustomAttributes <Metadata.MetadataProviderAttribute>(false))) { currProvider = providerAttribute.CreateProvider(dataControllerType, currProvider); currProvider.SetIsEntityTypeFunc(isEntityTypeFunc); providerList.Add(currProvider); } return(currProvider); }
internal static Metadata.MetadataProvider CreateMetadataProvider(Type dataControllerType) { // construct a list of all types in the inheritance hierarchy for the controller var baseTypes = new List<Type>(); var currType = dataControllerType; while (currType != typeof (DataController)) { baseTypes.Add(currType); Debug.Assert(currType != null, "currType != null"); currType = currType.BaseType; } // create our base reflection provider var providerList = new List<Metadata.MetadataProvider>(); var reflectionProvider = new Metadata.ReflectionMetadataProvider(); // Set the IsEntity function which consults the chain of providers. Func<Type, bool> isEntityTypeFunc = type => providerList.Any(metadataProvider => metadataProvider.LookUpIsEntityType(type)); reflectionProvider.SetIsEntityTypeFunc(isEntityTypeFunc); // Now from most derived to base, create any declared metadata providers, // chaining the instances as we progress. Note that ordering from derived to // base is important - we want to ensure that any providers the user has placed on // their DataController directly come before any DAL providers. Metadata.MetadataProvider currProvider = reflectionProvider; providerList.Add(currProvider); // Reflection rather than TD is used here so we only get explicit // Type attributes. TD inherits attributes by default, even if the // attributes aren't inheritable. foreach (var providerAttribute in baseTypes.SelectMany(type => type.GetCustomAttributes<Metadata.MetadataProviderAttribute>(false))) { currProvider = providerAttribute.CreateProvider(dataControllerType, currProvider); currProvider.SetIsEntityTypeFunc(isEntityTypeFunc); providerList.Add(currProvider); } return currProvider; }