Inheritance: IFieldHandler
Exemplo n.º 1
0
 public virtual IFieldHandler CreateFromType(Type type, FieldHandlerOptions options)
 {
     if (EnumFieldHandler.IsCompatibleWith(type))
     {
         return(new EnumFieldHandler(type));
     }
     foreach (var fieldHandler in BasicSerializersFactory.FieldHandlers)
     {
         if (fieldHandler.IsCompatibleWith(type, options))
         {
             return(fieldHandler);
         }
     }
     if (ListFieldHandler.IsCompatibleWith(type))
     {
         return(new ListFieldHandler(_provider.FieldHandlerFactory, _provider.TypeConvertorGenerator, type));
     }
     if (DictionaryFieldHandler.IsCompatibleWith(type))
     {
         return(new DictionaryFieldHandler(_provider.FieldHandlerFactory, _provider.TypeConvertorGenerator, type));
     }
     if (NullableFieldHandler.IsCompatibleWith(type))
     {
         return(new NullableFieldHandler(_provider.FieldHandlerFactory, _provider.TypeConvertorGenerator, type));
     }
     return(null);
 }
Exemplo n.º 2
0
        public IFieldHandler SpecializeLoadForType(Type type, IFieldHandler?typeHandler)
        {
            if (typeHandler == this)
            {
                return(this);
            }
            var enumTypeHandler = typeHandler as EnumFieldHandler;

            if (typeHandler == null && type.IsEnum)
            {
                enumTypeHandler = new EnumFieldHandler(type);
                typeHandler     = enumTypeHandler;
            }
            if (enumTypeHandler != null && _signed == enumTypeHandler._signed)
            {
                if (type.GetCustomAttributes(typeof(BinaryCompatibilityOnlyAttribute), false).Length != 0)
                {
                    if (new EnumConfiguration(Configuration).IsBinaryRepresentationSubsetOf(new EnumConfiguration(enumTypeHandler.Configuration)))
                    {
                        return(typeHandler);
                    }
                }
                else
                {
                    if (new EnumConfiguration(Configuration).IsSubsetOf(new EnumConfiguration(enumTypeHandler.Configuration)))
                    {
                        return(typeHandler);
                    }
                }
            }
            return(this);
        }
Exemplo n.º 3
0
 public virtual bool TypeSupported(Type type)
 {
     if (EnumFieldHandler.IsCompatibleWith(type))
     {
         return(true);
     }
     foreach (var fieldHandler in BasicSerializersFactory.FieldHandlers)
     {
         if (fieldHandler.IsCompatibleWith(type, FieldHandlerOptions.None))
         {
             return(true);
         }
     }
     if (ListFieldHandler.IsCompatibleWith(type))
     {
         return(true);
     }
     if (DictionaryFieldHandler.IsCompatibleWith(type))
     {
         return(true);
     }
     if (NullableFieldHandler.IsCompatibleWith(type))
     {
         return(true);
     }
     return(false);
 }