CapitalizeFirstChar() static private method

Capitalizes the first character of a string, used to create proper naming for services, attributes, and operations
static private CapitalizeFirstChar ( string text ) : string
text string The string to capitalize the first character of
return string
Exemplo n.º 1
0
        /// <summary>
        /// Creates a shape with a reference to the model it's a part of, its name, and the json data of the shape pulled from the model.
        /// Shapes are used to model structures and member types. If they are a structure the shape
        /// defines what members it has and what shape those members are. It also defines which of those
        /// members are required. If it is not a structure then it is used to specify the type of the member and its properties.
        /// </summary>
        /// <param name="model">The model that contains the shape</param>
        /// <param name="name">The name of the shape</param>
        /// <param name="data">The json object of the shape, pulled form the model json</param>
        public Shape(ServiceModel model, string name, JsonData data)
            : base(model, data)
        {
            this._name = ServiceModel.CapitalizeFirstChar(name);
            var nameOverride = this.model.Customizations.GetOverrideShapeName(this._name);

            if (nameOverride != null)
            {
                this._name = nameOverride;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates an enumeration that can model parts of the enumeration for the service
        /// </summary>
        /// <param name="model">The service model that is using the enumartion</param>
        /// <param name="name">The name of the enumeration</param>
        /// <param name="data">The json data for the enumartion object</param>
        public Enumeration(ServiceModel model, string name, JsonData data)
        {
            this.model = model;
            _modelName = name;
            _data      = data;

            var overrideName = model.Customizations.GetOverrideShapeName(_modelName);

            _outputName = !string.IsNullOrEmpty(overrideName)
                ? ServiceModel.CapitalizeFirstChar(overrideName)
                : ServiceModel.CapitalizeFirstChar(_modelName);
        }
Exemplo n.º 3
0
        public string GetSerializationInfoMethodName()
        {
            var simpleTypeName = DetermineType();

            switch (simpleTypeName)
            {
            case "string":
            case "boolean":
            case "double":
                return("Get" + ServiceModel.CapitalizeFirstChar(simpleTypeName));

            case "float":
                return("GetSingle");

            case "integer":
                return("GetInt32");

            case "long":
                return("GetInt64");

            default:
                throw new Exception("Unknown serialization type " + simpleTypeName);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Determines the type of the member based on customizations, if it isn't custom then it pulls
        /// from the full json model to get the shape of this member
        /// </summary>
        /// <param name="extendedData">The json data from the parent shape model</param>
        /// <param name="treatEnumsAsString">If true all any found enum type will be returned as a string</param>
        /// <returns></returns>
        private string DetermineType(JsonData extendedData, bool treatEnumsAsString)
        {
            JsonData typeNode = null;
            // Check to see if customizations is overriding - first by simple type remap
            // and then via more extensive customization. If we are handed a collection
            // shape to begin with, this check is whether the collection shape, not the
            // collected type, is remapped.

            /*var remapAsShapeName = this.model.Customizations.GetSubstituteShapeName(this.Shape.Name);
             * if (remapAsShapeName != null)
             * {
             *  var remappedShape = this.model.FindShape(remapAsShapeName);
             *  if (remappedShape == null)
             *      throw new Exception(string.Format("Found shape remap from {0} to {1} but no such shape in model!",
             *                                        this.Shape.Name, remapAsShapeName));
             *  if (remappedShape.IsStructure)
             *      return remapAsShapeName;
             *
             *  switch (remappedShape.Type)
             *  {
             *      case "boolean":
             *          return "bool";
             *      case "integer":
             *          return "int";
             *      case "timestamp":
             *          return "DateTime";
             *      default:
             *          return remappedShape.Type;
             *  }
             * }*/

            var overrideType = this.model.Customizations.OverrideDataType(OwningShape.Name, this._name);

            if (overrideType != null)
            {
                this._newType = overrideType.DataType;
                return(overrideType.DataType);
            }

            var extendsNode = extendedData[ServiceModel.ShapeKey];

            if (extendsNode == null)
            {
                throw new Exception("Missing extends for member " + this._name);
            }

            JsonData memberShape = null;
            // if this shape is a collection, has the collected type been remapped?
            var emitAsShapeName = this.model.Customizations.GetSubstituteShapeName(extendsNode.ToString());
            var renameShape     = this.model.Customizations.GetOverrideShapeName(extendsNode.ToString());

            if (emitAsShapeName == null)
            {
                memberShape = this.model.DocumentRoot[ServiceModel.ShapesKey][extendsNode.ToString()];
                typeNode    = memberShape[Shape.TypeKey];
            }
            else
            {
                // we only handle remap to one level at present
                memberShape = this.model.DocumentRoot[ServiceModel.ShapesKey][emitAsShapeName];
                typeNode    = memberShape[Shape.TypeKey];
            }

            if (typeNode == null)
            {
                throw new Exception("Type is missing for shape " + extendsNode.ToString());
            }

            switch (typeNode.ToString())
            {
            case "string":
                if (!treatEnumsAsString && memberShape["enum"] != null)
                {
                    return(ServiceModel.CapitalizeFirstChar(extendsNode.ToString()));
                }
                return("string");

            case "blob":
                if (this.IsStreaming)
                {
                    return("Stream");
                }
                return("MemoryStream");

            case "boolean":
                return("bool");

            case "double":
                return("double");

            case "float":
                return("float");

            case "integer":
                return("int");

            case "long":
                return("long");

            case "timestamp":
                return("DateTime");

            case "structure":
                return(emitAsShapeName ?? renameShape ?? extendsNode.ToString());

            case "map":
                var keyType   = DetermineType(memberShape["key"], true);
                var valueType = DetermineType(memberShape["value"], true);
                return(string.Format("Dictionary<{0}, {1}>", keyType, valueType));

            case "list":
                var listType = DetermineType(memberShape["member"], true);
                return(string.Format("List<{0}>", listType));

            default:
                throw new Exception("Unknown type " + typeNode.ToString());
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Creates an enumeration that can model parts of the enumeration for the service
 /// </summary>
 /// <param name="model">The service model that is using the enumartion</param>
 /// <param name="name">The name of the enumeration</param>
 /// <param name="data">The json data for the enumartion object</param>
 public Enumeration(ServiceModel model, string name, JsonData data)
 {
     this.model = model;
     this._name = ServiceModel.CapitalizeFirstChar(name);
     this._data = data;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a shape with a reference to the model it's a part of, its name, and the json data of the shape pulled from the model.
 /// Shapes are used to model structures and member types. If they are a structure the shape
 /// defines what members it has and what shape those members are. It also defines which of those
 /// members are required. If it is not a structure then it is used to specify the type of the member and its properties.
 /// </summary>
 /// <param name="model">The model that contains the shape</param>
 /// <param name="name">The name of the shape</param>
 /// <param name="data">The json object of the shape, pulled form the model json</param>
 public Shape(ServiceModel model, string name, JsonData data)
     : base(model, data)
 {
     this._name = ServiceModel.CapitalizeFirstChar(name);
 }