DescriptorOf() публичный Метод

public DescriptorOf ( Type objType ) : ITypeDescriptor
objType System.Type
Результат ITypeDescriptor
Пример #1
0
            public IDescriptorSerializerContext StoreNewDescriptors(AbstractBufferedWriter writer, object obj)
            {
                if (obj == null)
                {
                    return(this);
                }
                InfoForType infoForType;
                var         iKnowDescriptor = obj as IKnowDescriptor;

                if (iKnowDescriptor != null)
                {
                    var descriptor = iKnowDescriptor.GetDescriptor();
                    if (!_typeOrDescriptor2InfoMap.TryGetValue(descriptor, out infoForType) &&
                        !_typeSerializersMapping._typeOrDescriptor2Info.TryGetValue(descriptor, out infoForType))
                    {
                        infoForType = new InfoForType {
                            Id = 0, Descriptor = descriptor
                        };
                    }
                }
                else
                {
                    var objType = obj.GetType();
                    if (!_typeOrDescriptor2InfoMap.TryGetValue(objType, out infoForType) &&
                        !_typeSerializersMapping._typeOrDescriptor2Info.TryGetValue(objType, out infoForType))
                    {
                        var descriptor = _typeSerializers.DescriptorOf(objType);
                        if (_typeOrDescriptor2InfoMap.TryGetValue(descriptor, out infoForType))
                        {
                            _typeOrDescriptor2InfoMap[objType] = infoForType;
                        }
                        else if (_typeSerializersMapping._typeOrDescriptor2Info.TryGetValue(descriptor, out infoForType))
                        {
                            _typeSerializersMapping._typeOrDescriptor2Info[objType] = infoForType;
                        }
                        else
                        {
                            infoForType = new InfoForType {
                                Id = 0, Descriptor = descriptor
                            };
                        }
                    }
                }
                if (infoForType.Id == 0)
                {
                    AddDescriptor(infoForType);
                }
                if (!infoForType.KnownNewTypeDiscoverer)
                {
                    infoForType.NewTypeDiscoverer      = _typeSerializers.GetNewDescriptorSaver(infoForType.Descriptor);
                    infoForType.KnownNewTypeDiscoverer = true;
                }
                var action = infoForType.NewTypeDiscoverer;

                if (action != null)
                {
                    action(obj, this);
                }
                return(this);
            }
Пример #2
0
        public IDescriptorSerializerContext StoreNewDescriptors(object?obj)
        {
            if (obj == null)
            {
                return(this);
            }
            InfoForType infoForType;
            var         objType = obj.GetType();

            if (obj is IKnowDescriptor iKnowDescriptor)
            {
                var descriptor = iKnowDescriptor.GetDescriptor();
                if (!_typeOrDescriptor2Info.TryGetValue(descriptor, out infoForType))
                {
                    infoForType = new InfoForType {
                        Id = 0, Descriptor = descriptor
                    };
                }
            }
            else
            {
                if (!_typeOrDescriptor2Info.TryGetValue(objType, out infoForType))
                {
                    var descriptor = _typeSerializers.DescriptorOf(objType);
                    if (!_typeOrDescriptor2Info.TryGetValue(descriptor !, out infoForType))
                    {
                        infoForType = new InfoForType {
                            Id = 0, Descriptor = descriptor
                        };
                    }
                    else
                    {
                        _typeOrDescriptor2Info[objType] = infoForType;
                    }
                }
            }
Пример #3
0
        public IDescriptorSerializerContext StoreNewDescriptors(AbstractBufferedWriter writer, object obj)
        {
            if (obj == null)
            {
                return(this);
            }
            InfoForType infoForType;
            var         iKnowDescriptor = obj as IKnowDescriptor;

            if (iKnowDescriptor != null)
            {
                var descriptor = iKnowDescriptor.GetDescriptor();
                if (!_typeOrDescriptor2Info.TryGetValue(descriptor, out infoForType))
                {
                    infoForType = new InfoForType {
                        Id = 0, Descriptor = descriptor
                    };
                }
            }
            else
            {
                var objType = obj.GetType();
                if (!_typeOrDescriptor2Info.TryGetValue(objType, out infoForType))
                {
                    var descriptor = _typeSerializers.DescriptorOf(objType);
                    if (!_typeOrDescriptor2Info.TryGetValue(descriptor, out infoForType))
                    {
                        infoForType = new InfoForType {
                            Id = 0, Descriptor = descriptor
                        };
                    }
                    else
                    {
                        _typeOrDescriptor2Info[objType] = infoForType;
                    }
                }
            }
            DescriptorSerializerContext ctx = null;

            if (infoForType.Id == 0)
            {
                ctx = new DescriptorSerializerContext(this, writer);
                ctx.AddDescriptor(infoForType);
            }
            if (!infoForType.KnownNewTypeDiscoverer)
            {
                infoForType.NewTypeDiscoverer      = _typeSerializers.GetNewDescriptorSaver(infoForType.Descriptor, obj.GetType());
                infoForType.KnownNewTypeDiscoverer = true;
            }
            var action = infoForType.NewTypeDiscoverer;

            if (action != null)
            {
                if (ctx == null)
                {
                    ctx = new DescriptorSerializerContext(this, writer);
                }
                action(obj, ctx);
            }
            if (ctx != null && ctx.SomeTypeStored)
            {
                return(ctx);
            }
            return(this);
        }