Esempio n. 1
0
 /// <summary>
 /// Constructs a new instance for a specific list type
 /// </summary>
 /// <param name="context"><see cref="FudgeContext"/> for this surrogate.</param>
 /// <param name="typeData"><see cref="TypeData"/> describing the type to serialize.</param>
 public ListSurrogate(FudgeContext context, TypeData typeData)
     : base(context, typeData, "SerializeList", "DeserializeList")
 {
 }
Esempio n. 2
0
        /// <summary>
        /// Detects whether a given type can be serialized with this class.
        /// </summary>
        /// <param name="typeData">Type to test.</param>
        /// <returns><c>true</c> if this class can handle the type.</returns>
        public static bool CanHandle(TypeData typeData)
        {
            Type elementType;

            return(IsList(typeData.Type, out elementType));
        }
Esempio n. 3
0
 /// <summary>
 /// Determines whether a given type can be serialized with this class.
 /// </summary>
 /// <param
 /// name="typeData">Type to test.</param>
 /// <returns><c>true</c> if this class can handle the type.</returns>
 public static bool CanHandle(TypeData typeData)
 {
     return(typeData.GetCustomAttribute <DataContractAttribute>() != null);
 }
Esempio n. 4
0
 /// <summary>
 /// Detects whether a given type can be serialized with this class.
 /// </summary>
 /// <param name="type">Type to test.</param>
 /// <returns><c>true</c> if this class can handle the type.</returns>
 public static bool CanHandle(TypeData type)
 {
     return(type.Type.IsArray);
 }
 /// <summary>
 /// Detects whether a given type can be serialized with this class.
 /// </summary>
 /// <param
 /// name="typeData">Type to test.</param>
 /// <returns><c>true</c> if this class can handle the type.</returns>
 public static bool CanHandle(TypeData typeData)
 {
     return(typeof(ISerializable).IsAssignableFrom(typeData.Type) && FindConstructor(typeData) != null);
 }
        private static ConstructorInfo FindConstructor(TypeData typeData)
        {
            var constructor = typeData.Type.GetConstructor(BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, new Type[] { typeof(SerializationInfo), typeof(StreamingContext) }, null);

            return(constructor);
        }
 private static MethodInfo GetToMsg(TypeData typeData)
 {
     return(typeData.PublicMethods.FirstOrDefault(m => m.Name == "ToFudgeMsg" &&
                                                  m.ReturnType == typeof(void) &&
                                                  ParamMatch(m, new Type[] { typeof(IAppendingFudgeFieldContainer), typeof(IFudgeSerializer) })));
 }
 private static MethodInfo GetFromMsg(TypeData typeData)
 {
     return(typeData.StaticPublicMethods.FirstOrDefault(m => m.Name == "FromFudgeMsg" &&
                                                        m.ReturnType == typeData.Type &&
                                                        ParamMatch(m, new Type[] { typeof(IFudgeFieldContainer), typeof(IFudgeDeserializer) })));
 }
Esempio n. 9
0
 /// <summary>
 /// Detects whether a given type can be serialized with this class.
 /// </summary>
 /// <param name="typeData">Type to test.</param>
 /// <returns><c>true</c> if this class can handle the type.</returns>
 public static bool CanHandle(TypeData typeData)
 {
     return(IsDictionary(typeData.Type));
 }
 internal static bool CanHandle(TypeData typeData)
 {
     return(GetToMsg(typeData) != null && GetFromMsg(typeData) != null);
 }
Esempio n. 11
0
 /// <summary>
 /// Constructs a new instance for a specific dictionary type
 /// </summary>
 /// <param name="context"><see cref="FudgeContext"/> for this surrogate.</param>
 /// <param name="typeData"><see cref="TypeData"/> describing the type to serialize.</param>
 public DictionarySurrogate(FudgeContext context, TypeData typeData)
     : base(context, typeData, "SerializeDictionary", "DeserializeDictionary")
 {
 }
Esempio n. 12
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);
        }
        private IFudgeSerializationSurrogate SurrogateFromAttribute(FudgeContext context, TypeData typeData)
        {
            var surrogateAttribute = typeData.CustomAttributes.FirstOrDefault(attrib => attrib is FudgeSurrogateAttribute);

            if (surrogateAttribute != null)
            {
                return(BuildSurrogate(typeData.Type, (FudgeSurrogateAttribute)surrogateAttribute));
            }
            return(null);
        }
        private IFudgeSerializationSurrogate SurrogateFromDotNetSurrogateSelector(FudgeContext context, TypeData typeData)
        {
            if (DotNetSurrogateSelector == null)
            {
                return(null);
            }

            ISurrogateSelector      selector;
            StreamingContext        sc = new StreamingContext(StreamingContextStates.Persistence);
            ISerializationSurrogate dotNetSurrogate = DotNetSurrogateSelector.GetSurrogate(typeData.Type, sc, out selector);

            if (dotNetSurrogate == null)
            {
                return(null);
            }

            return(new DotNetSerializationSurrogateSurrogate(context, typeData, dotNetSurrogate, selector));
        }
 /// <summary>
 /// Detects whether a given type can be serialized with this class.
 /// </summary>
 /// <param
 /// name="typeData">Type to test.</param>
 /// <returns><c>true</c> if this class can handle the type.</returns>
 public static bool CanHandle(TypeData typeData)
 {
     return(typeData.GetCustomAttribute <SerializableAttribute>() != null);
 }