コード例 #1
0
ファイル: BaseDto.cs プロジェクト: hhristov-tsd/Gravity
        public static Dictionary <PropertyInfo, Type> GetRelativityObjectChildrenPropertyInfos <T>()
        {
            Dictionary <PropertyInfo, Type> returnDictionary = new Dictionary <PropertyInfo, Type>();

            foreach (var propertyInfo in typeof(T).GetPublicProperties())
            {
                RelativityObjectChildrenListAttribute childrenAttibute = propertyInfo.GetCustomAttribute <RelativityObjectChildrenListAttribute>();
                if (childrenAttibute != null)
                {
                    returnDictionary.Add(propertyInfo, childrenAttibute.ChildType);
                }
            }

            return(returnDictionary);
        }
コード例 #2
0
        public void DeleteRelativityObjectRecusively <T>(int objectToDeleteId) where T : BaseDto, new()
        {
            T theObjectToDelete = GetRelativityObject <T>(objectToDeleteId, Base.ObjectFieldsDepthLevel.FullyRecursive);

            Dictionary <PropertyInfo, RelativityObjectChildrenListAttribute> childObjectsInfo = BaseDto.GetRelativityObjectChildrenListInfos <T>();

            if (childObjectsInfo.Count == 0)
            {
                DeleteRDO(theObjectToDelete.ArtifactId);
            }
            else
            {
                foreach (var childPropertyInfo in childObjectsInfo)
                {
                    PropertyInfo propertyInfo = childPropertyInfo.Key;
                    RelativityObjectChildrenListAttribute theChildAttribute = childPropertyInfo.Value;

                    Type childType = childPropertyInfo.Value.ChildType;

                    var thisChildTypeObj = propertyInfo.GetValue(theObjectToDelete, null) as IList;

                    List <int> thisArtifactIDs = new List <int>();

                    foreach (var item in thisChildTypeObj)
                    {
                        thisArtifactIDs.Add((int)item.GetType().GetProperty("ArtifactId").GetValue(item, null));
                    }

                    if (thisArtifactIDs.Count != 0)
                    {
                        MethodInfo method = GetType().GetMethod("DeleteChildObjects", BindingFlags.NonPublic | BindingFlags.Instance).MakeGenericMethod(new Type[] { childType });

                        method.Invoke(this, new object[] { thisChildTypeObj, thisArtifactIDs });
                    }
                }

                DeleteRDO(theObjectToDelete.ArtifactId);
            }
        }