コード例 #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));
            }
            else
            {
                // Normal
                generatedProperties.Add(PropertyTemplates.GetProperty(
                                            $"{@override}{baseProperty.PropertyType.GetFullName(namespaces, parameter)}", baseProperty.Name,
                                            string.Join(Environment.NewLine, propertyImplementations), visibility, explicitInterfaceName));
            }

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