Ejemplo n.º 1
0
        private static bool HandlePublicProperty(SortedSet <string> namespaces, bool isMake, bool hasEvents,
                                                 bool requiresObsoleteSuppression, List <string> generatedProperties, PropertyMockableResult property,
                                                 PropertyInfo baseProperty, ParameterInfo[] indexers, string @override)
        {
            var propertyImplementations = new List <string>();
            var parameter = property.Accessors == PropertyAccessors.Get || property.Accessors == PropertyAccessors.GetAndSet ?
                            baseProperty.GetGetMethod().ReturnParameter :
                            baseProperty.GetSetMethod().GetParameters()[0];

            if (property.Accessors == PropertyAccessors.Get || property.Accessors == PropertyAccessors.GetAndSet)
            {
                PropertiesGenerator.HandlePublicGetter(namespaces, isMake, hasEvents, baseProperty, propertyImplementations);
            }

            if (property.Accessors == PropertyAccessors.Set || property.Accessors == PropertyAccessors.GetAndSet)
            {
                PropertiesGenerator.HandlePublicSetter(isMake, hasEvents, baseProperty, propertyImplementations);
            }

            var visibility = property.RequiresExplicitInterfaceImplementation == RequiresExplicitInterfaceImplementation.Yes ?
                             string.Empty : CodeTemplates.Public;
            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.GetPropertyIndexer(
                                            $"{@override}{baseProperty.PropertyType.GetFullName(namespaces, parameter)}", parameters,
                                            string.Join(Environment.NewLine, propertyImplementations), visibility, explicitInterfaceName,
                                            baseProperty.GetCustomAttributesData().GetAttributes(namespaces)));
            }
            else
            {
                // Normal
                var propertyAttributes = baseProperty.GetCustomAttributesData().ToList();

                var setterMethod = baseProperty.GetSetMethod();

                if (setterMethod is { })
Ejemplo n.º 2
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);
        }