Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 14
  1. #1

    [C#] PHP_Serializer , mi dareste un parere ?

    Salve, è il mio secondo giorno in C# e stò tentando di imparare, quindi vi chiederei di non insultarmi


    Visto che mi stò esercitando ho pensato, come prima cosa, di provare a fare una classe che secondo me un domani potrà tornarmi utile per l'implementazione in .NET di AJSHP ( sistema alternativo ajax che sfrutta alla base l' oggetto javascript PHP_Serializer .. sempre scritto da me ) in modo da inviare e ricevere dati con tipo assegnato senza dover per forza passare per JSON.

    Maggiori dettagli li trovate sul sito, ma non sono qui per fare pubblicità o spam, sono qui per sapere cosa ne pensate di questa mia prima classe in C# .

    Amici mi hanno già detto che è incomprensibile ... quindi vi spiego subito perchè ho scelto questi nomi:

    __ => lo uso in prefisso per metodi o variabili private
    u => lo utilizzo per indicare prefisso metodo di unserializzazione
    s => lo uso per indicare un metodo di serializzazione
    i => intero
    b => booleano
    d => double
    a => Array [Hashtable per voi]
    O => Oggetto [SortedList per voi]
    N => null

    questi i tipi di variabili in serializzazione PHP e compatibili con JavaScript e la PHP_Serializer

    di qui

    __us => metodo di deserializzazione stringa ... e così via
    __ss => metodo di serializzazione stringa .. e così via


    ultimo,
    __c , variabile che indica da quale numero di carattere cercare
    __s , stringa , in unserializzazione, di riferimento, dove operare

    Ecco la classe (alleluia)
    Codice PHP:
    class PHP_Serializer {
            
    // Andrea Giamamrchi [2006/02/09]
            
    private int __c;
            private 
    string __s;
            public 
    PHP_Serializer() {}
            public 
    string serialize(object what)
            {
                    
    string __s;
                    if (
    what is int)
                            
    __s __si((int) what);
                    else if (
    what is double)
                            
    __s __sd((double) what);
                    else if (
    what is bool)
                            
    __s __sb((bool) what);
                    else if (
    what is string)
                            
    __s __ss((string) what);
                    else if (
    what is System.Collections.Hashtable)
                            
    __s __sa((System.Collections.Hashtablewhat);
                    else if (
    what is System.Collections.SortedList)
                            
    __s __sO((System.Collections.SortedList)what);
                    else if (
    what == null)
                            
    __s "N;";
                    else
                            
    __s "";
                    return 
    __s;
            }
            public 
    object unserialize(string what)
            {
                    
    __c 0;
                    
    __s what;
                    return 
    __switchFunction(__s.Substring(__c1));
            }
            private 
    string __ss(string s
            {
                    return 
    "s:" s.Length ":\"" "\";";
            }
            private 
    string __sb(bool b)
            {
                    return 
    "b:" + (== false "0" "1") + ";";
            }
            private 
    string __sN(object N)
            {
                    return 
    "N;";
            }
            private 
    string __si(int i)
            {
                    return 
    "i:" ";";
            }
            private 
    string __sd(double d)
            {
                    return 
    "d:" d.ToString().Replace(
                    
    System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator".") + ";";
            }
            private 
    string __sa(System.Collections.Hashtable a)
            {
                    return 
    "a:" a.Count "{" __sct(a) + "}";
            }
            private 
    string __sO(System.Collections.SortedList O)
            {
                    return 
    "O:" O["__name__"].ToString().Length ":\"" O["__name__"] + "\":" + (O.Count 1) + ":{" __sct(O) + "}";
            }
            private 
    string __sct(System.Collections.Hashtable a)
            {
                    
    string __s "";
                    foreach (
    DictionaryEntry r in a)
                            
    __s += serialize(r.Key) + "" serialize(r.Value);
                    return 
    __s;
            }
            private 
    string __sct(System.Collections.SortedList O)
            {
                    
    string kv,  __s "";
                    foreach (
    DictionaryEntry r in O)
                    {
                            
    r.Key.ToString();
                            
    serialize(r.Value);
                            if (
    != "__name__") {
                                    
    serialize(k);
                                    if(
    != "" && != "")
                                            
    __s += "" v;
                            }
                                    
                    }
                    return 
    __s;
            }
            private 
    string __us()
            {
                    
    int slisli2;
                    
    string sls;
                    
    __c += 2;
                    
    sls __s.Substring(__c, (__s.IndexOf(':'__c) - __c));
                    
    sli System.Convert.ToInt32(sls);
                    
    sli2 __c sls.Length 2;
                    
    __c sli2 sli 2;
                    return 
    __s.Substring(sli2sli); 
            }
            private 
    int __ui() 
            {
                    
    int sli __s.IndexOf(';', (__c+1))-2;
                    
    int tmp System.Convert.ToInt32(__s.Substring((__c+2),(sli-__c)));
                    
    __c sli 3;
                    return 
    tmp;
            }
            private 
    double __ud()
            {
                    
    int sli __s.IndexOf(';', (__c 1)) - 2;
                    
    double tmp System.Convert.ToDouble(__s.Substring((__c 2),(sli __c)).Replace(
                            
    "."System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator));
                    
    __c sli 3;
                    return 
    tmp;
            }
            private 
    bool __ub()
            {
                    
    bool tmp = (__s.Substring(__c+2,1)=="1"?true:false);
                    
    __c += 4;
                    return 
    tmp;
            }
            private 
    object __uN()
            {
                    
    __c += 2;
                    return 
    null;
            }
            private 
    int __uGetKforWhile() {
                    
    int ak;
                    
    __c += 2;
                    
    __s.IndexOf(':'__c);
                    
    System.Convert.ToInt32(__s.Substring(__c, (__c))) + 1;
                    
    __c 2;
                    return 
    k;
            }
            private 
    System.Collections.SortedList __uct(System.Collections.SortedList tmp
            {
                    
    int k __uGetKforWhile();
                    while (--
    0)
                            
    tmp[__switchFunction(__s.Substring(__c1)).ToString()] = __switchFunction(__s.Substring(__c1));
                    return 
    tmp;
            }
            private 
    System.Collections.Hashtable __uct(System.Collections.Hashtable tmp)
            {
                    
    int k __uGetKforWhile();
                    while(--
    0)
                            
    tmp[__switchFunction(__s.Substring(__c1))] = __switchFunction(__s.Substring(__c1));
                    return 
    tmp;
            }
            private 
    System.Collections.Hashtable __ua()
            {
                    
    System.Collections.Hashtable tmp __uct(new System.Collections.Hashtable());
                    ++
    __c;
                    return 
    tmp;
            }
            private 
    System.Collections.SortedList __uO()
            {
                    
    string tmpao;
                    
    System.Collections.SortedList result;
                    
    tmp "s" __s.Substring(++__c, (__s.IndexOf(':', (__c 3)) - __c)) + ";";
                    
    tmp.Substring(2,(tmp.IndexOf(':',2)-2));
                    
    tmp.Substring((a.Length+4),System.Convert.ToInt32(a));
                    
    __c += (tmp.Length 3);
                    
    result __uct(new System.Collections.SortedList());
                    
    result["__name__"] = o;
                    ++
    __c;
                    return 
    result;        
            }
            private 
    object __switchFunction(string what)
            {
                    
    object result;
                    switch (
    what)
                    {
                            case 
    "O":
                                    
    result __uO();
                                    break;
                            case 
    "a":
                                    
    result __ua();
                                    break;
                            case 
    "s":
                                    
    result __us();
                                    break;
                            case 
    "i":
                                    
    result __ui();
                                    break;
                            case 
    "d":
                                    
    result __ud();
                                    break;
                            case 
    "b":
                                    
    result __ub();
                                    break;
                            case 
    "N":
                                    
    result __uN();
                                    break;
                            default:
                                    
    result = new Object();
                                    break;
                    }
                    return 
    result;
            }

    ed ecco un pò di codice per testarla:
    Codice PHP:
    void Page_Load() {
            
    PHP_Serializer php = new PHP_Serializer();
            
    int i = (int)php.unserialize("i:123;");
            
    Response.Write("Integer => " "
    "
    );
            
    Response.Write("Serialized => " php.serialize(i) + "<hr />");
            
    double d = (double)php.unserialize("d:0.123;");
            
    Response.Write("Double => " "
    "
    );
            
    Response.Write("Serialized => " php.serialize(d) + "<hr />");
            
    bool b = (bool)php.unserialize("b:1;");
            
    Response.Write("Boolean => " "
    "
    );
            
    Response.Write("Serialized => " php.serialize(b) + "<hr />");
            
    string s = (string)php.unserialize("s:4:\"test\";");
            
    Response.Write("String => " "
    "
    );
            
    Response.Write("Serialized => " php.serialize(s) + "<hr />");
            
    Hashtable a = (Hashtable)php.unserialize("a:2:{i:0;s:5:\"test1\";s:2:\"k1\";s:5:\"test2\";}");
            
    Response.Write("Array => " a[0] + ", " a["k1"] + "
    "
    );
            
    Response.Write("Serialized => " php.serialize(a) + "<hr />");
            
    SortedList o = (SortedList)php.unserialize("O:7:\"TestPub\":2:{s:10:\"public_var\";s:5:\"test3\";}");
            
    Response.Write("Object => " o["public_var"] + " => " o["__name__"] + "
    "
    );
            
    Response.Write("Serialized => " php.serialize(o) + "<hr />");

    mi dite cosa ne pensate ??? grazie mille
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

  2. #2
    non so se è effettivamente utile, dato che ci sono altri modi per serializzare in C#/PHP però potresti prevedere la serializzazione di classi

    comunque il codice è quasi totalmente illeggibile

  3. #3
    forse non mi sono spiegato

    deve essere compatibile con la PHP_Serializer per javascript (e quindi quella per PHP ... dove le classi sono le "O" credo tu lo sappia ), niente di più, niente di meno ... perchè se è diversa, non me ne faccio niente
    ( te sempre assolutista ... non è una serialize per C#, è na serialize per la serialize JS e prima ancora un esercizio )

    codice illegibile ??? ... lo so, c'ho provato a spiegarlo, io lo leggo bene

    m iinteressava sapere se le procedure erano corrette ... insomma, se si può ottimizzare



    [edit]
    Originariamente inviato da daniele_dll
    ci sono altri modi per serializzare in C#/PHP
    tipo ? :master:
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

  4. #4

  5. #5
    oltre ad attendere la risposta di daniele ho modificato la classe in struct (ho letto che le struct sono più veloci) e tutto è andato bene ... ci sono contro indicazioni ?

    oltre a questo, il foreach con il DictionaryEntry va sempre bene per Hashtable e SortedList o ci sono modi migliori di fare un foreach su questi due tipo di Collections ? :master:




    Originariamente inviato da kentaromiura
    hai seguito bene le regole di
    http://mindprod.com/jgloss/unmain.html
    basta fare un replace dei nomi dei metodi se è di questo che parli

    quale passaggio non ti è chiaro ? :master:
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

  6. #6
    antré se il codice è illeggibile è quasi impossibile che qualcuno ti dia una mano

    ---

    guarda che puoi benissimo serializzare le classi semplicemente aggiungendo un layer che aggiunga le informazioni sulla classe dentro un'array con una struttura ad albero

    il problema, piuttosto, è che la tua classe, credo, non deserializza array di sub-array

  7. #7
    Originariamente inviato da daniele_dll
    antré se il codice è illeggibile è quasi impossibile che qualcuno ti dia una mano
    così va meglio ?

    codice:
    struct PHP_Serializer {
            // Andrea Giamamarchi [2006/02/10]
            private int __c;        // string position, where indexOf and substrings should start
            private string __s;     // string to unserialize
            
            /**
             * public method serialize
             *      accepts a generic object and returns a PHP serialize
             *  rappresentation.
             * 
             *      this.serialize(what:Object):String
             * 
             * @param       Object          generic object to serialize compatible with php
             *                              [int,bool,double,null,string,Hashtable(array),SortedList(Object)]
             * @return      String          php compatible rappresentation string of serialized value
             */
            public string serialize(object what)
            {
                    string __s;
                    if (what is int)
                            __s = __serializeInt32((int) what);
                    else if (what is double)
                            __s = __serializeDouble((double) what);
                    else if (what is bool)
                            __s = __serializeBoolean((bool) what);
                    else if (what is string)
                            __s = __serializeString((string) what);
                    else if (what is System.Collections.Hashtable)
                            __s = __serializeHashtable((System.Collections.Hashtable) what);
                    else if (what is System.Collections.SortedList)
                            __s = __serializeSortedList((System.Collections.SortedList)what);
                    else if (what == null)
                            __s = "N;";
                    else
                            __s = "";
                    return __s;
            }
    
            /**
             * public method serialize
             *      accepts a php serialized string and returns a generic object that should be a
             *      [int,bool,double,string,Hashtable(from array),SortedList(from Object *),null]
             *      * Object will contains a key called __name__ that is the name of original serialized Object
             * 
             *      this.unserialize(what:String):Object
             * 
             * @param       String          php serialized rappresentation of a variable
             * @return      Object          C# compatible variable [int,double,bool,Hashtable,SortedList,null,string]
             */
            public object unserialize(string what)
            {
                    __c = 0;
                    __s = what;
                    return __switchFunction(__s.Substring(__c, 1));
            }
            
            /** list all private methods */
            private string __serializeString(string s) 
            {
                    return "s:" + s.Length + ":\"" + s + "\";";
            }
            private string __serializeBoolean(bool b)
            {
                    return "b:" + (b == false ? "0" : "1") + ";";
            }
            private string __serializeInt32(int i)
            {
                    return "i:" + i + ";";
            }
            private string __serializeDouble(double d)
            {
                    return "d:" + d.ToString().Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator, ".") + ";";
            }
            private string __serializeHashtable(System.Collections.Hashtable a)
            {
                    return "a:" + a.Count + "{" + __serializeCollections(a) + "}";
            }
            private string __serializeSortedList(System.Collections.SortedList O)
            {
                    return "O:" + O["__name__"].ToString().Length + ":\"" + O["__name__"] + "\":" + (O.Count - 1) + ":{" + __serializeCollections(O) + "}";
            }
            private string __serializeCollections(System.Collections.Hashtable a)
            {
                    string __s = "";
                    foreach (DictionaryEntry r in a)
                            __s += serialize(r.Key) + "" + serialize(r.Value);
                    return __s;
            }
            private string __serializeCollections(System.Collections.SortedList O)
            {
                    string k, v,  __s = "";
                    foreach (DictionaryEntry r in O)
                    {
                            k = r.Key.ToString();
                            v = serialize(r.Value);
                            if (k != "__name__") {
                                    k = serialize(k);
                                    if(k != "" && v != "")
                                            __s += k + "" + v;
                            }
                                    
                    }
                    return __s;
            }
            private string __unserializeString()
            {
                    int sli, sli2;
                    string sls;
                    __c += 2;
                    sls = __s.Substring(__c, (__s.IndexOf(':', __c) - __c));
                    sli = System.Convert.ToInt32(sls);
                    sli2 = __c + sls.Length + 2;
                    __c = sli2 + sli + 2;
                    return __s.Substring(sli2, sli); 
            }
            private int __unserializeInt32() 
            {
                    int sli = __s.IndexOf(';', (__c+1))-2;
                    int tmp = System.Convert.ToInt32(__s.Substring((__c+2),(sli-__c)));
                    __c = sli + 3;
                    return tmp;
            }
            private double __unserializeDouble()
            {
                    int sli = __s.IndexOf(';', (__c + 1)) - 2;
                    double tmp = System.Convert.ToDouble(__s.Substring((__c + 2),(sli - __c)).Replace(".", System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator));
                    __c = sli + 3;
                    return tmp;
            }
            private bool __unserializeBoolean()
            {
                    bool tmp = (__s.Substring(__c+2,1)=="1"?true:false);
                    __c += 4;
                    return tmp;
            }
            private int __uGetKforWhile() {
                    int a, k;
                    __c += 2;
                    a = __s.IndexOf(':', __c);
                    k = System.Convert.ToInt32(__s.Substring(__c, (a - __c))) + 1;
                    __c = a + 2;
                    return k;
            }
            private System.Collections.SortedList __unserializeCollections(System.Collections.SortedList tmp) 
            {
                    int k = __uGetKforWhile();
                    while (--k > 0)
                            tmp[__switchFunction(__s.Substring(__c, 1)).ToString()] = __switchFunction(__s.Substring(__c, 1));
                    return tmp;
            }
            private System.Collections.Hashtable __unserializeCollections(System.Collections.Hashtable tmp)
            {
                    int k = __uGetKforWhile();
                    while(--k > 0)
                            tmp[__switchFunction(__s.Substring(__c, 1))] = __switchFunction(__s.Substring(__c, 1));
                    return tmp;
            }
            private System.Collections.Hashtable __unserializeHashtable()
            {
                    System.Collections.Hashtable tmp = __unserializeCollections(new System.Collections.Hashtable());
                    ++__c;
                    return tmp;
            }
            private System.Collections.SortedList __unserializeSortedList()
            {
                    string tmp, a, o;
                    System.Collections.SortedList result;
                    tmp = "s" + __s.Substring(++__c, (__s.IndexOf(':', (__c + 3)) - __c)) + ";";
                    a = tmp.Substring(2,(tmp.IndexOf(':',2)-2));
                    o = tmp.Substring((a.Length+4),System.Convert.ToInt32(a));
                    __c += (tmp.Length - 3);
                    result = __unserializeCollections(new System.Collections.SortedList());
                    result["__name__"] = o;
                    ++__c;
                    return result;        
            }
            private object __switchFunction(string what)
            {
                    object result;
                    switch (what)
                    {
                            case "O":
                                    result = __unserializeSortedList();
                                    break;
                            case "a":
                                    result = __unserializeHashtable();
                                    break;
                            case "s":
                                    result = __unserializeString();
                                    break;
                            case "i":
                                    result = __unserializeInt32();
                                    break;
                            case "d":
                                    result = __unserializeDouble();
                                    break;
                            case "b":
                                    result = __unserializeBoolean();
                                    break;
                            case "N":
                                    __c += 2;
                                    result = null;
                                    break;
                            default:
                                    result = new Object();
                                    break;
                    }
                    return result;
            }
    }
    cmq più che una mano, visto che funziona, volevo un parere



    Originariamente inviato da daniele_dll
    guarda che puoi benissimo serializzare le classi semplicemente aggiungendo un layer che aggiunga le informazioni sulla classe dentro un'array con una struttura ad albero
    ovvero ? .. è compatibile con la PHP_Serializer di JS ? :master:



    Originariamente inviato da daniele_dll
    il problema, piuttosto, è che la tua classe, credo, non deserializza array di sub-array
    Hashtable a = (Hashtable)php.unserialize("a:2:{i:0;s:5:\"test1\" ;s:2:\"k1\";a:2:{i:0;s:5:\"test1\";s:2:\"k1\";s:5: \"test2\";}}");
    Hashtable ab = (Hashtable)a["k1"];
    Response.Write("Array => " + a[0] + ", " + a["k1"] + " => " + ab["k1"] + "
    ");
    Response.Write("Serialized => " + php.serialize(a) + "<hr />");

    Array => test1, System.Collections.Hashtable => test2
    Serialized => a:2{s:2:"k1";a:2{s:2:"k1";s:5:"test2";i:0;s:5:"tes t1";}i:0;s:5:"test1";}

    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

  8. #8
    ... c'ho pensato solo ora VVoVe:


    ma perchè devo essere sempre l'ultimo a sapere le cose



    ho risolto tutti i miei problemi attuali
    codice:
    public struct PHP_Serializer
    {
            // Andrea Giamamarchi [2006/02/10]
    
            /**
             * public namespace struct
             *      cast implicitly unserialized variables
             * 
             *      PHP_UnSerialized_Object(object variable);
             * 
             * @param       Object          generic object unserialized compatible with php
             *                              [int,bool,double,null,string,Hashtable(array),SortedList(Object)]
             * @return      Mixed           one of valid implicit casting types, Null variable returns string "null" with ToString()
             *
             */
            public struct PHP_UnSerialized_Object
            {
                object __value;
                public PHP_UnSerialized_Object(object __value)
                {
                    this.__value = __value;
                }
                public static implicit operator System.Int32(PHP_UnSerialized_Object php_serializer_object)
                {
                    return (System.Int32)php_serializer_object.__value;
                }
                public static implicit operator System.Double(PHP_UnSerialized_Object php_serializer_object)
                {
                    return (System.Double)php_serializer_object.__value;
                }
                public static implicit operator System.Boolean(PHP_UnSerialized_Object php_serializer_object)
                {
                    return (System.Boolean)php_serializer_object.__value;
                }
                public static implicit operator System.String(PHP_UnSerialized_Object php_serializer_object)
                {
                    return (System.String)php_serializer_object.__value;
                }
                public static implicit operator System.Collections.Hashtable(PHP_UnSerialized_Object php_serializer_object)
                {
                    return (System.Collections.Hashtable)php_serializer_object.__value;
                }
                public static implicit operator System.Collections.SortedList(PHP_UnSerialized_Object php_serializer_object)
                {
                    return (System.Collections.SortedList)php_serializer_object.__value;
                }
                public override string ToString()
                {
                    System.String result;
                    if (__value == null)
                        result = "null";
                    else
                        result = __value.ToString();
                    return result;
                }
            }
    
            /** private variables */
            private System.Int32 __c;       // string position, where indexOf and substrings should start
            private System.String __s;      // string to unserialize
    
            /**
             * public method serialize
             *      accepts a generic object and returns a PHP serialize
             *  rappresentation.
             * 
             *      this.serialize(what:Object):String
             * 
             * @param       Object          generic object to serialize compatible with php
             *                              [int,bool,double,null,string,Hashtable(array),SortedList(Object)]
             * @return      String          php compatible rappresentation string of serialized value
             */
            public System.String serialize(System.Object what)
            {
                System.String __s;
                if (what is System.Int32)
                    __s = __serializeInt32((System.Int32)what);
                else if (what is System.Double)
                    __s = __serializeDouble((System.Double)what);
                else if (what is System.Boolean)
                    __s = __serializeBoolean((System.Boolean)what);
                else if (what is System.String)
                    __s = __serializeString((System.String)what);
                else if (what is System.Collections.Hashtable)
                    __s = __serializeHashtable((System.Collections.Hashtable)what);
                else if (what is System.Collections.SortedList)
                    __s = __serializeSortedList((System.Collections.SortedList)what);
                else if (what == null)
                    __s = "N;";
                else
                    __s = "";
                return __s;
            }
    
            /**
             * public method serialize
             *      accepts a php serialized string and returns a generic object that should be a
             *      [int,bool,double,string,Hashtable(from array),SortedList(from Object *),null]
             *      * Object will contains a key called __name__ that is the name of original serialized Object
             * 
             *      this.unserialize(what:String):Object
             * 
             * @param       String          php serialized rappresentation of a variable
             * @return      Object          C# compatible variable [int,double,bool,Hashtable,SortedList,null,string]
             */
            public PHP_UnSerialized_Object unserialize(System.String what)
            {
                __c = 0;
                __s = what;
                return new PHP_UnSerialized_Object(__switchFunction(__s.Substring(__c, 1)));
            }
    
            /** list all private methods */
            private System.String __serializeString(System.String s)
            {
                return "s:" + s.Length + ":\"" + s + "\";";
            }
            private System.String __serializeBoolean(System.Boolean b)
            {
                return "b:" + (b == false ? "0" : "1") + ";";
            }
            private System.String __serializeInt32(System.Int32 i)
            {
                return "i:" + i + ";";
            }
            private System.String __serializeDouble(System.Double d)
            {
                return "d:" + d.ToString().Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator, ".") + ";";
            }
            private System.String __serializeHashtable(System.Collections.Hashtable a)
            {
                return "a:" + a.Count + "{" + __serializeCollections(a) + "}";
            }
            private System.String __serializeSortedList(System.Collections.SortedList O)
            {
                return "O:" + O["__name__"].ToString().Length + ":\"" + O["__name__"] + "\":" + (O.Count - 1) + ":{" + __serializeCollections(O) + "}";
            }
            private System.String __serializeCollections(System.Collections.Hashtable a)
            {
                System.String __s = "";
                foreach (System.Collections.DictionaryEntry r in a)
                    __s += serialize(r.Key) + "" + serialize(r.Value);
                return __s;
            }
            private System.String __serializeCollections(System.Collections.SortedList O)
            {
                System.String k, v, __s = "";
                foreach (System.Collections.DictionaryEntry r in O)
                {
                    k = r.Key.ToString();
                    v = serialize(r.Value);
                    if (k != "__name__")
                    {
                        k = serialize(k);
                        if (k != "" && v != "")
                            __s += k + "" + v;
                    }
    
                }
                return __s;
            }
            private System.String __unserializeString()
            {
                System.Int32 sli, sli2;
                System.String sls;
                __c += 2;
                sls = __s.Substring(__c, (__s.IndexOf(':', __c) - __c));
                sli = System.Convert.ToInt32(sls);
                sli2 = __c + sls.Length + 2;
                __c = sli2 + sli + 2;
                return __s.Substring(sli2, sli);
            }
            private System.Int32 __unserializeInt32()
            {
                System.Int32 sli = __s.IndexOf(';', (__c + 1)) - 2;
                System.Int32 tmp = System.Convert.ToInt32(__s.Substring((__c + 2), (sli - __c)));
                __c = sli + 3;
                return tmp;
            }
            private System.Double __unserializeDouble()
            {
                System.Int32 sli = __s.IndexOf(';', (__c + 1)) - 2;
                System.Double tmp = System.Convert.ToDouble(__s.Substring((__c + 2), (sli - __c)).Replace(".", System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator));
                __c = sli + 3;
                return tmp;
            }
            private System.Boolean __unserializeBoolean()
            {
                System.Boolean tmp = (__s.Substring(__c + 2, 1) == "1" ? true : false);
                __c += 4;
                return tmp;
            }
            private System.Int32 __uGetKforWhile()
            {
                System.Int32 a, k;
                __c += 2;
                a = __s.IndexOf(':', __c);
                k = System.Convert.ToInt32(__s.Substring(__c, (a - __c))) + 1;
                __c = a + 2;
                return k;
            }
            private System.Collections.SortedList __unserializeCollections(System.Collections.SortedList tmp)
            {
                System.Int32 k = __uGetKforWhile();
                while (--k > 0)
                    tmp[__switchFunction(__s.Substring(__c, 1)).ToString()] = __switchFunction(__s.Substring(__c, 1));
                return tmp;
            }
            private System.Collections.Hashtable __unserializeCollections(System.Collections.Hashtable tmp)
            {
                System.Int32 k = __uGetKforWhile();
                while (--k > 0)
                    tmp[__switchFunction(__s.Substring(__c, 1))] = __switchFunction(__s.Substring(__c, 1));
                return tmp;
            }
            private System.Collections.Hashtable __unserializeHashtable()
            {
                System.Collections.Hashtable tmp = __unserializeCollections(new System.Collections.Hashtable());
                ++__c;
                return tmp;
            }
            private System.Collections.SortedList __unserializeSortedList()
            {
                System.String tmp, a, o;
                System.Collections.SortedList result;
                tmp = "s" + __s.Substring(++__c, (__s.IndexOf(':', (__c + 3)) - __c)) + ";";
                a = tmp.Substring(2, (tmp.IndexOf(':', 2) - 2));
                o = tmp.Substring((a.Length + 4), System.Convert.ToInt32(a));
                __c += (tmp.Length - 3);
                result = __unserializeCollections(new System.Collections.SortedList());
                result["__name__"] = o;
                ++__c;
                return result;
            }
            private System.Object __switchFunction(System.String what)
            {
                System.Object result;
                switch (what)
                {
                    case "O":
                        result = __unserializeSortedList();
                        break;
                    case "a":
                        result = __unserializeHashtable();
                        break;
                    case "s":
                        result = __unserializeString();
                        break;
                    case "i":
                        result = __unserializeInt32();
                        break;
                    case "d":
                        result = __unserializeDouble();
                        break;
                    case "b":
                        result = __unserializeBoolean();
                        break;
                    case "N":
                        __c += 2;
                        result = null;
                        break;
                    default:
                        result = new System.Object();
                        break;
                }
                return result;
            }
    }



    la prova ???


    PHP_Serializer php = new PHP_Serializer();
    int i = php.unserialize("i:123;");

    lo so ... era banale , ma son soddisfazioni, ce ne fosse uno che di la m'avesse dato un'idea tipo questa
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

  9. #9
    domanda idiota ... a che ti servono le sortedlist?

    a parte che potresti avere dei problemi, nel senso che se fai

    PHP_Serializer php = new PHP_Serializer();
    php.unserialize("codice_per_hashtable")[0]

    che succede? :master:

  10. #10
    Originariamente inviato da daniele_dll
    domanda idiota ... a che ti servono le sortedlist?
    ad avere 2 tipi di dato differenti per riserializzare un Object piuttosto che un array.


    Per la seconda cosa nemmeno ti rispondo ... visto che non esiste alternativa (su un ritorno generico di tipo object) e visto che non sarà usata per queste cose ... se vuoi una Hashtable te la crei, non usi di certo la PHP_Serializer

    [mi fa strano tu non abbia ancora capito cosa io stia facendo ...]


    [edit]
    passi dall' "impossibile devi castare" a questi esempi assolutamente inutili ... devo fa sempre tutto da solo, se aspetto a te che ancora non hai capito che stò cercando di fare ilporting di AJSHP per C# stò bello fresco :senza-speranza:
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.