Exemplo n.º 1
0
    public static IEnumerable <PropertyDefinition> EnumerateOverridesAndImplementations(this PropertyDefinition property)
    {
        if (!property.HasThis)
        {
            yield break;
        }

        var propertyOverrides = property.EnumerateOverrides().ToArray();

        if (propertyOverrides.Any())
        {
            foreach (var propertyOverride in propertyOverrides)
            {
                yield return(propertyOverride);
            }

            yield break;
        }

        var declaringType = property.GetMethod?.DeclaringType;

        if (declaringType != null)
        {
            foreach (var interfaceType in declaringType.EnumerateInterfaces(declaringType))
            {
                var interfaceProperty = interfaceType.Find(property);
                if (interfaceProperty == null)
                {
                    continue;
                }

                if (declaringType.HasExplicitInterfaceImplementation(property))
                {
                    continue;
                }

                yield return(interfaceProperty);
            }
        }

        var baseProperty = property.GetBaseProperty();

        if (baseProperty != null)
        {
            yield return(baseProperty);

            foreach (var baseImplementation in baseProperty.EnumerateOverridesAndImplementations())
            {
                yield return(baseImplementation);
            }
        }
    }