Files
Umbraco-CMS/src/Umbraco.Core/ServiceContextExtensions.cs

22 lines
835 B
C#
Raw Normal View History

using System;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
namespace Umbraco.Core
{
public static class ServiceContextExtensions
{
2019-02-01 17:16:50 +01:00
public static IContentTypeBaseService<T> GetContentTypeService<T>(this ServiceContext services)
where T : IContentTypeComposition
{
if (typeof(T).Implements<IContentType>())
2019-02-01 17:16:50 +01:00
return services.ContentTypeService as IContentTypeBaseService<T>;
if (typeof(T).Implements<IMediaType>())
2019-02-01 17:16:50 +01:00
return services.MediaTypeService as IContentTypeBaseService<T>;
if (typeof(T).Implements<IMemberType>())
2019-02-01 17:16:50 +01:00
return services.MemberTypeService as IContentTypeBaseService<T>;
throw new ArgumentException("Type " + typeof(T).FullName + " does not have a service.");
}
}
}