예제 #1
0
 /// <summary>
 /// Controls the binding of a serialized object to a type.
 /// </summary>
 /// <param name="serializedType">The type of the object the formatter creates a new instance of.</param>
 /// <param name="assemblyName">Specifies the <see cref="T:System.Reflection.Assembly" /> name of the serialized object.</param>
 /// <param name="typeName">Specifies the <see cref="T:System.Type" /> name of the serialized object.</param>
 public override void BindToName(Type serializedType, out string assemblyName, out string typeName)
 {
     _defaultBinder.BindToName(serializedType, out assemblyName, out typeName);
     if (typeName.Contains(_realKinectNamespace))
     {
         var types = serializedType.GenericTypeArguments;
         if (types.Length > 0)
         {
             foreach (var type in types)
             {
                 if (type.Namespace == _realKinectNamespace)
                 {
                     var replaceWith = _jsonKinectNamespace + "." + type.Name + ", " + _jsonKinectAssembly;
                     typeName = typeName.Replace(type.AssemblyQualifiedName, replaceWith);
                 }
             }
         }
         else
         {
             typeName     = typeName.Replace(_realKinectAssembly, _jsonKinectAssembly);
             typeName     = typeName.Replace(_realKinectNamespace, _jsonKinectNamespace);
             assemblyName = assemblyName.Replace(_realKinectAssembly, _jsonKinectAssembly);
         }
     }
 }
예제 #2
0
        public static string smethod_4(Type type_1, FormatterAssemblyStyle formatterAssemblyStyle_0, SerializationBinder serializationBinder_0)
        {
            string assemblyQualifiedName;

            if (serializationBinder_0 != null)
            {
                string str2;
                string str3;
                serializationBinder_0.BindToName(type_1, out str2, out str3);
                assemblyQualifiedName = str3 + ((str2 == null) ? "" : (", " + str2));
            }
            else
            {
                assemblyQualifiedName = type_1.AssemblyQualifiedName;
            }
            switch (formatterAssemblyStyle_0)
            {
            case FormatterAssemblyStyle.Simple:
                return(smethod_5(assemblyQualifiedName));

            case FormatterAssemblyStyle.Full:
                return(assemblyQualifiedName);
            }
            throw new ArgumentOutOfRangeException();
        }
