Esempio n. 1
0
        internal static bool CanHandle(TypeData typeData)
        {
            if (typeData.DefaultConstructor == null)
            {
                return(false);
            }
            foreach (var prop in typeData.Properties)
            {
                switch (prop.Kind)
                {
                case TypeData.TypeKind.FudgePrimitive:
                case TypeData.TypeKind.Inline:
                case TypeData.TypeKind.Reference:
                    // OK
                    break;

                default:
                    // Unknown
                    return(false);
                }

                if (!prop.HasPublicSetter && !ListSurrogate.IsList(prop.Type))      // Special case for lists, which we can just append to if no setter present
                {
                    // Not bean-style
                    return(false);
                }
            }
            return(true);
        }
 private Func <FudgeContext, TypeData, IFudgeSerializationSurrogate>[] BuildSelectorList()
 {
     // This is the list of potential surrogates, in the order that they are tested
     return(new Func <FudgeContext, TypeData, IFudgeSerializationSurrogate>[]
     {
         this.SurrogateFromAttribute,
         (c, td) => SerializableSurrogate.CanHandle(td) ? new SerializableSurrogate(td.Type) : null,
         (c, td) => ArraySurrogate.CanHandle(td) ? new ArraySurrogate(c, td) : null,
         (c, td) => DictionarySurrogate.CanHandle(td) ? new DictionarySurrogate(c, td) : null,
         (c, td) => ListSurrogate.CanHandle(td) ? new ListSurrogate(c, td) : null,
         (c, td) => ToFromFudgeMsgSurrogate.CanHandle(td) ? new ToFromFudgeMsgSurrogate(c, td) : null,
         (c, td) => DataContractSurrogate.CanHandle(td) ? new DataContractSurrogate(c, td) : null,
         (c, td) => DotNetSerializableSurrogate.CanHandle(td) ? new DotNetSerializableSurrogate(c, td) : null,
         this.SurrogateFromDotNetSurrogateSelector,
         (c, td) => SerializableAttributeSurrogate.CanHandle(td) ? new SerializableAttributeSurrogate(c, td) : null,
         (c, td) => PropertyBasedSerializationSurrogate.CanHandle(td) ? new PropertyBasedSerializationSurrogate(c, td) : null,
         (c, td) => ImmutableSurrogate.CanHandle(td) ? new ImmutableSurrogate(c, td) : null,
     });
 }
Esempio n. 3
0
        private static TypeKind CalcKind(FudgeContext context, TypeDataCache typeCache, Type type, FudgeFieldNameConvention fieldNameConvention, out TypeData subType, out TypeData subType2, out FudgeFieldType fieldType)
        {
            // REVIEW 2010-02-14 t0rx -- There seems to be some duplication here with the FudgeSurrogateSelector, should look at joining up
            subType   = null;
            subType2  = null;
            fieldType = context.TypeDictionary.GetByCSharpType(type);
            if (fieldType != null)
            {
                // Just a simple field
                return(TypeKind.FudgePrimitive);
            }

            // Check for arrays
            if (type.IsArray)
            {
                subType = typeCache.GetTypeData(type.GetElementType(), fieldNameConvention);
                return(TypeKind.Inline);
            }

            // Check for dictionaries
            Type keyType, valueType;

            if (DictionarySurrogate.IsDictionary(type, out keyType, out valueType))
            {
                subType  = typeCache.GetTypeData(keyType, fieldNameConvention);
                subType2 = typeCache.GetTypeData(valueType, fieldNameConvention);
                return(TypeKind.Inline);
            }

            // Check for lists
            Type elementType;

            if (ListSurrogate.IsList(type, out elementType))
            {
                subType = typeCache.GetTypeData(elementType, fieldNameConvention);
                return(TypeKind.Inline);
            }

            return(TypeKind.Reference);
        }