public static void Marshal(object value, Stream stream)
        {
            Debug.Assert(value != null, "MarshalingManager: value cannot be null");
            ITypeMarshaler marshaler = GetMarshaler(value.GetType());

            marshaler.MarshalObject(value, stream);
        }
 public static object DemarshalObject(this ITypeMarshaler marshaler, byte[] data)
 {
     using (MemoryStream memoryStream = new MemoryStream(data))
     {
         return(marshaler.DemarshalObject(memoryStream));
     }
 }
 public static byte[] MarshalObject(this ITypeMarshaler marshaler, object value)
 {
     using (MemoryStream memoryStream = new MemoryStream())
     {
         marshaler.MarshalObject(value, memoryStream);
         return(memoryStream.ToArray());
     }
 }
Exemplo n.º 4
0
 public bool TryCreate(Type type, out ITypeMarshaler typeMarshaler)
 {
     if (!typeof(DynamicSettings).IsAssignableFrom(type))
     {
         typeMarshaler = null;
         return(false);
     }
     typeMarshaler = new DynamicSettingsMarhaler(type);
     return(true);
 }
 public static void RegisterMarshaler(ITypeMarshaler marshaler)
 {
     lock (Marshalers)
     {
         if (!Marshalers.ContainsKey(marshaler.ManagedType))
         {
             Marshalers.Add(marshaler.ManagedType, marshaler);
         }
     }
 }
Exemplo n.º 6
0
        public object ReadResult(Type returnType)
        {
            object result;

            byte[] data = ByteArrayMarshaler.Demarshal(InputStream);
            using (MemoryStream stream = new MemoryStream(data))
            {
                ITypeMarshaler marshaler = MarshalingManager.GetMarshaler(returnType);
                result = marshaler.DemarshalObject(stream);
            }
            return(result);
        }
        public bool TryCreate(Type type, out ITypeMarshaler typeMarshaler)
        {
            if (!IsUniqueSettingsCollection(type) || type.IsAbstract)
            {
                typeMarshaler = null;
                return(false);
            }
            Type           elementType      = GetSettingsType(type);
            ITypeMarshaler elementMarshaler = MarshalingManager.GetMarshaler(elementType);

            typeMarshaler = new UniqueSettingsCollectionMarhaler(type, elementMarshaler);
            return(true);
        }
Exemplo n.º 8
0
 public object[] ReadArguments(Type[] signature)
 {
     object[] arguments = new object[signature.Length];
     byte[]   data      = ByteArrayMarshaler.Demarshal(InputStream);
     using (MemoryStream stream = new MemoryStream(data))
     {
         for (int i = 0; i < arguments.Length; i++)
         {
             Type           type      = signature[i];
             ITypeMarshaler marshaler = MarshalingManager.GetMarshaler(type);
             arguments[i] = marshaler.DemarshalObject(stream);
         }
     }
     return(arguments);
 }
        public bool TryCreate(Type type, out ITypeMarshaler typeMarshaler)
        {
            if (!type.IsEnum)
            {
                typeMarshaler = null;
                return(false);
            }
            Type           underlyingType      = Enum.GetUnderlyingType(type);
            ITypeMarshaler underlyingMarshaler = MarshalingManager.GetMarshaler(underlyingType);

            if (underlyingMarshaler == null)
            {
                typeMarshaler = null;
                return(false);
            }
            typeMarshaler = new EnumMarshaler(type, underlyingMarshaler);
            return(true);
        }
Exemplo n.º 10
0
        public bool TryCreate(Type type, out ITypeMarshaler typeMarshaler)
        {
            if (!IsList(type))
            {
                typeMarshaler = null;
                return(false);
            }
            Type           elementType      = type.GetProperty("Item").PropertyType;
            ITypeMarshaler elementMarshaler = MarshalingManager.GetMarshaler(elementType);

            if (elementMarshaler == null)
            {
                typeMarshaler = null;
                return(false);
            }
            typeMarshaler = new ListMarshaler(type, elementMarshaler);
            return(true);
        }
Exemplo n.º 11
0
        public bool TryCreate(Type type, out ITypeMarshaler typeMarshaler)
        {
            if (!type.IsArray)
            {
                typeMarshaler = null;
                return(false);
            }
            Type           elementType      = type.GetElementType();
            ITypeMarshaler elementMarshaler = MarshalingManager.GetMarshaler(elementType);

            if (elementMarshaler == null)
            {
                typeMarshaler = null;
                return(false);
            }
            typeMarshaler = new ArrayMarshaler(type, elementMarshaler);
            return(true);
        }
Exemplo n.º 12
0
 internal EnumMarshaler(Type type, ITypeMarshaler underlyingMarshaler)
 {
     ManagedType          = type;
     _underlyingMarshaler = underlyingMarshaler;
 }
Exemplo n.º 13
0
 public ArrayMarshaler(Type type, ITypeMarshaler elementMarshaler)
 {
     ManagedType       = type;
     _elementMarshaler = elementMarshaler;
 }
Exemplo n.º 14
0
        public static object Demarshal(Type targetType, Stream stream)
        {
            ITypeMarshaler marshaler = GetMarshaler(targetType);

            return(marshaler.DemarshalObject(stream));
        }
Exemplo n.º 15
0
 public UniqueSettingsCollectionMarhaler(Type type, ITypeMarshaler elementMarshaler)
 {
     ManagedType       = type;
     _elementMarshaler = elementMarshaler;
 }