// PUBLIC METHODS ///////////////////////////////////////////////////
        #region IApiObjectTypeConvention Implementation
        public void Apply(IApiObjectTypeBuilder apiObjectTypeBuilder, ApiConventionSettings apiConventionSettings)
        {
            Contract.Requires(apiObjectTypeBuilder != null);

            // Try and discover relationship CLR properties of the CLR object type:
            var clrObjectType = apiObjectTypeBuilder.ClrType;
            var clrProperties = ClrPropertyDiscoveryRules.GetClrProperties(clrObjectType);

            foreach (var clrProperty in clrProperties)
            {
                var clrPropertyType = clrProperty.PropertyType;
                var apiTypeKind     = clrPropertyType.GetApiTypeKind(out var clrItemType);

                switch (apiTypeKind)
                {
                case ApiTypeKind.Collection:
                {
                    var apiItemTypeKind = clrItemType.GetApiTypeKind();
                    switch (apiItemTypeKind)
                    {
                    case ApiTypeKind.Object:
                    {
                        var clrPropertyName = clrProperty.Name;
                        apiObjectTypeBuilder.ApiRelationship(clrPropertyName, clrPropertyType);
                        break;
                    }
                    }
                    break;
                }

                case ApiTypeKind.Object:
                {
                    var clrPropertyName = clrProperty.Name;
                    apiObjectTypeBuilder.ApiRelationship(clrPropertyName, clrPropertyType);
                    break;
                }
                }
            }
        }
Ejemplo n.º 2
0
        private static void HandleApiRelationshipAttribute(IApiObjectTypeBuilder apiObjectTypeBuilder,
                                                           ApiPrecedenceStack apiPrecedenceStack,
                                                           PropertyInfo clrPropertyInfo)
        {
            Contract.Requires(apiObjectTypeBuilder != null);
            Contract.Requires(clrPropertyInfo != null);

            var apiRelationshipAttribute = Attribute.GetCustomAttribute(clrPropertyInfo, typeof(ApiRelationshipAttribute));

            if (apiRelationshipAttribute == null)
            {
                return;
            }

            var clrPropertyName = clrPropertyInfo.Name;
            var clrPropertyType = clrPropertyInfo.PropertyType;

            apiPrecedenceStack.Push(ApiPrecedenceLevel.Annotation);
            apiObjectTypeBuilder.ApiRelationship(clrPropertyName, clrPropertyType);
            apiPrecedenceStack.Pop();
        }