Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1267)

Unified Diff: Src/GoogleApis.Tools.CodeGen/Decorator/ResourceDecorator/RequestDecorator/RequestConstructorDecorator.cs

Issue 12020043: Issue 325 - Remove discovery and codegen (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Patch Set: Sir miceli comment Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Src/GoogleApis.Tools.CodeGen/Decorator/ResourceDecorator/RequestDecorator/RequestConstructorDecorator.cs
===================================================================
deleted file mode 100644
--- a/Src/GoogleApis.Tools.CodeGen/Decorator/ResourceDecorator/RequestDecorator/RequestConstructorDecorator.cs
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
-Copyright 2011 Google Inc
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-using System.CodeDom;
-using Google.Apis.Discovery;
-using Google.Apis.Download;
-using Google.Apis.Services;
-using Google.Apis.Testing;
-using Google.Apis.Tools.CodeGen.Generator;
-
-namespace Google.Apis.Tools.CodeGen.Decorator.ResourceDecorator.RequestDecorator
-{
- /// <summary>
- /// Generates the two standard constructors of a request.
- /// 1. A constructor taking the service and mandatory parameters.
- /// 2. A constructor taking the service and all mandatory + optional parameters.
- /// Example:
- /// <c>public ListRequest(ISchemaAwareRequestExecutor service, int requiredParameter, ..) : base(service) {..}</c>
- /// <c>public ListRequest(ISchemaAwareRequestExecutor s, int required, string optional..) : base(service) {..}</c>
- /// </summary>
- public class RequestConstructorDecorator : BaseRequestConstructorDecorator
- {
- internal const string ServiceName = "service";
-
- /// <summary>
- /// Defines whether this decorator should also add a constructor containing optional and mandatory parameters.
- /// </summary>
- public bool CreateOptionalConstructor { get; set; }
-
- /// <summary>
- /// Creates a new request constructor decorator.
- /// </summary>
- /// <remarks>Will create only the mandatory-only constructor</remarks>
- public RequestConstructorDecorator(IObjectTypeProvider objectTypeProvider) : base(objectTypeProvider) { }
-
- #region IRequestDecorator Members
-
- public override void DecorateClass(IResource resource,
- IMethod request,
- CodeTypeDeclaration requestClass,
- CodeTypeDeclaration resourceClass)
- {
- requestClass.Members.Add(CreateRequiredConstructor(resourceClass, request, false));
-
- if (CreateOptionalConstructor && request.HasOptionalParameters())
- {
- requestClass.Members.Add(CreateRequiredConstructor(resourceClass, request, true));
- }
- }
-
- #endregion
-
- /// <summary>
- /// Creates the constructor for this request class which only takes required arguments.
- /// </summary>
- [VisibleForTestOnly]
- internal CodeConstructor CreateRequiredConstructor(CodeTypeDeclaration resourceClass,
- IMethod request,
- bool addOptionalParameters)
- {
- var constructor = new CodeConstructor();
- constructor.Attributes = MemberAttributes.Public;
-
- // ISchemaAwareRequestExecutor service
- var serviceArg = new CodeParameterDeclarationExpression(typeof(IClientService), ServiceName);
- constructor.Parameters.Add(serviceArg);
-
- // : base(service)
- constructor.BaseConstructorArgs.Add(new CodeVariableReferenceExpression(ServiceName));
-
- // Add all required arguments to the constructor.
- AddBodyParameter(constructor, request);
- AddRequestParameters(resourceClass, request, constructor, addOptionalParameters);
-
- // media download
- if (request.SupportMediaDownload)
- {
- // Generates: _mediaDownloader = new MediaDownloader(service);
- var assign = new CodeAssignStatement();
- assign.Left = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(),
- "_mediaDownloader");
- assign.Right = new CodeObjectCreateExpression(typeof(MediaDownloader),
- new CodeVariableReferenceExpression("service"));
- constructor.Statements.Add(assign);
- }
-
- // generate: initParameters()
- constructor.Statements.Add(new CodeMethodInvokeExpression(
- new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), "InitParameters")));
-
- return constructor;
- }
- }
-}

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b