text: ﻿// Copyright 2017 DAIMTO ([Linda Lawton](https://twitter.com/LindaLawtonDK)) :  [www.daimto.com](http://www.daimto.com/)
  //
  // 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.
  //------------------------------------------------------------------------------
  // <auto-generated>
  //     This code was generated by DAIMTO-Google-apis-Sample-generator 1.0.0
  //     Template File Name:  methodTemplate.tt
  //     Build date: 2017-10-08
  //     C# generater version: 1.0.0
  //     
  //     Changes to this file may cause incorrect behavior and will be lost if
  //     the code is regenerated.
  // </auto-generated>
  //------------------------------------------------------------------------------  
  // About 
  // 
  // Unoffical sample for the Fusiontables v2 API for C#. 
  // This sample is designed to be used with the Google .Net client library. (https://github.com/google/google-api-dotnet-client)
  // 
  // API Description: API for working with Fusion Tables data.
  // API Documentation Link https://developers.google.com/fusiontables
  //
  // Discovery Doc  https://www.googleapis.com/discovery/v1/apis/Fusiontables/v2/rest
  //
  //------------------------------------------------------------------------------
  // Installation
  //
  // This sample code uses the Google .Net client library (https://github.com/google/google-api-dotnet-client)
  //
  // NuGet package:
  //
  // Location: https://www.nuget.org/packages/Google.Apis.Fusiontables.v2/ 
  // Install Command: PM>  Install-Package Google.Apis.Fusiontables.v2
  //
  //------------------------------------------------------------------------------  
  using Google.Apis.Fusiontables.v2;
  using Google.Apis.Fusiontables.v2.Data;
  using System;
  
  namespace GoogleSamplecSharpSample.Fusiontablesv2.Methods
  {
    
      public static class StyleSample
      {
  
  
          /// <summary>
          /// Deletes a style. 
          /// Documentation https://developers.google.com/fusiontables/v2/reference/style/delete
          /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
          /// </summary>
          /// <param name="service">Authenticated Fusiontables service.</param>  
          /// <param name="tableId">Table from which the style is being deleted</param>
          /// <param name="styleId">Identifier (within a table) for the style being deleted</param>
          public static void Delete(FusiontablesService service, string tableId, int? styleId)
          {
              try
              {
                  // Initial validation.
                  if (service == null)
                      throw new ArgumentNullException("service");
                  if (tableId == null)
                      throw new ArgumentNullException(tableId);
                  if (styleId == null)
                      throw new ArgumentNullException(styleId);
  
                  // Make the request.
                   service.Style.Delete(tableId, styleId).Execute();
              }
              catch (Exception ex)
              {
                  throw new Exception("Request Style.Delete failed.", ex);
              }
          }
  
          /// <summary>
          /// Gets a specific style. 
          /// Documentation https://developers.google.com/fusiontables/v2/reference/style/get
          /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
          /// </summary>
          /// <param name="service">Authenticated Fusiontables service.</param>  
          /// <param name="tableId">Table to which the requested style belongs</param>
          /// <param name="styleId">Identifier (integer) for a specific style in a table</param>
          /// <returns>StyleSettingResponse</returns>
          public static StyleSetting Get(FusiontablesService service, string tableId, int? styleId)
          {
              try
              {
                  // Initial validation.
                  if (service == null)
                      throw new ArgumentNullException("service");
                  if (tableId == null)
                      throw new ArgumentNullException(tableId);
                  if (styleId == null)
                      throw new ArgumentNullException(styleId);
  
                  // Make the request.
                  return service.Style.Get(tableId, styleId).Execute();
              }
              catch (Exception ex)
              {
                  throw new Exception("Request Style.Get failed.", ex);
              }
          }
  
          /// <summary>
          /// Adds a new style for the table. 
          /// Documentation https://developers.google.com/fusiontables/v2/reference/style/insert
          /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
          /// </summary>
          /// <param name="service">Authenticated Fusiontables service.</param>  
          /// <param name="tableId">Table for which a new style is being added</param>
          /// <param name="body">A valid Fusiontables v2 body.</param>
          /// <returns>StyleSettingResponse</returns>
          public static StyleSetting Insert(FusiontablesService service, string tableId, StyleSetting body)
          {
              try
              {
                  // Initial validation.
                  if (service == null)
                      throw new ArgumentNullException("service");
                  if (body == null)
                      throw new ArgumentNullException("body");
                  if (tableId == null)
                      throw new ArgumentNullException(tableId);
  
                  // Make the request.
                  return service.Style.Insert(body, tableId).Execute();
              }
              catch (Exception ex)
              {
                  throw new Exception("Request Style.Insert failed.", ex);
              }
          }
          public class StyleListOptionalParms
          {
              /// Maximum number of styles to return. Optional. Default is 5.
              public int? MaxResults { get; set; }  
              /// Continuation token specifying which result page to return. Optional.
              public string PageToken { get; set; }  
          
          }
   
          /// <summary>
          /// Retrieves a list of styles. 
          /// Documentation https://developers.google.com/fusiontables/v2/reference/style/list
          /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
          /// </summary>
          /// <param name="service">Authenticated Fusiontables service.</param>  
          /// <param name="tableId">Table whose styles are being listed</param>
          /// <param name="optional">Optional paramaters.</param>
          /// <returns>StyleSettingListResponse</returns>
          public static StyleSettingList List(FusiontablesService service, string tableId, StyleListOptionalParms optional = null)
          {
              try
              {
                  // Initial validation.
                  if (service == null)
                      throw new ArgumentNullException("service");
                  if (tableId == null)
                      throw new ArgumentNullException(tableId);
  
                  // Building the initial request.
                  var request = service.Style.List(tableId);
  
                  // Applying optional parameters to the request.                
                  request = (StyleResource.ListRequest)SampleHelpers.ApplyOptionalParms(request, optional);
  
                  // Requesting data.
                  return request.Execute();
              }
              catch (Exception ex)
              {
                  throw new Exception("Request Style.List failed.", ex);
              }
          }
  
          /// <summary>
          /// Updates an existing style. This method supports patch semantics. 
          /// Documentation https://developers.google.com/fusiontables/v2/reference/style/patch
          /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
          /// </summary>
          /// <param name="service">Authenticated Fusiontables service.</param>  
          /// <param name="tableId">Table whose style is being updated.</param>
          /// <param name="styleId">Identifier (within a table) for the style being updated.</param>
          /// <param name="body">A valid Fusiontables v2 body.</param>
          /// <returns>StyleSettingResponse</returns>
          public static StyleSetting Patch(FusiontablesService service, string tableId, int? styleId, StyleSetting body)
          {
              try
              {
                  // Initial validation.
                  if (service == null)
                      throw new ArgumentNullException("service");
                  if (body == null)
                      throw new ArgumentNullException("body");
                  if (tableId == null)
                      throw new ArgumentNullException(tableId);
                  if (styleId == null)
                      throw new ArgumentNullException(styleId);
  
                  // Make the request.
                  return service.Style.Patch(body, tableId, styleId).Execute();
              }
              catch (Exception ex)
              {
                  throw new Exception("Request Style.Patch failed.", ex);
              }
          }
  
          /// <summary>
          /// Updates an existing style. 
          /// Documentation https://developers.google.com/fusiontables/v2/reference/style/update
          /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
          /// </summary>
          /// <param name="service">Authenticated Fusiontables service.</param>  
          /// <param name="tableId">Table whose style is being updated.</param>
          /// <param name="styleId">Identifier (within a table) for the style being updated.</param>
          /// <param name="body">A valid Fusiontables v2 body.</param>
          /// <returns>StyleSettingResponse</returns>
          public static StyleSetting Update(FusiontablesService service, string tableId, int? styleId, StyleSetting body)
          {
              try
              {
                  // Initial validation.
                  if (service == null)
                      throw new ArgumentNullException("service");
                  if (body == null)
                      throw new ArgumentNullException("body");
                  if (tableId == null)
                      throw new ArgumentNullException(tableId);
                  if (styleId == null)
                      throw new ArgumentNullException(styleId);
  
                  // Make the request.
                  return service.Style.Update(body, tableId, styleId).Execute();
              }
              catch (Exception ex)
              {
                  throw new Exception("Request Style.Update failed.", ex);
              }
          }
          
          }
  
          public static class SampleHelpers
          {
  
          /// <summary>
          /// Using reflection to apply optional parameters to the request.  
          /// 
          /// If the optonal parameters are null then we will just return the request as is.
          /// </summary>
          /// <param name="request">The request. </param>
          /// <param name="optional">The optional parameters. </param>
          /// <returns></returns>
          public static object ApplyOptionalParms(object request, object optional)
          {
              if (optional == null)
                  return request;
  
              System.Reflection.PropertyInfo[] optionalProperties = (optional.GetType()).GetProperties();
  
              foreach (System.Reflection.PropertyInfo property in optionalProperties)
              {
                  // Copy value from optional parms to the request.  They should have the same names and datatypes.
                  System.Reflection.PropertyInfo piShared = (request.GetType()).GetProperty(property.Name);
  				if (property.GetValue(optional, null) != null) // TODO Test that we do not add values for items that are null
  					piShared.SetValue(request, property.GetValue(optional, null), null);
              }
  
              return request;
          }
      }
  }