Rock.Reflection.GetServiceForEntityType C# (CSharp) Méthode

GetServiceForEntityType() public static méthode

Gets the appropriate Rock.Data.IService based on the entity type
public static GetServiceForEntityType ( Type entityType, System dbContext ) : Rock.Data.IService
entityType System.Type Type of the Entity.
dbContext System The database context.
Résultat Rock.Data.IService
        public static Rock.Data.IService GetServiceForEntityType( Type entityType, System.Data.Entity.DbContext dbContext )
        {
            Type serviceType = typeof( Rock.Data.Service<> );
            if ( entityType.Assembly != serviceType.Assembly )
            {
                var serviceTypeLookup = Reflection.SearchAssembly( entityType.Assembly, serviceType );
                if ( serviceTypeLookup.Any() )
                {
                    serviceType = serviceTypeLookup.First().Value;
                }
            }

            Type service = serviceType.MakeGenericType( new Type[] { entityType } );
            Rock.Data.IService serviceInstance = Activator.CreateInstance( service, dbContext ) as Rock.Data.IService;
            return serviceInstance;
        }