System.Xml.Serialization.TypeScope.ShouldBeReplaced C# (CSharp) Method

ShouldBeReplaced() private static method

private static ShouldBeReplaced ( MemberInfo memberInfoToBeReplaced, Type derivedType, MemberInfo &replacedInfo ) : bool
memberInfoToBeReplaced System.Reflection.MemberInfo
derivedType System.Type
replacedInfo System.Reflection.MemberInfo
return bool
        private static bool ShouldBeReplaced(MemberInfo memberInfoToBeReplaced, Type derivedType, out MemberInfo replacedInfo)
        {
            replacedInfo = memberInfoToBeReplaced;
            Type currentType = derivedType;
            Type typeToBeReplaced = memberInfoToBeReplaced.DeclaringType;

            if (typeToBeReplaced.IsAssignableFrom(currentType))
            {
                while (currentType != typeToBeReplaced)
                {
                    TypeInfo currentInfo = currentType.GetTypeInfo();

                    foreach (PropertyInfo info in currentInfo.DeclaredProperties)
                    {
                        if (info.Name == memberInfoToBeReplaced.Name)
                        {
                            // we have a new modifier situation: property names are the same but the declaring types are different
                            replacedInfo = info;
                            if (replacedInfo != memberInfoToBeReplaced)
                            {
                                return true;
                            }
                        }
                    }
                    foreach (FieldInfo info in currentInfo.DeclaredFields)
                    {
                        if (info.Name == memberInfoToBeReplaced.Name)
                        {
                            // we have a new modifier situation: field names are the same but the declaring types are different
                            replacedInfo = info;
                            if (replacedInfo != memberInfoToBeReplaced)
                            {
                                return true;
                            }
                        }
                    }

                    // we go one level down and try again
                    currentType = currentType.GetTypeInfo().BaseType;
                }
            }

            return false;
        }