ToCode() приватный Метод

private ToCode ( Type type ) : InternalPrimitiveTypeE
type System.Type
Результат InternalPrimitiveTypeE
 internal static BinaryTypeEnum GetBinaryTypeInfo(Type type, WriteObjectInfo objectInfo, string typeName, ObjectWriter objectWriter, out object typeInformation, out int assemId)
 {
     BinaryTypeEnum primitive;
     assemId = 0;
     typeInformation = null;
     if (object.ReferenceEquals(type, Converter.typeofString))
     {
         return BinaryTypeEnum.String;
     }
     if (((objectInfo == null) || ((objectInfo != null) && !objectInfo.isSi)) && object.ReferenceEquals(type, Converter.typeofObject))
     {
         return BinaryTypeEnum.Object;
     }
     if (object.ReferenceEquals(type, Converter.typeofStringArray))
     {
         return BinaryTypeEnum.StringArray;
     }
     if (object.ReferenceEquals(type, Converter.typeofObjectArray))
     {
         return BinaryTypeEnum.ObjectArray;
     }
     if (Converter.IsPrimitiveArray(type, out typeInformation))
     {
         return BinaryTypeEnum.PrimitiveArray;
     }
     InternalPrimitiveTypeE ee = objectWriter.ToCode(type);
     switch (ee)
     {
         case InternalPrimitiveTypeE.Invalid:
         {
             string fullName = null;
             if (objectInfo == null)
             {
                 fullName = type.Assembly.FullName;
                 typeInformation = type.FullName;
             }
             else
             {
                 fullName = objectInfo.GetAssemblyString();
                 typeInformation = objectInfo.GetTypeFullName();
             }
             if (fullName.Equals(Converter.urtAssemblyString))
             {
                 primitive = BinaryTypeEnum.ObjectUrt;
                 assemId = 0;
                 return primitive;
             }
             primitive = BinaryTypeEnum.ObjectUser;
             assemId = (int) objectInfo.assemId;
             if (assemId == 0)
             {
                 throw new SerializationException(Environment.GetResourceString("Serialization_AssemblyId", new object[] { typeInformation }));
             }
             return primitive;
         }
     }
     primitive = BinaryTypeEnum.Primitive;
     typeInformation = ee;
     return primitive;
 }
Пример #2
0
        // From the type create the BinaryTypeEnum and typeInformation which describes the type on the wire
        internal static BinaryTypeEnum GetBinaryTypeInfo(Type type, WriteObjectInfo?objectInfo, string?typeName, ObjectWriter objectWriter, out object?typeInformation, out int assemId)
        {
            BinaryTypeEnum binaryTypeEnum;

            assemId         = 0;
            typeInformation = null;

            if (ReferenceEquals(type, Converter.s_typeofString))
            {
                binaryTypeEnum = BinaryTypeEnum.String;
            }
            else if (((objectInfo == null) || ((objectInfo != null) && !objectInfo._isSi)) && (ReferenceEquals(type, Converter.s_typeofObject)))
            {
                // If objectInfo.Si then can be a surrogate which will change the type
                binaryTypeEnum = BinaryTypeEnum.Object;
            }
            else if (ReferenceEquals(type, Converter.s_typeofStringArray))
            {
                binaryTypeEnum = BinaryTypeEnum.StringArray;
            }
            else if (ReferenceEquals(type, Converter.s_typeofObjectArray))
            {
                binaryTypeEnum = BinaryTypeEnum.ObjectArray;
            }
            else if (Converter.IsPrimitiveArray(type, out typeInformation))
            {
                binaryTypeEnum = BinaryTypeEnum.PrimitiveArray;
            }
            else
            {
                InternalPrimitiveTypeE primitiveTypeEnum = objectWriter.ToCode(type);
                switch (primitiveTypeEnum)
                {
                case InternalPrimitiveTypeE.Invalid:
                    string?assembly = null;
                    if (objectInfo == null)
                    {
                        assembly        = type.Assembly.FullName;
                        typeInformation = type.FullName;
                    }
                    else
                    {
                        assembly        = objectInfo.GetAssemblyString();
                        typeInformation = objectInfo.GetTypeFullName();
                    }

                    Debug.Assert(assembly != null);
                    if (assembly.Equals(Converter.s_urtAssemblyString) || assembly.Equals(Converter.s_urtAlternativeAssemblyString))
                    {
                        binaryTypeEnum = BinaryTypeEnum.ObjectUrt;
                        assemId        = 0;
                    }
                    else
                    {
                        binaryTypeEnum = BinaryTypeEnum.ObjectUser;
                        Debug.Assert(objectInfo != null, "[BinaryConverter.GetBinaryTypeInfo]objectInfo null for user object");
                        assemId = (int)objectInfo._assemId;
                        if (assemId == 0)
                        {
                            throw new SerializationException(SR.Format(SR.Serialization_AssemblyId, typeInformation));
                        }
                    }
                    break;

                default:
                    binaryTypeEnum  = BinaryTypeEnum.Primitive;
                    typeInformation = primitiveTypeEnum;
                    break;
                }
            }

            return(binaryTypeEnum);
        }