예제 #3
0
        public static string GetTypeName(Type t, FormatterAssemblyStyle assemblyFormat, SerializationBinder binder)
        {
            string text2;

            if (binder != null)
            {
                string text;
                string str;
                binder.BindToName(t, out text, out str);
                text2 = str + ((text == null) ? "" : (", " + text));
            }
            else
            {
                text2 = t.AssemblyQualifiedName;
            }
            switch (assemblyFormat)
            {
            case FormatterAssemblyStyle.Simple:
                return(ReflectionUtils.RemoveAssemblyDetails(text2));

            case FormatterAssemblyStyle.Full:
                return(text2);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #4
0
 private void InvokeSerializationBinder(SerializationBinder binder)
 {
     if (binder != null)
     {
         binder.BindToName(objectType, out binderAssemblyString, out binderTypeName);
     }
 }
        public static string GetTypeName(Type t, FormatterAssemblyStyle assemblyFormat, SerializationBinder binder)
        {
            string fullyQualifiedTypeName;

#if !(NET20 || NET35)
            if (binder != null)
            {
                string assemblyName, typeName;
                binder.BindToName(t, out assemblyName, out typeName);
                fullyQualifiedTypeName = typeName + (assemblyName == null ? "" : ", " + assemblyName);
            }
            else
            {
                fullyQualifiedTypeName = t.AssemblyQualifiedName;
            }
#else
            fullyQualifiedTypeName = t.AssemblyQualifiedName;
#endif

            switch (assemblyFormat)
            {
            case FormatterAssemblyStyle.Simple:
                return(RemoveAssemblyDetails(fullyQualifiedTypeName));

            case FormatterAssemblyStyle.Full:
                return(fullyQualifiedTypeName);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        public static string BindToName(this SerializationBinder @this, Type serializedType)
        {
            string assemblyName;
            string typeName;

            @this.BindToName(serializedType, out assemblyName, out typeName);
            return(assemblyName.IsNullOrEmpty() ? typeName : "{0}, {1}".Fmt(typeName, assemblyName));
        }
예제 #7
0
 private void InvokeSerializationBinder(SerializationBinder binder)
 {
     if (binder == null)
     {
         return;
     }
     binder.BindToName(this.objectType, out this.binderAssemblyString, out this.binderTypeName);
 }
        public void BindToName(Type serializedType, out string assemblyName, out string typeName)
        {
#if HAVE_SERIALIZATION_BINDER_BIND_TO_NAME
            SerializationBinder.BindToName(serializedType, out assemblyName, out typeName);
#else
            assemblyName = null;
            typeName     = null;
#endif
        }
        public void BindToName(Type serializedType, out string assemblyName, out string typeName)
        {
#if !(NET35 || NET20)
            SerializationBinder.BindToName(serializedType, out assemblyName, out typeName);
#else
            assemblyName = null;
            typeName     = null;
#endif
        }
예제 #10
0
 public override void BindToName(Type serializedType, out string assemblyName, out string typeName)
 {
     if (Inner != null)
     {
         Inner.BindToName(serializedType, out assemblyName, out typeName);
         return;
     }
     base.BindToName(serializedType, out assemblyName, out typeName);
 }
예제 #11
0
            public override void BindToName(Type serializedType, out string assemblyName, out string typeName)
            {
                assemblyName = null;
                typeName     = null;

                if (binder != null)
                {
                    binder.BindToName(serializedType, out assemblyName, out typeName);
                }
                else
                {
                    base.BindToName(serializedType, out assemblyName, out typeName);
                }
            }
예제 #12
0
 public override void BindToName(Type serializedType, out string assemblyName, out string typeName)
 {
     if (serializedType.FullName.Contains("["))
     // It's either a dynamic type as a result of projection or an
     // anonymous type perhaps constructed by a controller (e.g, a "Lookups" object)
     //
     // These two predicates would work for dynamic types but not anonymous types
     // if (serializedType.Assembly.IsDynamic)
     // if (serializedType.BaseType == typeof(Breeze.ContextProvider.DynamicTypeBase))
     {
         assemblyName = "Dynamic";
         typeName     = serializedType.Name;
     }
     else
     {
         _binder.BindToName(serializedType, out assemblyName, out typeName);
     }
 }
예제 #13
0
        private void Serialize(object graph)
        {
            List <PropertyInfo> properties = graph.GetType().GetProperties().ToList();

            Binder.BindToName(graph.GetType(), out string assemblyName, out string typeName);
            this._dataSB.Append("{" + assemblyName + "}\t{" + typeName + "}\t{m_idGenerator:\"" +
                                this.m_idGenerator.GetId(graph, out bool firstTime) + "\"}");

            foreach (PropertyInfo propertyInfo in properties)
            {
                WriteMember(propertyInfo.Name, propertyInfo.GetValue(graph));
            }

            this._dataSB.Append("\n");

            while (this.m_objectQueue.Count != 0)
            {
                this.Serialize(this.m_objectQueue.Dequeue());
            }
        }
        internal static void Write(this BinaryWriter writer, IAtomize atomize,
                                   SerializationBinder binder, Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            EnsureTypeIsSerializable(type);
            string name;
            string assembly;

            binder.BindToName(type, out assembly, out name);
            if (assembly == null)
            {
                assembly = type.Assembly.FullName;
            }
            if (name == null)
            {
                name = type.FullName;
            }
            writer.WriteInterned(atomize, assembly);
            writer.WriteInterned(atomize, name);
        }
예제 #15
0
        public static string GetTypeName(Type t, FormatterAssemblyStyle assemblyFormat, SerializationBinder binder)
        {
            string assemblyQualifiedName;

            if (binder != null)
            {
                binder.BindToName(t, out string str, out string str2);
                assemblyQualifiedName = str2 + ((str == null) ? "" : (", " + str));
            }
            else
            {
                assemblyQualifiedName = t.AssemblyQualifiedName;
            }
            if (assemblyFormat != FormatterAssemblyStyle.Simple)
            {
                if (assemblyFormat != FormatterAssemblyStyle.Full)
                {
                    throw new ArgumentOutOfRangeException();
                }
                return(assemblyQualifiedName);
            }
            return(RemoveAssemblyDetails(assemblyQualifiedName));
        }
예제 #16
0
 public override void BindToName(Type serializedType, out string assemblyName, out string typeName)
 {
     binder.BindToName(serializedType, out assemblyName, out typeName);
 }
예제 #17
0
        private void GetObjectData(object obj, out TypeMetadata metadata, out object data)
        {
            Type instanceType = obj.GetType();

#if NET_4_0
            string binderAssemblyName = null;
            string binderTypeName     = null;
            if (_binder != null)
            {
                _binder.BindToName(instanceType, out binderAssemblyName, out binderTypeName);
            }
#endif
            // Check if the formatter has a surrogate selector, if it does,
            // check if the surrogate selector handles objects of the given type.

            if (_surrogateSelector != null)
            {
                ISurrogateSelector      selector;
                ISerializationSurrogate surrogate = _surrogateSelector.GetSurrogate(instanceType, _context, out selector);
                if (surrogate != null)
                {
                    SerializationInfo info = new SerializationInfo(instanceType, new FormatterConverter());
                    surrogate.GetObjectData(obj, info, _context);
                    metadata = new SerializableTypeMetadata(instanceType, info);
#if NET_4_0
                    if (_binder != null)
                    {
                        metadata.BindToName(binderAssemblyName, binderTypeName);
                    }
#endif

                    data = info;
                    return;
                }
            }

            // Check if the object is marked with the Serializable attribute

            BinaryCommon.CheckSerializable(instanceType, _surrogateSelector, _context);

            _manager.RegisterObject(obj);

            ISerializable ser = obj as ISerializable;

            if (ser != null)
            {
                SerializationInfo info = new SerializationInfo(instanceType, new FormatterConverter());
                ser.GetObjectData(info, _context);
                metadata = new SerializableTypeMetadata(instanceType, info);
#if NET_4_0
                if (_binder != null)
                {
                    metadata.BindToName(binderAssemblyName, binderTypeName);
                }
#endif

                data = info;
            }
            else
            {
                data = obj;
                if (_context.Context != null)
                {
                    // Don't cache metadata info when the Context property is not null sice
                    // we can't control the number of possible contexts in this case
                    metadata = new MemberTypeMetadata(instanceType, _context);
#if NET_4_0
                    if (_binder != null)
                    {
                        metadata.BindToName(binderAssemblyName, binderTypeName);
                    }
#endif

                    return;
                }

                Hashtable typesTable;
                bool      isNew = false;
                lock (_cachedTypes) {
                    typesTable = (Hashtable)_cachedTypes [_context.State];
                    if (typesTable == null)
                    {
                        typesTable = new Hashtable();
                        _cachedTypes [_context.State] = typesTable;
                        isNew = true;
                    }
                }

                metadata = null;
                lock (typesTable) {
                    if (!isNew)
                    {
                        metadata = (TypeMetadata)typesTable [instanceType];
                    }

                    if (metadata == null)
                    {
                        metadata = CreateMemberTypeMetadata(instanceType);
#if NET_4_0
                        if (_binder != null)
                        {
                            metadata.BindToName(binderAssemblyName, binderTypeName);
                        }
#endif
                    }

                    typesTable [instanceType] = metadata;
                }
            }
        }
예제 #18
0
 private void InvokeSerializationBinder(SerializationBinder binder) =>
 binder?.BindToName(_objectType, out _binderAssemblyString, out _binderTypeName);
예제 #19
0
 public void BindToName(Type serializedType, out string assemblyName, out string typeName)
 {
     _serializationBinder.BindToName(serializedType, out assemblyName, out typeName);
 }