public static IEnumerable GetOptionsWithReferences(string typeManagerName)
        {
            Type t = TypeManager.GetType(typeManagerName);
            IEnumerable <ForeignPropertyInfo> foreignKeyProperties = DataReferenceFacade.GetForeignKeyProperties(t);
            List <PropertyInfo> properties = t.GetPropertiesRecursively(f => f.DeclaringType != typeof(IData));

            List <string> result = new List <string>();

            foreach (PropertyInfo propertyInfo in properties)
            {
                result.Add(propertyInfo.Name);
                ForeignPropertyInfo foreignKeyInfo = foreignKeyProperties.FirstOrDefault(f => f.SourcePropertyName == propertyInfo.Name);

                if (foreignKeyInfo != null)
                {
                    List <PropertyInfo> foreignProperties = foreignKeyInfo.TargetType.GetPropertiesRecursively(f => f.DeclaringType != typeof(IData));

                    foreach (PropertyInfo foreignPropertyInfo in foreignProperties)
                    {
                        string foreignKey = string.Format("{0}.{1}", propertyInfo.Name, foreignPropertyInfo.Name);
                        result.Add(foreignKey);
                    }
                }
            }

            return(result);
        }
Esempio n. 2
0
        private static IReferencedDataHelper <SOURCE> BuildImpl(string foreignKeyPropertyName)
        {
            Type sourceType             = typeof(SOURCE);
            ForeignPropertyInfo keyInfo = DataReferenceFacade.GetForeignKeyPropertyInfo(sourceType, foreignKeyPropertyName);
            Type destinationType        = keyInfo.TargetType;

            PropertyInfo sourceKeyPropertyInfo      = sourceType.GetDataPropertyRecursivly(foreignKeyPropertyName);
            PropertyInfo destinationKeyPropertyInfo = destinationType.GetKeyProperties().Single();
            Type         keyFieldType = destinationKeyPropertyInfo.PropertyType;

            Type[] genericArgs = new Type[] { typeof(SOURCE), destinationType, keyFieldType };

            return((IReferencedDataHelper <SOURCE>)Activator.CreateInstance(typeof(ReferencedDataHelper <, ,>).MakeGenericType(genericArgs), sourceKeyPropertyInfo, destinationKeyPropertyInfo));
        }
Esempio n. 3
0
        private static QueryInfo GetQueryInfo(IEnumerable <string> propertyNames)
        {
            string key = string.Join("|", propertyNames);

            QueryInfo queryInfo = _queryInfoTable[key];

            if (queryInfo != null)
            {
                return(queryInfo);
            }


            lock (_queryInfoTable)
            {
                queryInfo = _queryInfoTable[key];
                if (queryInfo != null)
                {
                    return(queryInfo);
                }

                queryInfo = new QueryInfo();
                queryInfo.HasLocalizableReference = DataLocalizationFacade.IsLocalized(typeof(T));
                queryInfo.HasPublishableReference = DataFacade.GetSupportedDataScopes(typeof(T)).Count() > 1;

                List <Type> relatedTypesList = new List <Type>();

                foreach (string propertyName in propertyNames.Where(f => f.Contains(".")))
                {
                    string foreignKeyPropertyName = propertyName.Substring(0, propertyName.IndexOf("."));
                    ForeignPropertyInfo keyInfo   = DataReferenceFacade.GetForeignKeyPropertyInfo(typeof(T),
                                                                                                  foreignKeyPropertyName);

                    Type targetType = keyInfo.TargetType;
                    if (!relatedTypesList.Contains(targetType))
                    {
                        relatedTypesList.Add(targetType);
                    }

                    queryInfo.HasLocalizableReference = queryInfo.HasLocalizableReference || DataLocalizationFacade.IsLocalized(targetType);
                    queryInfo.HasPublishableReference = queryInfo.HasPublishableReference || (DataFacade.GetSupportedDataScopes(targetType).Count() > 1);
                }

                queryInfo.ReferencedDataTypes = relatedTypesList;

                _queryInfoTable.Add(key, queryInfo);
                return(queryInfo);
            }
        }