Пример #3
0
        internal static BinaryTypeEnum GetBinaryTypeInfo(Type type, WriteObjectInfo objectInfo, string typeName, ObjectWriter objectWriter, out object typeInformation, out int assemId)
        {
            assemId         = 0;
            typeInformation = (object)null;
            BinaryTypeEnum binaryTypeEnum;

            if (type == Converter.typeofString)
            {
                binaryTypeEnum = BinaryTypeEnum.String;
            }
            else if ((objectInfo == null || objectInfo != null && !objectInfo.isSi) && type == Converter.typeofObject)
            {
                binaryTypeEnum = BinaryTypeEnum.Object;
            }
            else if (type == Converter.typeofStringArray)
            {
                binaryTypeEnum = BinaryTypeEnum.StringArray;
            }
            else if (type == Converter.typeofObjectArray)
            {
                binaryTypeEnum = BinaryTypeEnum.ObjectArray;
            }
            else if (Converter.IsPrimitiveArray(type, out typeInformation))
            {
                binaryTypeEnum = BinaryTypeEnum.PrimitiveArray;
            }
            else
            {
                InternalPrimitiveTypeE code = objectWriter.ToCode(type);
                if (code == InternalPrimitiveTypeE.Invalid)
                {
                    string str;
                    if (objectInfo == null)
                    {
                        str             = type.Assembly.FullName;
                        typeInformation = (object)type.FullName;
                    }
                    else
                    {
                        str             = objectInfo.GetAssemblyString();
                        typeInformation = (object)objectInfo.GetTypeFullName();
                    }
                    if (str.Equals(Converter.urtAssemblyString))
                    {
                        binaryTypeEnum = BinaryTypeEnum.ObjectUrt;
                        assemId        = 0;
                    }
                    else
                    {
                        binaryTypeEnum = BinaryTypeEnum.ObjectUser;
                        assemId        = (int)objectInfo.assemId;
                        if (assemId == 0)
                        {
                            throw new SerializationException(Environment.GetResourceString("Serialization_AssemblyId", typeInformation));
                        }
                    }
                }
                else
                {
                    binaryTypeEnum  = BinaryTypeEnum.Primitive;
                    typeInformation = (object)code;
                }
            }
            return(binaryTypeEnum);
        }
        // From the type create the BinaryTypeEnum and typeInformation which describes the type on the wire
 
        internal static BinaryTypeEnum GetBinaryTypeInfo(Type type, WriteObjectInfo objectInfo, String typeName, ObjectWriter objectWriter, out Object typeInformation, out int assemId)
        {
            SerTrace.Log("BinaryConverter", "GetBinaryTypeInfo Entry type ",type,", typeName ",typeName," objectInfo "+objectInfo);
            BinaryTypeEnum binaryTypeEnum; 

            assemId = 0; 
            typeInformation = null; 

            if (Object.ReferenceEquals(type, Converter.typeofString)) 
                binaryTypeEnum = BinaryTypeEnum.String;
            else if (((objectInfo == null) || ((objectInfo != null) && !objectInfo.isSi))
                     && (Object.ReferenceEquals(type, Converter.typeofObject)))
            { 
                // If objectInfo.Si then can be a surrogate which will change the type
                binaryTypeEnum = BinaryTypeEnum.Object; 
            } 
            else if (Object.ReferenceEquals(type, Converter.typeofStringArray))
                binaryTypeEnum = BinaryTypeEnum.StringArray; 
            else if (Object.ReferenceEquals(type, Converter.typeofObjectArray))
                binaryTypeEnum = BinaryTypeEnum.ObjectArray;
            else if (Converter.IsPrimitiveArray(type, out typeInformation))
                binaryTypeEnum = BinaryTypeEnum.PrimitiveArray; 
            else
            { 
                InternalPrimitiveTypeE primitiveTypeEnum = objectWriter.ToCode(type); 
                switch (primitiveTypeEnum)
                { 
                    case InternalPrimitiveTypeE.Invalid:
                        String assembly = null;
                        if (objectInfo == null)
                        { 
                            assembly = type.Assembly.FullName;
                            typeInformation = type.FullName; 
                        } 
                        else
                        { 
                            assembly = objectInfo.GetAssemblyString();
                            typeInformation = objectInfo.GetTypeFullName();
                        }
 
                        if (assembly.Equals(Converter.urtAssemblyString))
                        { 
                            binaryTypeEnum = BinaryTypeEnum.ObjectUrt; 
                            assemId = 0;
                        } 
                        else
                        {
                            binaryTypeEnum = BinaryTypeEnum.ObjectUser;
                            Contract.Assert(objectInfo!=null, "[BinaryConverter.GetBinaryTypeInfo]objectInfo null for user object"); 
                            assemId = (int)objectInfo.assemId;
                            if (assemId == 0) 
                                throw new SerializationException(Environment.GetResourceString("Serialization_AssemblyId",typeInformation)); 
                        }
                        break; 
                    default:
                        binaryTypeEnum = BinaryTypeEnum.Primitive;
                        typeInformation = primitiveTypeEnum;
                        break; 
                }
            } 
 
            SerTrace.Log( "BinaryConverter", "GetBinaryTypeInfo Exit ",((Enum)binaryTypeEnum).ToString(),", typeInformation ",typeInformation," assemId ",assemId);
            return binaryTypeEnum; 
        }
