Exemple #1
0
 // Get the memberInfo for a memberName
 internal MemberInfo GetMemberInfo(String name)
 {
     InternalST.Soap(this, objectInfoId, " ", objectType, " GetMemberInfo Entry ", name);
     if (isSi)
     {
         throw new SerializationException(String.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_MemberInfo"), objectType + " " + name));
     }
     if (cache.memberInfos == null)
     {
         throw new SerializationException(String.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_NoMemberInfo"), objectType + " " + name));
     }
     return(cache.memberInfos[Position(name)]);
 }
Exemple #2
0
        internal Type GetMemberType(MemberInfo objMember)
        {
            Type objectType = null;

            if (objMember is FieldInfo)
            {
                objectType = ((FieldInfo)objMember).FieldType;
                InternalST.Soap(this, objectInfoId, " ", "GetMemberType FieldInfo ", objectType);
            }
            else if (objMember is PropertyInfo)
            {
                objectType = ((PropertyInfo)objMember).PropertyType;
                InternalST.Soap(this, objectInfoId, " ", "GetMemberType PropertyInfo ", objectType);
            }
            else
            {
                throw new SerializationException(String.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_SerMemberInfo"), objMember.GetType()));
            }

            return(objectType);
        }
Exemple #3
0
        // Write constructor
        internal void InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SoapAttributeInfo attributeInfo, ObjectWriter objectWriter)
        {
            InternalST.Soap(this, objectInfoId, " Constructor 1 ", obj);
            this.context                   = context;
            this.obj                       = obj;
            this.serObjectInfoInit         = serObjectInfoInit;
            this.parentMemberAttributeInfo = attributeInfo;
            this.surrogateSelector         = surrogateSelector;
            this.converter                 = converter;
            ISurrogateSelector surrogateSelectorTemp;

            if (RemotingServices.IsTransparentProxy(obj))
            {
                objectType = Converter.typeofMarshalByRefObject;
            }
            else
            {
                objectType = obj.GetType();
            }

            if (objectType.IsArray)
            {
                arrayElemObjectInfo = Serialize(objectType.GetElementType(), surrogateSelector, context, serObjectInfoInit, converter, null);
                typeAttributeInfo   = GetTypeAttributeInfo();
                isArray             = true;
                InitNoMembers();
                return;
            }

            InternalST.Soap(this, objectInfoId, " Constructor 1 trace 2");

            typeAttributeInfo = GetTypeAttributeInfo();

            objectWriter.ObjectManager.RegisterObject(obj);
            if (surrogateSelector != null && (serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp)) != null)
            {
                InternalST.Soap(this, objectInfoId, " Constructor 1 trace 3");
                si = new SerializationInfo(objectType, converter);
                if (!objectType.IsPrimitive)
                {
                    serializationSurrogate.GetObjectData(obj, si, context);
                }
                InitSiWrite(objectWriter);
            }
            else if (obj is ISerializable)
            {
                if (!objectType.IsSerializable)
                {
                    throw new SerializationException(String.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_NonSerType"),
                                                                   objectType.FullName, objectType.Module.Assembly.FullName));
                }
                si = new SerializationInfo(objectType, converter);
                ((ISerializable)obj).GetObjectData(si, context);
                InternalST.Soap(this, objectInfoId, " Constructor 1 trace 4 ISerializable " + objectType);
                InitSiWrite(objectWriter);
            }
            else
            {
                InternalST.Soap(this, objectInfoId, " Constructor 1 trace 5");
                InitMemberInfo();
            }
        }
