private MemberTypeData GenerateInfo(Type memberType, string memberName) { MemberTypeData memberInfo = new MemberTypeData(memberType, memberName); if (memberType.IsClass) { if (memberType != typeof(string)) { if (FixtureGenerator.DoesItImplementInterface(memberType, typeof(IList))) { var itemType = memberType.GetGenericArguments()[0]; memberInfo.ItemType = GenerateInfo(itemType, "Item"); } else if (FixtureGenerator.DoesItImplementInterface(memberType, typeof(IDictionary))) { var genericTypes = memberType.GetGenericArguments(); memberInfo.KeyType = GenerateInfo(genericTypes[0], "Key"); memberInfo.ItemType = GenerateInfo(genericTypes[1], "Item"); } else { memberInfo.Children = BuildTree(memberType); } } } return(memberInfo); }
private MemberTypeData GetCommonMemberData(MemberTypeData member1, MemberTypeData member2) { MemberTypeData common = member1.Clone(); if (member1.MemberType == member2.MemberType) { return(common); } else { if (member1.MemberType.IsClass && member2.MemberType.IsClass) { if (member1.MemberType != typeof(string) && member2.MemberType != typeof(string)) { if (FixtureGenerator.DoesItImplementInterface(member1.MemberType, typeof(IList)) && FixtureGenerator.DoesItImplementInterface(member2.MemberType, typeof(IList))) { common.ItemType = GetCommonMemberData(member1.ItemType, member2.ItemType); if (common.ItemType == null) { // list value types do not have common elements return(null); } } else if (FixtureGenerator.DoesItImplementInterface(member1.MemberType, typeof(IDictionary)) && FixtureGenerator.DoesItImplementInterface(member2.MemberType, typeof(IDictionary))) { if (member1.KeyType.MemberType != member1.KeyType.MemberType) { return(null); // keys MUST be of the same type, commmon members are not enough } common.ItemType = GetCommonMemberData(member1.ItemType, member2.ItemType); if (common.ItemType == null) { // dictionary value types do not have common elements return(null); } } else { common.Children = GetCommonTree(member1.Children, member2.Children); } return(common); } return(null); } } return(null); }