Exemple #1
0
        public static object GetNodeInfo(string typeName, int id, UniversityStructureRepository rep)
        {
            dynamic obj = FindObject(typeName, id, rep);

            if (obj == null)
            {
                return(null);
            }

            return(GetNodeInfo(obj));
        }
Exemple #2
0
        private static object FindObject(string typeName, int id, UniversityStructureRepository rep)
        {
            //here we look for the relevant enumerable property-collection in the repository
            var          repositoryEnumerableProperties = FindEnumerableProperties(rep.GetType());
            PropertyInfo propertyInfo = null;

            foreach (var property in repositoryEnumerableProperties)
            {
                if (property.PropertyType.GetGenericArguments().Select(t => t.Name).FirstOrDefault() == typeName)
                {
                    propertyInfo = property;
                }
            }
            if (propertyInfo == null)
            {
                return(null);
            }

            //check generic parameter
            Type genericParameter = propertyInfo.PropertyType.GetGenericArguments().FirstOrDefault();

            if (genericParameter == null || genericParameter.GetType().IsValueType || genericParameter.GetType().Name == "object")
            {
                return(null);
            }

            //here we find the object with id 'id' of type 'typeName'
            IEnumerable collection = propertyInfo.GetValue(rep) as IEnumerable;
            IEnumerator enumerator = collection.GetEnumerator();
            dynamic     current    = null;
            dynamic     wanted     = null;

            while (enumerator.MoveNext())
            {
                current = enumerator.Current;
                if ((int)GetProperty("Id", current, typeName) == id)
                {
                    wanted = current;
                }
            }
            return(wanted);
        }
Exemple #3
0
 public static object GetObject(string typeName, int id, UniversityStructureRepository rep)
 {
     return(FindObject(typeName, id, rep));
 }
Exemple #4
0
        public static int GetNumberOfDescendants(string typeName, int id, UniversityStructureRepository rep)
        {
            object o = FindObject(typeName, id, rep);

            return(CalculateDescendants(o));
        }