Exemple #1
0
        private List <KeyValuePair <String, Entidad> > comenzarObjeto(bool conEtiqueta = true)
        {
            List <KeyValuePair <String, Entidad> > resultado = new List <KeyValuePair <String, Entidad> >();
            //Comenzamos el objeto
            KeyValuePair <char, String> comienzo = mc.cogerCadena(new char[] { '{', ']' });
            char c = comienzo.Key;

            while (c != '}' && c != ']' && c != '\0')
            {
                String etiqueta = "";
                if (conEtiqueta)
                {
                    KeyValuePair <char, String> etiquetaLeida = mc.cogerCadena(new char[] { ':', '}' });
                    if (etiquetaLeida.Key == '}' || etiquetaLeida.Key == '\0')
                    {
                        return(resultado);
                    }
                    etiqueta = etiquetaLeida.Value.Trim();
                    etiqueta = etiqueta.Substring(1, etiqueta.Length - 2).Trim();
                }
                KeyValuePair <char, String> valorLeido = mc.cogerCadena(new char[] { '{', ',', '}', '[' });
                Object valor = valorLeido.Value;
                c = valorLeido.Key;
                TIPO_ENTIDAD tipo = TIPO_ENTIDAD.String;
                switch (c)
                {
                case ',':
                case '}':
                    valor = ((string)valor).Trim();
                    if (((string)valor)[0] != '"')
                    {
                        if (((string)valor).IndexOf('T') > 0)
                        {
                            tipo = TIPO_ENTIDAD.Date;
                            //TODO: Castear la fecha
                        }
                        else
                        {
                            tipo = TIPO_ENTIDAD.Numeric;
                            try {
                                if (valor == null)
                                {
                                    valor = 0;
                                }
                                else
                                {
                                    valor = double.Parse(valor.ToString().Replace(".", ","));
                                }
                            } catch {
                                valor = 0;
                            }
                        }
                    }
                    else
                    {
                        valor = ((string)valor).Substring(1, ((string)valor).Length - 2);
                    }
                    resultado.Add(new KeyValuePair <String, Entidad>(etiqueta,
                                                                     new Entidad(valor,
                                                                                 tipo
                                                                                 )));
                    break;

                case '[':
                    List <Dictionary <string, Entidad> > elementos = cogerElementos();
                    resultado.Add(new KeyValuePair <String, Entidad>(etiqueta,
                                                                     new Entidad(elementos,
                                                                                 TIPO_ENTIDAD.Array
                                                                                 )));
                    valorLeido = mc.cogerCadena(new char[] { ',', '}' });
                    c          = valorLeido.Key;
                    break;

                case '{':
                    mc.saltar(-1);
                    List <KeyValuePair <String, Entidad> > objetos     = comenzarObjeto(true);
                    Dictionary <string, Entidad>           diccionario = new Dictionary <string, Entidad>();
                    foreach (KeyValuePair <String, Entidad> objeto in objetos)
                    {
                        diccionario[objeto.Key] = objeto.Value;
                    }
                    resultado.Add(new KeyValuePair <String, Entidad>(etiqueta,
                                                                     new Entidad(diccionario,
                                                                                 TIPO_ENTIDAD.Entidad
                                                                                 )));
                    valorLeido = mc.cogerCadena(new char[] { ',', '}' });
                    c          = valorLeido.Key;
                    break;
                }
                //System.Diagnostics.Trace.WriteLine(etiqueta + "=" + valor);
            }

            return(resultado);
        }
Exemple #2
0
 public Entidad(Object _valor, TIPO_ENTIDAD _tipo)
 {
     valor = _valor;
     tipo  = _tipo;
 }