Exemplo n.º 1
0
        private static bool HandleNonPrivateAbstractProperty(SortedSet <string> namespaces, bool requiresObsoleteSuppression,
                                                             List <string> generatedProperties, PropertyMockableResult property, PropertyInfo baseProperty, ParameterInfo[] indexers, MethodInfo propertyMethod)
        {
            var propertyImplementations = new List <string>();
            var visibility = property.RequiresExplicitInterfaceImplementation == RequiresExplicitInterfaceImplementation.Yes ?
                             string.Empty : CodeTemplates.GetVisibility(propertyMethod.IsFamily, propertyMethod.IsFamilyOrAssembly);

            if (property.Accessors == PropertyAccessors.Get || property.Accessors == PropertyAccessors.GetAndSet)
            {
                var getVisibility = CodeTemplates.GetVisibility(baseProperty.GetMethod.IsFamily, baseProperty.GetMethod.IsFamilyOrAssembly);

                if (getVisibility == visibility)
                {
                    getVisibility = string.Empty;
                }

                propertyImplementations.Add(PropertyTemplates.GetNonPublicPropertyGet(getVisibility));
            }

            if (property.Accessors == PropertyAccessors.Set || property.Accessors == PropertyAccessors.GetAndSet)
            {
                var setVisibility = CodeTemplates.GetVisibility(baseProperty.SetMethod.IsFamily, baseProperty.SetMethod.IsFamilyOrAssembly);

                if (setVisibility == visibility)
                {
                    setVisibility = string.Empty;
                }

                propertyImplementations.Add(PropertyTemplates.GetNonPublicPropertySet(setVisibility));
            }

            var explicitInterfaceName = property.RequiresExplicitInterfaceImplementation == RequiresExplicitInterfaceImplementation.Yes ?
                                        $"{property.Value.DeclaringType.GetFullName(namespaces)}." : string.Empty;

            if (indexers.Length > 0)
            {
                var parameters = string.Join(", ",
                                             from indexer in indexers
                                             let _ = namespaces.Add(indexer.ParameterType.Namespace)
                                                     select $"{indexer.ParameterType.Name} {indexer.Name}");

                // Indexer
                generatedProperties.Add(PropertyTemplates.GetNonPublicPropertyIndexer(visibility,
                                                                                      $"{baseProperty.PropertyType.GetFullName(namespaces)}", parameters,
                                                                                      string.Join(Environment.NewLine, propertyImplementations), explicitInterfaceName));
            }
            else
            {
                // Normal
                generatedProperties.Add(PropertyTemplates.GetNonPublicProperty(visibility,
                                                                               $"{baseProperty.PropertyType.GetFullName(namespaces)}", baseProperty.Name,
                                                                               string.Join(Environment.NewLine, propertyImplementations), explicitInterfaceName));
            }

            requiresObsoleteSuppression |= baseProperty.GetCustomAttribute <ObsoleteAttribute>() != null;
            return(requiresObsoleteSuppression);
        }