internal CodeStatementCollection CreateSubresourceCreateStatements(IResource resource)
        {
            var initializers = new CodeStatementCollection();
            ICollection <string> otherResourceNames = resource.Resources.Keys;

            foreach (IResource subresource in resource.Resources.Values)
            {
                IEnumerable <string> relevantResourceNames = otherResourceNames.Without(subresource.Name);

                // Retrieve backing field name and type of the (already created) subresource
                var fieldRef  = ServiceClassGenerator.GetFieldReference(subresource, relevantResourceNames);
                var fieldType = GeneratorUtils.GetClassName(subresource, relevantResourceNames);

                // ... new SubResource(service);
                var fieldConstructor = new CodeObjectCreateExpression(fieldType);
                fieldConstructor.Parameters.Add(
                    new CodeVariableReferenceExpression(ResourceBaseGenerator.ServiceFieldName));
                fieldConstructor.Parameters.Add(
                    new CodeVariableReferenceExpression(ResourceClassGenerator.AuthenticatorName));

                // subResource = ...
                var assign = new CodeAssignStatement(fieldRef, fieldConstructor);
                initializers.Add(assign);
            }

            return(initializers);
        }
        internal CodeMemberProperty CreateResourceGetter(IResource resource,
                                                         IEnumerable <string> otherResourceNames)
        {
            var getter = new CodeMemberProperty();

            getter.Name       = GeneratorUtils.GetPropertyName(resource.Name, otherResourceNames);
            getter.HasGet     = true;
            getter.HasSet     = false;
            getter.Attributes = MemberAttributes.Public;
            getter.Type       = new CodeTypeReference(GeneratorUtils.GetClassName(resource, otherResourceNames));
            getter.GetStatements.Add(
                new CodeMethodReturnStatement(ServiceClassGenerator.GetFieldReference(resource, otherResourceNames)));

            return(getter);
        }
Example #3
0
        private void AddResourceAssignment(CodeMemberMethod constructor,
                                           IResource resource,
                                           int resourceNumber,
                                           IEnumerable <string> otherResourceNames)
        {
            IEnumerable <string> otherNames = otherResourceNames.Without(resource.Name);

            // Generate:  _files = new FilesResource(this, authenticator);
            constructor.Statements.Add(
                new CodeAssignStatement(
                    ServiceClassGenerator.GetFieldReference(resource, otherNames),
                    new CodeObjectCreateExpression(
                        GeneratorUtils.GetClassName(resource, otherNames),
                        new CodeThisReferenceExpression(),
                        new CodeVariableReferenceExpression(ServiceClassGenerator.AuthenticatorPropertyName))));
        }
Example #4
0
        internal CodeNamespace GenerateClientCode()
        {
            var clientNamespace = CreateNamespace(codeClientNamespace);

            ResourceContainerGenerator resourceContainerGenerator =
                new ResourceContainerGenerator(resourceContainerDecorators);
            var requestClassGenerator = new RequestClassGenerator(
                GetSchemaAwareCommonRequestDecorators(DataNamespace(codeClientNamespace), service),
                GetSchemaAwareRequestDecorators(DataNamespace(codeClientNamespace), service),
                GetSchemaAwareUploadDecorators(DataNamespace(codeClientNamespace), service));

            var serviceClass =
                new ServiceClassGenerator(service, serviceDecorators, resourceContainerGenerator).CreateServiceClass();
            string serviceClassName = serviceClass.Name;

            clientNamespace.Types.Add(serviceClass);
            CreateResources(
                clientNamespace, serviceClassName, service, requestClassGenerator, resourceContainerGenerator);

            return(clientNamespace);
        }