public static Type GetMatchingEntityReferenceType(string entityType, Type type)
        {
            IEnumerable <Type> matchingTypes = GetMatchingTypes(type);
            List <Type>        result        = new List <Type>();

            foreach (Type matchingType in matchingTypes)
            {
                EntityTypeAttribute eta = Reflection.Utility.GetAttribute <EntityTypeAttribute>(matchingType);
                if (eta != null && eta.Name == entityType)
                {
                    result.Add(matchingType);
                }
                else if (matchingType.Name == entityType + "Reference")
                {
                    result.Add(matchingType);
                }
            }

            if (result.Count == 0)
            {
                throw new MissingEntityReferenceTypeException(entityType, type);
            }
            if (result.Count > 1)
            {
                throw new MultipleEntityReferenceTypesException(entityType, type, result);
            }

            return(result.First());
        }
Exemple #2
0
        protected string GetEntityType(Type t)
        {
            EntityTypeAttribute entityTypeAttribute = Reflection.Utility.GetAttribute <EntityTypeAttribute>(t);

            if (entityTypeAttribute != null)
            {
                return(entityTypeAttribute.Name);
            }

            return(t.Name);
        }
        private static IEnumerable <Type> GetMatchingEntityTypes(string entityType, Type type)
        {
            IEnumerable <Type> matchingTypes = GetMatchingTypes(type);
            List <Type>        result        = new List <Type>();

            foreach (Type matchingType in matchingTypes)
            {
                EntityTypeAttribute eta = Reflection.Utility.GetAttribute <EntityTypeAttribute>(matchingType);
                if (eta != null && eta.Name == entityType)
                {
                    result.Add(matchingType);
                }
                else if (matchingType.Name == entityType)
                {
                    result.Add(matchingType);
                }
            }

            return(result);
        }