internal CodeTypeMemberCollection CreateServiceParametersProperty()
        {
            var property = DecoratorUtil.CreateAutoProperty(
                ServiceParametersName, string.Empty, new CodeTypeReference(typeof(IDictionary <string, IParameter>)),
                Enumerable.Empty <string>(), true, null, MemberAttributes.Override | MemberAttributes.Public);

            return(property);
        }
        public void DecorateClass(IService service, CodeTypeDeclaration serviceClass)
        {
            CodeTypeMemberCollection col = DecoratorUtil.CreateAutoProperty(
                PropertyName, "Sets the API-Key (or DeveloperKey) which this service uses for all requests",
                new CodeTypeReference(typeof(string)), GeneratorUtils.GetUsedWordsFromMembers(serviceClass.Members),
                false, null);

            serviceClass.Members.AddRange(col);
        }
        /// <summary>Generates an <seealso cref="Google.Apis.Download.IMediaDownloader"/> property.</summary>
        private static void GenerateMediaDownloaderProperty(CodeTypeDeclaration requestClass)
        {
            // Generates:
            // private IMediaDownloader _mediaDownloader;
            // public IMediaDownloader MediaDownloader { get { return _mediaDownloader; } }

            foreach (CodeTypeMember memeber in DecoratorUtil.CreateAutoProperty("mediaDownloader", null,
                                                                                new CodeTypeReference(typeof(IMediaDownloader)), new List <string>(), true))
            {
                requestClass.Members.Add(memeber);
            }
        }
        public void CreateAutoPropertyEdgeCaseTest()
        {
            const string      name    = "TestProperty";
            const string      comment = "Comment";
            CodeTypeReference type    = new CodeTypeReference(typeof(object));

            string[] usedWords = new string[] { };

            Assert.Throws <ArgumentNullException>(
                () => DecoratorUtil.CreateAutoProperty(null, comment, type, usedWords, false));
            Assert.Throws <ArgumentNullException>(
                () => DecoratorUtil.CreateAutoProperty(name, comment, null, usedWords, false));
            Assert.Throws <ArgumentNullException>(
                () => DecoratorUtil.CreateAutoProperty(name, comment, type, null, false));
            Assert.DoesNotThrow(() => DecoratorUtil.CreateAutoProperty(name, null, type, usedWords, false));
        }
Exemple #5
0
        internal static CodeTypeMemberCollection CreateETagProperty(CodeTypeDeclaration typeDeclaration)
        {
            CodeMemberProperty property = typeDeclaration.Members.FindPropertyByName(ETagPropertyName);

            if (property != null)
            {
                if (property.ImplementationTypes.Count == 0)
                {
                    property.ImplementationTypes.Add(new CodeTypeReference(typeof(IDirectResponseSchema)));
                }
                return(new CodeTypeMemberCollection()); // Don't add a new property; it's already there.
            }

            CodeTypeReference type = new CodeTypeReference(typeof(string));

            return(DecoratorUtil.CreateAutoProperty(ETagPropertyName, null, type, Enumerable.Empty <string>(), false, typeof(IDirectResponseSchema)));
        }
Exemple #6
0
        internal static CodeTypeMemberCollection CreateErrorProperty(CodeTypeDeclaration typeDeclaration)
        {
            CodeTypeReference        type = new CodeTypeReference(typeof(RequestError));
            CodeTypeMemberCollection col  = DecoratorUtil.CreateAutoProperty(
                ErrorPropertyName, null, type, Enumerable.Empty <string>(), false, typeof(IDirectResponseSchema));

            // Find the created property and add the JsonProperty to it.
            foreach (CodeTypeMember member in col)
            {
                if (member is CodeMemberProperty)
                {
                    member.CustomAttributes.Add(NewtonSoftPropertyAttributeDecorator.CreateAttribute(ErrorJsonName));
                    break;
                }
            }

            return(col);
        }
        internal CodeTypeMemberCollection GenerateParameterProperty(IDiscoveryParameter parameter,
                                                                    IMethod method,
                                                                    CodeTypeDeclaration resourceClass,
                                                                    IEnumerable <string> usedNames)
        {
            // Get the name and return type of this parameter.
            string            name       = parameter.Name;
            CodeTypeReference returnType = ResourceBaseGenerator.GetParameterTypeReference(
                resourceClass, parameter);

            // Generate the property and field.
            CodeTypeMemberCollection newMembers = DecoratorUtil.CreateAutoProperty(
                name, parameter.Description, returnType, usedNames, parameter.IsRequired, null);

            // Add the KeyAttribute to the property.
            foreach (CodeTypeMember member in newMembers)
            {
                CodeMemberProperty property = member as CodeMemberProperty;
                if (property == null)
                {
                    continue;
                }

                RequestParameterType requestParameterType =
                    parameter.ParameterType == PathParameter ? RequestParameterType.Path : RequestParameterType.Query;

                // Declare the RequestParameter attribute.
                CodeTypeReference attributeType = new CodeTypeReference(typeof(RequestParameterAttribute));

                // Generates something like..
                // [Google.Apis.Util.RequestParameterAttribute("prettyPrint",
                //   Google.Apis.Util.RequestParameterType.Query)]
                CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(attributeType);
                attribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(parameter.Name)));
                attribute.Arguments.Add(
                    new CodeAttributeArgument(
                        new CodeFieldReferenceExpression(
                            new CodeTypeReferenceExpression(typeof(RequestParameterType)),
                            Enum.GetName(typeof(RequestParameterType), requestParameterType))));
                property.CustomAttributes.Add(attribute);
            }

            return(newMembers);
        }
        public void CreateAutoPropertyTest()
        {
            const string      name    = "TestProperty";
            const string      comment = "Comment";
            CodeTypeReference type    = new CodeTypeReference(typeof(int));

            string[] usedWords = new string[] { };

            CodeTypeMemberCollection col = DecoratorUtil.CreateAutoProperty(name, comment, type, usedWords, false);

            Assert.That(col.Count, Is.EqualTo(2));
            Assert.That(col[1], Is.InstanceOf <CodeMemberProperty>());
            Assert.That(col[1].Attributes, Is.EqualTo(MemberAttributes.Public));
            Assert.That(col[0], Is.InstanceOf <CodeMemberField>());

            var property = col[1] as CodeMemberProperty;

            Assert.IsNotNull(property);
            Assert.That(property.Name, Is.EqualTo(name));
            Assert.That(property.Type.BaseType, Is.EqualTo(typeof(int).FullName));

            // Backening field is tested in its own unit case.
        }
 internal CodeTypeMemberCollection GenerateBodyProperty(IMethod request, CodeTypeReference bodyType)
 {
     return(DecoratorUtil.CreateAutoProperty(
                BodyPropertyName, BodyPropertyComment, bodyType, Enumerable.Empty <string>(), false, null));
 }