Exemple #4
0
        private int Position(String name)
        {
            InternalST.Soap(this, objectInfoId, " Position ", lastPosition, " ", name);
            if (cache.memberNames[lastPosition].Equals(name))
            {
                return(lastPosition);
            }
            else if ((++lastPosition < cache.memberNames.Length) && (cache.memberNames[lastPosition].Equals(name)))
            {
                return(lastPosition);
            }
            else
            {
                // Search for name
                InternalST.Soap(this, objectInfoId, " Position miss search for name " + name);
                for (int i = 0; i < cache.memberNames.Length; i++)
                {
                    if (cache.memberNames[i].Equals(name))
                    {
                        lastPosition = i;
                        return(lastPosition);
                    }
                }

                throw new SerializationException(String.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_Position"), objectType + " " + name));
            }
        }
Exemple #5
0
        internal Type GetType(string name)
        {
            Type type = null;

            if (this.isTyped)
            {
                type = this.cache.memberTypes[this.Position(name)];
            }
            else
            {
                type = (Type)this.memberTypesList[this.Position(name)];
            }
            if (type == null)
            {
                throw new SerializationException(string.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_ISerializableTypes"), new object[] { this.objectType + " " + name }));
            }
            return(type);
        }
Exemple #6
0
 private int Position(string name)
 {
     if (this.cache.memberNames[this.lastPosition].Equals(name))
     {
         return(this.lastPosition);
     }
     if ((++this.lastPosition < this.cache.memberNames.Length) && this.cache.memberNames[this.lastPosition].Equals(name))
     {
         return(this.lastPosition);
     }
     for (int i = 0; i < this.cache.memberNames.Length; i++)
     {
         if (this.cache.memberNames[i].Equals(name))
         {
             this.lastPosition = i;
             return(this.lastPosition);
         }
     }
     throw new SerializationException(string.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_Position"), new object[] { this.objectType + " " + name }));
 }
Exemple #7
0
 internal Type GetMemberType(MemberInfo objMember)
 {
     if (objMember is FieldInfo)
     {
         return(((FieldInfo)objMember).FieldType);
     }
     if (!(objMember is PropertyInfo))
     {
         throw new SerializationException(string.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_SerMemberInfo"), new object[] { objMember.GetType() }));
     }
     return(((PropertyInfo)objMember).PropertyType);
 }
        internal static object FromString(string value, InternalPrimitiveTypeE code)
        {
            switch (code)
            {
            case InternalPrimitiveTypeE.Boolean:
                if (!(value == "1") && !(value == "true"))
                {
                    if ((value != "0") && (value != "false"))
                    {
                        throw new SerializationException(string.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_typeCoercion"), new object[] { value, "Boolean" }));
                    }
                    return(false);
                }
                return(true);

            case InternalPrimitiveTypeE.Double:
                if (!(value == "INF"))
                {
                    if (value == "-INF")
                    {
                        return((double)-1.0 / (double)0.0);
                    }
                    return(double.Parse(value, CultureInfo.InvariantCulture));
                }
                return((double)1.0 / (double)0.0);

            case InternalPrimitiveTypeE.Single:
                if (!(value == "INF"))
                {
                    if (value == "-INF")
                    {
                        return((float)-1.0 / (float)0.0);
                    }
                    return(float.Parse(value, CultureInfo.InvariantCulture));
                }
                return((float)1.0 / (float)0.0);

            case InternalPrimitiveTypeE.TimeSpan:
                return(SoapDuration.Parse(value));

            case InternalPrimitiveTypeE.DateTime:
                return(SoapDateTime.Parse(value));

            case InternalPrimitiveTypeE.Time:
                return(SoapTime.Parse(value));

            case InternalPrimitiveTypeE.Date:
                return(SoapDate.Parse(value));

            case InternalPrimitiveTypeE.YearMonth:
                return(SoapYearMonth.Parse(value));

            case InternalPrimitiveTypeE.Year:
                return(SoapYear.Parse(value));

            case InternalPrimitiveTypeE.MonthDay:
                return(SoapMonthDay.Parse(value));

            case InternalPrimitiveTypeE.Day:
                return(SoapDay.Parse(value));

            case InternalPrimitiveTypeE.Month:
                return(SoapMonth.Parse(value));

            case InternalPrimitiveTypeE.HexBinary:
                return(SoapHexBinary.Parse(value));

            case InternalPrimitiveTypeE.Base64Binary:
                return(SoapBase64Binary.Parse(value));

            case InternalPrimitiveTypeE.Integer:
                return(SoapInteger.Parse(value));

            case InternalPrimitiveTypeE.PositiveInteger:
                return(SoapPositiveInteger.Parse(value));

            case InternalPrimitiveTypeE.NonPositiveInteger:
                return(SoapNonPositiveInteger.Parse(value));

            case InternalPrimitiveTypeE.NonNegativeInteger:
                return(SoapNonNegativeInteger.Parse(value));

            case InternalPrimitiveTypeE.NegativeInteger:
                return(SoapNegativeInteger.Parse(value));

            case InternalPrimitiveTypeE.AnyUri:
                return(SoapAnyUri.Parse(value));

            case InternalPrimitiveTypeE.QName:
                return(SoapQName.Parse(value));

            case InternalPrimitiveTypeE.Notation:
                return(SoapNotation.Parse(value));

            case InternalPrimitiveTypeE.NormalizedString:
                return(SoapNormalizedString.Parse(value));

            case InternalPrimitiveTypeE.Token:
                return(SoapToken.Parse(value));

            case InternalPrimitiveTypeE.Language:
                return(SoapLanguage.Parse(value));

            case InternalPrimitiveTypeE.Name:
                return(SoapName.Parse(value));

            case InternalPrimitiveTypeE.Idrefs:
                return(SoapIdrefs.Parse(value));

            case InternalPrimitiveTypeE.Entities:
                return(SoapEntities.Parse(value));

            case InternalPrimitiveTypeE.Nmtoken:
                return(SoapNmtoken.Parse(value));

            case InternalPrimitiveTypeE.Nmtokens:
                return(SoapNmtokens.Parse(value));

            case InternalPrimitiveTypeE.NcName:
                return(SoapNcName.Parse(value));

            case InternalPrimitiveTypeE.Id:
                return(SoapId.Parse(value));

            case InternalPrimitiveTypeE.Idref:
                return(SoapIdref.Parse(value));

            case InternalPrimitiveTypeE.Entity:
                return(SoapEntity.Parse(value));
            }
            if (code != InternalPrimitiveTypeE.Invalid)
            {
                return(Convert.ChangeType(value, ToTypeCode(code), CultureInfo.InvariantCulture));
            }
            return(value);
        }
 internal void InitSerialize(object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SoapAttributeInfo attributeInfo, ObjectWriter objectWriter)
 {
     this.context                   = context;
     this.obj                       = obj;
     this.serObjectInfoInit         = serObjectInfoInit;
     this.parentMemberAttributeInfo = attributeInfo;
     this.surrogateSelector         = surrogateSelector;
     this.converter                 = converter;
     if (RemotingServices.IsTransparentProxy(obj))
     {
         this.objectType = Converter.typeofMarshalByRefObject;
     }
     else
     {
         this.objectType = obj.GetType();
     }
     if (this.objectType.IsArray)
     {
         this.arrayElemObjectInfo = Serialize(this.objectType.GetElementType(), surrogateSelector, context, serObjectInfoInit, converter, null);
         this.typeAttributeInfo   = this.GetTypeAttributeInfo();
         this.isArray             = true;
         this.InitNoMembers();
     }
     else
     {
         ISurrogateSelector selector;
         this.typeAttributeInfo = this.GetTypeAttributeInfo();
         objectWriter.ObjectManager.RegisterObject(obj);
         if ((surrogateSelector != null) && ((this.serializationSurrogate = surrogateSelector.GetSurrogate(this.objectType, context, out selector)) != null))
         {
             this.si = new SerializationInfo(this.objectType, converter);
             if (!this.objectType.IsPrimitive)
             {
                 this.serializationSurrogate.GetObjectData(obj, this.si, context);
             }
             this.InitSiWrite(objectWriter);
         }
         else if (obj is ISerializable)
         {
             if (!this.objectType.IsSerializable)
             {
                 throw new SerializationException(string.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_NonSerType"), new object[] { this.objectType.FullName, this.objectType.Module.Assembly.FullName }));
             }
             this.si = new SerializationInfo(this.objectType, converter);
             ((ISerializable)obj).GetObjectData(this.si, context);
             this.InitSiWrite(objectWriter);
         }
         else
         {
             this.InitMemberInfo();
         }
     }
 }
Exemple #10
0
 internal MemberInfo GetMemberInfo(string name)
 {
     if (this.isSi)
     {
         throw new SerializationException(string.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_MemberInfo"), new object[] { this.objectType + " " + name }));
     }
     if (this.cache.memberInfos == null)
     {
         throw new SerializationException(string.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_NoMemberInfo"), new object[] { this.objectType + " " + name }));
     }
     return(this.cache.memberInfos[this.Position(name)]);
 }
Exemple #11
0
 internal object Next()
 {
     if (this.next > this.top)
     {
         throw new SerializationException(string.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_StackRange"), new object[] { this.stackId }));
     }
     return(this.objects[this.next++]);
 }
Exemple #12
0
 internal Assembly GetAssembly(ObjectReader objectReader)
 {
     if (assembly == null)
     {
         assembly = objectReader.LoadAssemblyFromString(assemblyString);
         if (assembly == null)
         {
             throw new SerializationException(String.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_AssemblyString"), assemblyString));
         }
     }
     return(assembly);
 }
Exemple #13
0
 internal Object Next()
 {
     if (next > top)
     {
         throw new SerializationException(String.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_StackRange"), stackId));
     }
     return(objects[next++]);
 }
Exemple #14
0
        // Get the ObjectType for a memberName
        internal Type GetType(String name)
        {
            InternalST.Soap(this, objectInfoId, " ", objectType, " GetType Entry ", name);
            Type type = null;

            if (isTyped)
            {
                type = cache.memberTypes[Position(name)];
            }
            else
            {
                type = (Type)memberTypesList[Position(name)];
            }

            if (type == null)
            {
                throw new SerializationException(String.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_ISerializableTypes"), objectType + " " + name));
            }

            InternalST.Soap(this, objectInfoId, " ", objectType, " GetType Exit ", type);
            return(type);
        }
Exemple #15
0
        internal Type GetType(int position)
        {
            Type type = null;

            if (!this.isTyped)
            {
                return(type);
            }
            if (position >= this.cache.memberTypes.Length)
            {
                throw new SerializationException(string.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_ISerializableTypes"), new object[] { this.objectType + " " + position }));
            }
            return(this.cache.memberTypes[position]);
        }
Exemple #16
0
        internal Type GetType(int position)
        {
            InternalST.Soap(this, objectInfoId, " ", objectType, " GetType Entry ByPosition ", position);
            Type type = null;

            if (isTyped)
            {
                if (position >= cache.memberTypes.Length)
                {
                    throw new SerializationException(String.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_ISerializableTypes"), objectType + " " + position));
                }
                type = cache.memberTypes[position];

                InternalST.Soap(this, objectInfoId, " ", objectType, " GetType Exit ByPosition ", type);
            }
            return(type);
        }
        internal static InternalPrimitiveTypeE ToCode(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("serParser", string.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("ArgumentNull_WithParamName"), new object[] { value }));
            }
            string str = value.ToLower(CultureInfo.InvariantCulture);
            char   ch  = str[0];
            InternalPrimitiveTypeE invalid = InternalPrimitiveTypeE.Invalid;

            switch (ch)
            {
            case 'a':
                if (str == "anyuri")
                {
                    invalid = InternalPrimitiveTypeE.AnyUri;
                }
                return(invalid);

            case 'b':
                if (!(str == "boolean"))
                {
                    switch (str)
                    {
                    case "byte":
                        return(InternalPrimitiveTypeE.SByte);

                    case "base64binary":
                        return(InternalPrimitiveTypeE.Base64Binary);

                    case "base64":
                        invalid = InternalPrimitiveTypeE.Base64Binary;
                        break;
                    }
                    return(invalid);
                }
                return(InternalPrimitiveTypeE.Boolean);

            case 'c':
                if (!(str == "char") && !(str == "character"))
                {
                    return(invalid);
                }
                return(InternalPrimitiveTypeE.Char);

            case 'd':
                switch (str)
                {
                case "double":
                    invalid = InternalPrimitiveTypeE.Double;
                    break;

                case "datetime":
                    return(InternalPrimitiveTypeE.DateTime);

                case "duration":
                    return(InternalPrimitiveTypeE.TimeSpan);

                case "date":
                    return(InternalPrimitiveTypeE.Date);

                case "decimal":
                    invalid = InternalPrimitiveTypeE.Decimal;
                    break;
                }
                return(invalid);

            case 'e':
                if (!(str == "entities"))
                {
                    if (str == "entity")
                    {
                        invalid = InternalPrimitiveTypeE.Entity;
                    }
                    return(invalid);
                }
                return(InternalPrimitiveTypeE.Entities);

            case 'f':
                if (str == "float")
                {
                    invalid = InternalPrimitiveTypeE.Single;
                }
                return(invalid);

            case 'g':
                if (!(str == "gyearmonth"))
                {
                    if (str == "gyear")
                    {
                        return(InternalPrimitiveTypeE.Year);
                    }
                    if (str == "gmonthday")
                    {
                        return(InternalPrimitiveTypeE.MonthDay);
                    }
                    if (str == "gday")
                    {
                        return(InternalPrimitiveTypeE.Day);
                    }
                    if (str == "gmonth")
                    {
                        invalid = InternalPrimitiveTypeE.Month;
                    }
                    return(invalid);
                }
                return(InternalPrimitiveTypeE.YearMonth);

            case 'h':
                if (str == "hexbinary")
                {
                    invalid = InternalPrimitiveTypeE.HexBinary;
                }
                return(invalid);

            case 'i':
                switch (str)
                {
                case "int":
                    invalid = InternalPrimitiveTypeE.Int32;
                    break;

                case "integer":
                    return(InternalPrimitiveTypeE.Integer);

                case "idrefs":
                    return(InternalPrimitiveTypeE.Idrefs);

                case "id":
                    return(InternalPrimitiveTypeE.Id);

                case "idref":
                    invalid = InternalPrimitiveTypeE.Idref;
                    break;
                }
                return(invalid);

            case 'l':
                if (!(str == "long"))
                {
                    if (str == "language")
                    {
                        invalid = InternalPrimitiveTypeE.Language;
                    }
                    return(invalid);
                }
                return(InternalPrimitiveTypeE.Int64);

            case 'n':
                if (!(str == "number"))
                {
                    if (str == "normalizedstring")
                    {
                        return(InternalPrimitiveTypeE.NormalizedString);
                    }
                    if (str == "nonpositiveinteger")
                    {
                        return(InternalPrimitiveTypeE.NonPositiveInteger);
                    }
                    if (str == "negativeinteger")
                    {
                        return(InternalPrimitiveTypeE.NegativeInteger);
                    }
                    if (str == "nonnegativeinteger")
                    {
                        return(InternalPrimitiveTypeE.NonNegativeInteger);
                    }
                    if (str == "notation")
                    {
                        return(InternalPrimitiveTypeE.Notation);
                    }
                    if (str == "nmtoken")
                    {
                        return(InternalPrimitiveTypeE.Nmtoken);
                    }
                    if (str == "nmtokens")
                    {
                        return(InternalPrimitiveTypeE.Nmtokens);
                    }
                    if (str == "name")
                    {
                        return(InternalPrimitiveTypeE.Name);
                    }
                    if (str == "ncname")
                    {
                        invalid = InternalPrimitiveTypeE.NcName;
                    }
                    return(invalid);
                }
                return(InternalPrimitiveTypeE.Decimal);

            case 'p':
                if (str == "positiveinteger")
                {
                    invalid = InternalPrimitiveTypeE.PositiveInteger;
                }
                return(invalid);

            case 'q':
                if (str == "qname")
                {
                    invalid = InternalPrimitiveTypeE.QName;
                }
                return(invalid);

            case 's':
                if (!(str == "short"))
                {
                    if (str == "system.byte")
                    {
                        return(InternalPrimitiveTypeE.Byte);
                    }
                    if (str == "system.sbyte")
                    {
                        return(InternalPrimitiveTypeE.SByte);
                    }
                    if (str == "system")
                    {
                        return(ToCode(value.Substring(7)));
                    }
                    if (str == "system.runtime.remoting.metadata")
                    {
                        invalid = ToCode(value.Substring(0x21));
                    }
                    return(invalid);
                }
                return(InternalPrimitiveTypeE.Int16);

            case 't':
                if (!(str == "time"))
                {
                    if (str == "token")
                    {
                        return(InternalPrimitiveTypeE.Token);
                    }
                    if (str == "timeinstant")
                    {
                        return(InternalPrimitiveTypeE.DateTime);
                    }
                    if (str == "timeduration")
                    {
                        invalid = InternalPrimitiveTypeE.TimeSpan;
                    }
                    return(invalid);
                }
                return(InternalPrimitiveTypeE.Time);

            case 'u':
                if (!(str == "unsignedlong"))
                {
                    if (str == "unsignedint")
                    {
                        return(InternalPrimitiveTypeE.UInt32);
                    }
                    if (str == "unsignedshort")
                    {
                        return(InternalPrimitiveTypeE.UInt16);
                    }
                    if (str == "unsignedbyte")
                    {
                        invalid = InternalPrimitiveTypeE.Byte;
                    }
                    return(invalid);
                }
                return(InternalPrimitiveTypeE.UInt64);
            }
            return(InternalPrimitiveTypeE.Invalid);
        }