Пример #5
0
        // From the type create the BinaryTypeEnum and typeInformation which describes the type on the wire
        internal static BinaryTypeEnum GetBinaryTypeInfo(Type type, WriteObjectInfo objectInfo, string typeName, ObjectWriter objectWriter, out object typeInformation, out int assemId)
        {
            BinaryTypeEnum binaryTypeEnum;

            assemId = 0;
            typeInformation = null;

            if (ReferenceEquals(type, Converter.s_typeofString))
            {
                binaryTypeEnum = BinaryTypeEnum.String;
            }
            else if (((objectInfo == null) || ((objectInfo != null) && !objectInfo._isSi)) && (ReferenceEquals(type, Converter.s_typeofObject)))
            {
                // If objectInfo.Si then can be a surrogate which will change the type
                binaryTypeEnum = BinaryTypeEnum.Object;
            }
            else if (ReferenceEquals(type, Converter.s_typeofStringArray))
            {
                binaryTypeEnum = BinaryTypeEnum.StringArray;
            }
            else if (ReferenceEquals(type, Converter.s_typeofObjectArray))
            {
                binaryTypeEnum = BinaryTypeEnum.ObjectArray;
            }
            else if (Converter.IsPrimitiveArray(type, out typeInformation))
            {
                binaryTypeEnum = BinaryTypeEnum.PrimitiveArray;
            }
            else
            {
                InternalPrimitiveTypeE primitiveTypeEnum = objectWriter.ToCode(type);
                switch (primitiveTypeEnum)
                {
                    case InternalPrimitiveTypeE.Invalid:
                        string assembly = null;
                        if (objectInfo == null)
                        {
                            assembly = type.Assembly.FullName;
                            typeInformation = type.FullName;
                        }
                        else
                        {
                            assembly = objectInfo.GetAssemblyString();
                            typeInformation = objectInfo.GetTypeFullName();
                        }

                        if (assembly.Equals(Converter.s_urtAssemblyString))
                        {
                            binaryTypeEnum = BinaryTypeEnum.ObjectUrt;
                            assemId = 0;
                        }
                        else
                        {
                            binaryTypeEnum = BinaryTypeEnum.ObjectUser;
                            Debug.Assert(objectInfo != null, "[BinaryConverter.GetBinaryTypeInfo]objectInfo null for user object");
                            assemId = (int)objectInfo._assemId;
                            if (assemId == 0)
                            {
                                throw new SerializationException(SR.Format(SR.Serialization_AssemblyId, typeInformation));
                            }
                        }
                        break;
                    default:
                        binaryTypeEnum = BinaryTypeEnum.Primitive;
                        typeInformation = primitiveTypeEnum;
                        break;
                }
            }

            return binaryTypeEnum;
        }
        internal static BinaryTypeEnum GetBinaryTypeInfo(Type type, WriteObjectInfo objectInfo, string typeName, ObjectWriter objectWriter, out object typeInformation, out int assemId)
        {
            BinaryTypeEnum primitive;

            assemId         = 0;
            typeInformation = null;
            if (object.ReferenceEquals(type, Converter.typeofString))
            {
                return(BinaryTypeEnum.String);
            }
            if (((objectInfo == null) || ((objectInfo != null) && !objectInfo.isSi)) && object.ReferenceEquals(type, Converter.typeofObject))
            {
                return(BinaryTypeEnum.Object);
            }
            if (object.ReferenceEquals(type, Converter.typeofStringArray))
            {
                return(BinaryTypeEnum.StringArray);
            }
            if (object.ReferenceEquals(type, Converter.typeofObjectArray))
            {
                return(BinaryTypeEnum.ObjectArray);
            }
            if (Converter.IsPrimitiveArray(type, out typeInformation))
            {
                return(BinaryTypeEnum.PrimitiveArray);
            }
            InternalPrimitiveTypeE ee = objectWriter.ToCode(type);

            switch (ee)
            {
            case InternalPrimitiveTypeE.Invalid:
            {
                string fullName = null;
                if (objectInfo == null)
                {
                    fullName        = type.Assembly.FullName;
                    typeInformation = type.FullName;
                }
                else
                {
                    fullName        = objectInfo.GetAssemblyString();
                    typeInformation = objectInfo.GetTypeFullName();
                }
                if (fullName.Equals(Converter.urtAssemblyString))
                {
                    primitive = BinaryTypeEnum.ObjectUrt;
                    assemId   = 0;
                    return(primitive);
                }
                primitive = BinaryTypeEnum.ObjectUser;
                assemId   = (int)objectInfo.assemId;
                if (assemId == 0)
                {
                    throw new SerializationException(Environment.GetResourceString("Serialization_AssemblyId", new object[] { typeInformation }));
                }
                return(primitive);
            }
            }
            primitive       = BinaryTypeEnum.Primitive;
            typeInformation = ee;
            return(primitive);
        }
        // Token: 0x06005295 RID: 21141 RVA: 0x00121EF4 File Offset: 0x001200F4
        internal static BinaryTypeEnum GetBinaryTypeInfo(Type type, WriteObjectInfo objectInfo, string typeName, ObjectWriter objectWriter, out object typeInformation, out int assemId)
        {
            assemId         = 0;
            typeInformation = null;
            BinaryTypeEnum result;

            if (type == Converter.typeofString)
            {
                result = BinaryTypeEnum.String;
            }
            else if ((objectInfo == null || (objectInfo != null && !objectInfo.isSi)) && type == Converter.typeofObject)
            {
                result = BinaryTypeEnum.Object;
            }
            else if (type == Converter.typeofStringArray)
            {
                result = BinaryTypeEnum.StringArray;
            }
            else if (type == Converter.typeofObjectArray)
            {
                result = BinaryTypeEnum.ObjectArray;
            }
            else if (Converter.IsPrimitiveArray(type, out typeInformation))
            {
                result = BinaryTypeEnum.PrimitiveArray;
            }
            else
            {
                InternalPrimitiveTypeE internalPrimitiveTypeE = objectWriter.ToCode(type);
                if (internalPrimitiveTypeE == InternalPrimitiveTypeE.Invalid)
                {
                    string text;
                    if (objectInfo == null)
                    {
                        text            = type.Assembly.FullName;
                        typeInformation = type.FullName;
                    }
                    else
                    {
                        text            = objectInfo.GetAssemblyString();
                        typeInformation = objectInfo.GetTypeFullName();
                    }
                    if (text.Equals(Converter.urtAssemblyString))
                    {
                        result  = BinaryTypeEnum.ObjectUrt;
                        assemId = 0;
                    }
                    else
                    {
                        result  = BinaryTypeEnum.ObjectUser;
                        assemId = (int)objectInfo.assemId;
                        if (assemId == 0)
                        {
                            throw new SerializationException(Environment.GetResourceString("Serialization_AssemblyId", new object[]
                            {
                                typeInformation
                            }));
                        }
                    }
                }
                else
                {
                    result          = BinaryTypeEnum.Primitive;
                    typeInformation = internalPrimitiveTypeE;
                }
            }
            return(result);
        }