public ResourceConfigurationBuilder(ConfigurationBuilder configurationBuilder) { ResourceTypeConvention = configurationBuilder.GetConvention <IResourceTypeConvention>(); LinkNameConvention = configurationBuilder.GetConvention <ILinkNameConvention>(); LinkIdConvention = configurationBuilder.GetConvention <ILinkIdConvention>(); PropertyScanningConvention = configurationBuilder.GetConvention <IPropertyScanningConvention>(); BuiltResourceMapping = new ResourceMapping <TResource, TController> { ResourceType = ResourceTypeConvention.GetResourceTypeFromRepresentationType(typeof(TResource)) }; }
public ResourceConfigurationBuilder(ConfigurationBuilder configurationBuilder) { ConfigurationBuilder = configurationBuilder; ResourceTypeConvention = configurationBuilder.GetConvention <IResourceTypeConvention>(); LinkNameConvention = configurationBuilder.GetConvention <ILinkNameConvention>(); LinkIdConvention = configurationBuilder.GetConvention <ILinkIdConvention>(); PropertyScanningConvention = configurationBuilder.GetConvention <IPropertyScanningConvention>(); ConstructedMetadata = new ResourceMapping <TResource> { ResourceType = ResourceTypeConvention.GetResourceTypeFromRepresentationType(typeof(TResource)) }; }
public ResourceConfigurationBuilder <TResource, TController> WithLinkedResource <TNested>( Expression <Func <TResource, TNested> > objectAccessor, Expression <Func <TResource, object> > idAccessor = null, string linkedResourceType = null, string linkName = null, ResourceInclusionRules inclusionRule = ResourceInclusionRules.Smart) where TNested : class { if (typeof(TNested).Name == "Array") { throw new NotSupportedException("Array type is not supported!"); } var propertyInfo = objectAccessor.GetPropertyInfo(); var isCollection = typeof(IEnumerable).IsAssignableFrom(propertyInfo.PropertyType); var linkedType = isCollection ? GetItemType(typeof(TNested)) : typeof(TNested); if (linkName == null) { linkName = LinkNameConvention.GetLinkNameFromExpression(objectAccessor); } if (linkedResourceType == null) { linkedResourceType = ResourceTypeConvention.GetResourceTypeFromRepresentationType(linkedType); } if (idAccessor == null) { idAccessor = LinkIdConvention.GetIdExpression(objectAccessor); } var link = new RelationshipMapping <TResource, TNested> { RelationshipName = linkName, ResourceIdGetter = idAccessor, ResourceGetter = ExpressionUtils.CompileToObjectTypedExpression(objectAccessor), IsCollection = isCollection, RelatedCollectionProperty = isCollection ? new PropertyHandle <TResource, TNested>(objectAccessor) : null, RelatedBaseType = linkedType, RelatedBaseResourceType = linkedResourceType, InclusionRule = inclusionRule }; BuiltResourceMapping.Relationships.Add(link); return(this); }