Example #1
0
        private void GenerateOwnedTypeFieldInfos(Field parentField, IEntityType ownedType, IEnumerable <INavigation> nestedOwnedTypes, Dictionary <string, IEntityType> ownedMap)
        {
            parentField.fieldType = FieldType.Object;

            foreach (INavigation ownedNavigation in nestedOwnedTypes)
            {
                Field fieldInfo = new Field {
                    fieldName = ownedNavigation.Name
                };
                string      nm = ownedNavigation.ForeignKey.DeclaringEntityType.Name;
                IEntityType nestedOwnedType2 = ownedMap[nm];
                IEnumerable <INavigation> nestedOwnedTypes2 = nestedOwnedType2.GetNavigations().Where(n => ownedMap.ContainsKey(n.ForeignKey.DeclaringEntityType.Name)).ToArray();
                GenerateOwnedTypeFieldInfos(fieldInfo, nestedOwnedType2, nestedOwnedTypes2, ownedMap);
                parentField.nested.Add(fieldInfo);
            }

            IProperty[] edmProps = ownedType.GetProperties().Where(p => !p.IsShadowProperty()).ToArray();
            DataService.Utils.IValueConverter valueConverter = ServiceContainer.ValueConverter;

            foreach (IProperty edmProp in edmProps)
            {
                bool  isContinue = false;
                Field fieldInfo  = new Field {
                    fieldName = edmProp.Name
                };

                try
                {
                    fieldInfo.dataType = edmProp.ClrType.IsArrayType() ? DataType.None : valueConverter.DataTypeFromType(edmProp.ClrType);
                }
                catch (UnsupportedTypeException)
                {
                    // Console.WriteLine($"{edmProp.Name} unsupported type {edmProp.ClrType.FullName}");

                    // complex type
                    if (edmProp.ClrType.IsClass)
                    {
                        GenerateNestedFieldInfos(fieldInfo, edmProp.ClrType);
                    }
                    else
                    {
                        isContinue = true;
                    }
                }

                if (isContinue)
                {
                    continue;
                }

                if (fieldInfo.fieldType != FieldType.Object)
                {
                    UpdateFieldInfo(fieldInfo, edmProp);
                }

                parentField.nested.Add(fieldInfo);
            }
        }
Example #2
0
        private void GenerateNestedFieldInfos(Field parentField, Type nestedType)
        {
            PropertyInfo[] nestedProps = nestedType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).ToArray();
            DataService.Utils.IValueConverter valueConverter = ServiceContainer.ValueConverter;

            foreach (PropertyInfo propInfo in nestedProps)
            {
                bool  isContinue = false;
                Field fieldInfo  = new Field {
                    fieldName = propInfo.Name
                };
                try
                {
                    fieldInfo.dataType = propInfo.PropertyType.IsArrayType() ? DataType.None : valueConverter.DataTypeFromType(propInfo.PropertyType);
                }
                catch (UnsupportedTypeException)
                {
                    if (propInfo.PropertyType.IsClass)
                    {
                        // complex Type field
                        GenerateNestedFieldInfos(fieldInfo, propInfo.PropertyType);
                    }
                    else
                    {
                        isContinue = true;
                    }
                }

                if (isContinue)
                {
                    continue;
                }

                if (fieldInfo.fieldType != FieldType.Object)
                {
                    UpdateNestedFieldInfo(fieldInfo, propInfo);
                }

                parentField.fieldType = FieldType.Object;
                parentField.nested.Add(fieldInfo);
            }
        }