Exemple #1
0
        public SyncFileTarget(IFormatter formatter, string logFilePath, bool autoFlush = false)
            : base(formatter)
        {
            _logFilePath = logFilePath;
            _logFileDirectory = Path.GetDirectoryName(logFilePath);

            if (!string.IsNullOrEmpty(_logFileDirectory))
                Directory.CreateDirectory(_logFileDirectory);

            if (File.Exists(logFilePath))
            {
                File.Delete(logFilePath);
            }

            try
            {
                var file = File.Open(logFilePath, FileMode.Create, FileAccess.Write, FileShare.Read);
                _writer = new StreamWriter(file, Encoding.UTF8);
                _writer.AutoFlush = autoFlush;
            }
            catch (IOException)
            {
                _writer = StreamWriter.Null;
            }
        }
 public BaseLanguageWriter(ILanguage language, IFormatter formatter, IExceptionFormatter exceptionFormatter, bool writeExceptionsAsComments)
 {
     this.Language = language;
     this.formatter = formatter;
     this.exceptionFormatter = exceptionFormatter;
     this.WriteExceptionsAsComments = writeExceptionsAsComments;
 }
Exemple #3
0
        public FileStorage( string path )
        {
            // Open the file
            file = new FileStream(path, FileMode.OpenOrCreate);

            // Create the info object
            info = new FileInfo(path);
            lastLength = info.Length;

            try
            {
                // Check for read & write ability
                if( !(file.CanRead && file.CanWrite) )
                    throw new IOException("File filePath could not be opened for both read & write.");

                // Create our formatter
                formatter = new BinaryFormatter();

                InitializeDataStructures();
            }
            finally
            {
                file.Close();
            }
        }
Exemple #4
0
 public DropCommand(IConsoleWrapper console, IRepositoryFactoryFactory factory, IGameObjectQueries queries, IFormatter[] formatters)
     : base(console, factory, queries, formatters)
 {
     AddCommandName("drop");
     AddCommandName("putdown");
     AddCommandName("release");
 }
Exemple #5
0
        private static void Print(IFormatter formatter)
        {
            List<Publication> documents = new List<Publication>();

            var newspaper = new Newspaper(formatter);
            newspaper.Title = "The Publicist";
            newspaper.Articles.Add("Sugar linked to bad eyesight", "Rod Sugar");
            newspaper.Articles.Add("Sweden bans chocolate", "Willy Wonka");
            newspaper.Articles.Add("Opera house to be painted orange", "Orange Arup");
            documents.Add(newspaper);

            var book = new Book(formatter)
            {
                Title = "Price of Silence",
                Author = "Jay and Silent Bob",
                Text = "Blah-de-blah-de-blah..."
            };

            documents.Add(book);

            var magazine = new Magazine(formatter)
            {
                Name = "MixMag",
                PrintDate = "30/08/1993",
                CoverHeadline = "Downloads outstrip CD sales"
            };

            documents.Add(magazine);

            foreach (var doc in documents)
            {
                doc.Print();
            }
        }
 public void Before_Each_Test()
 {
     console = MockRepository.GenerateMock<IConsoleFacade>();
     repository = MockRepository.GenerateMock<IRepository<GameObject>>();
     format = new Formatter(console, repository);
     cmd = new DescribeCommand(console, repository, format);
 }
 private static string BuildFormatTimePart(IFormatter cultureFormatter, TimeUnit timeUnitType, int amountOfTimeUnits)
 {
     // Always use positive units to account for negative timespans
     return amountOfTimeUnits != 0
         ? cultureFormatter.TimeSpanHumanize(timeUnitType, Math.Abs(amountOfTimeUnits))
         : null;
 }
Exemple #8
0
 public RunnerInvocation(string dll, string tags, IFormatter formatter, bool failFast)
 {
     this.dll = dll;
     this.failFast = failFast;
     Tags = tags;
     Formatter = formatter;
 }
Exemple #9
0
 public FileModel(FileAndType ft, object content, FileAndType original = null, IFormatter serializer = null)
 {
     OriginalFileAndType = original ?? ft;
     FileAndType = ft;
     _content = content;
     _serializer = serializer;
 }
 private NetworkRecieverActor(Actor Reciever, bool IsServer)
 {
     this.formatter = new BinaryFormatter();
     this.IsServer = IsServer;
     if(Reciever is RecieverActor)
         this.Reciever = (RecieverActor)Reciever;
 }
 public InventoryCommand(IConsoleWrapper console, IRepositoryFactoryFactory factory, IGameObjectQueries queries, IFormatter[] formatters)
     : base(console, factory, queries, formatters)
 {
     AddCommandName("inventory");
     AddCommandName("inv");
     AddCommandName("i");
 }
 public StreamJournalWriter(IStore storage, EngineConfiguration config)
 {
     _config = config;
     _storage = storage;
     _journalFormatter = config.CreateFormatter(FormatterUsage.Journal);
     _rolloverStrategy = _config.CreateRolloverStrategy();
 }
Exemple #13
0
 public TakeCommand(IConsoleWrapper console, IRepositoryFactoryFactory factory, IGameObjectQueries queries, IFormatter[] formatters)
     : base(console, factory, queries, formatters)
 {
     AddCommandName("take");
     AddCommandName("pickup");
     AddCommandName("get");
 }
Exemple #14
0
        public override void Write(Entry entry, IFormatter formatter)
        {
            lock (typeof (ColoredConsoleTarget))
            {
                var oldColor = Console.ForegroundColor;

                switch (entry.Level)
                {
                    case LogLevel.Warn:
                        Console.ForegroundColor = ConsoleColor.DarkYellow;
                        break;

                    case LogLevel.Error:
                        Console.ForegroundColor = ConsoleColor.Red;
                        break;

                    case LogLevel.Fatal:
                        Console.ForegroundColor = ConsoleColor.Magenta;
                        break;
                }

                var content = (Formatter ?? formatter).Format(entry);

                Console.Write(content);

                Console.ForegroundColor = oldColor;
            }
        }
        public SimpleIterativeRouter2(Key self, ushort tcpPort, IMessagingSocket sock, IKeyBasedRoutingAlgorithm algo, IFormatter formatter, bool isStrictMode)
        {
            _selfId = self;
            _tcpPort = tcpPort;
            _sock = sock;
            _algo = algo;
            _strict_mode = isStrictMode;

            // メッセージに含むことの出来る大体の最大NodeHandle数を計算
            int overhead, nodeHandleBytes;
            {
                using (MemoryStream ms = new MemoryStream ()) {
                    formatter.Serialize (ms, new NextHopResponse (self, _tcpPort, true, new NodeHandle[0]));
                    overhead = (int)ms.Length;
                }
                using (MemoryStream ms = new MemoryStream ()) {
                    formatter.Serialize (ms, new NodeHandle (self, new IPEndPoint (IPAddress.Loopback, 0), tcpPort));
                    nodeHandleBytes = (int)ms.Length;
                }
            }
            _maxNodeHandlesPerResponse = (dgramMaxSize - overhead) / nodeHandleBytes;

            algo.Setup (self, this);
            sock.AddInquiredHandler (typeof (NextHopQuery), MessagingSocket_Inquired_NextHopQuery);
            sock.AddInquiredHandler (typeof (CloseNodeQuery), MessagingSocket_Inquired_CloseNodeQuery);
        }
Exemple #16
0
 public override void Write(Entry entry, IFormatter formatter)
 {
     var contents = (Formatter ?? formatter).Format(entry);
     switch (entry.Level)
     {
         case LogLevel.Trace:
             Log.Verbose(_tag, contents);
             break;
         case LogLevel.Debug:
             Log.Debug(_tag, contents);
             break;
         case LogLevel.Info:
             Log.Info(_tag, contents);
             break;
         case LogLevel.Warn:
             Log.Warn(_tag, contents);
             break;
         case LogLevel.Error:
             Log.Error(_tag, contents);
             break;
         case LogLevel.Fatal:
             Log.WriteLine(LogPriority.Assert, _tag, contents);
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
Exemple #17
0
 public MessageReceiver(TcpClient client, IFormatter formatter, IHandler handler)
 {
     this.client = client;
     this.handler = handler;
     this.assembler = new MessageAssembler(formatter);
     this.chunk = new byte[4096];
 }
Exemple #18
0
 static void Serialize(string filename,IFormatter formatter)
 {
     MyItemType obj = new MyItemType(1, "food");
     FileStream fs = new FileStream(filename,FileMode.OpenOrCreate) ;
     formatter.Serialize(fs, obj);
     fs.Close();
 }
 public SimpleClient(string IP, int Port)
 {
     newClient = new TcpClient(IP, Port);
     newNetworkStream = newClient.GetStream();
     formatter = new BinaryFormatter();
     new Thread();
 }
        /// <inheritdoc />
        public string Format(object obj, IFormatter formatter)
        {
            if (state == null)
                state = new ReentranceState();

            string result = null;
            state.Enter(reentranceCount =>
            {
                if (reentranceCount >= 3 || state.Visited.Contains(obj))
                {
                    result = "{...}";
                }
                else
                {
                    try
                    {
                        state.Visited.Add(obj);
                        result = FormatRecursive(obj, formatter);
                    }
                    finally
                    {
                        state.Visited.Remove(obj);
                    }
                }
            });

            return result;
        }
Exemple #21
0
 public LookCommand(IConsoleFacade console,  IRepository<GameObject> repository, IFormatter format, IPlayer player)
 {
     this.console = console;
     this.repository = repository;
     this.format = format;
     this.player = player;
 }
        public ConsoleTarget(IFormatter formatter)
        {
			if (formatter == null)
				throw new ArgumentNullException("formatter");

            Formatter = formatter;
        }
Exemple #23
0
        public void Run(string dll, string filter, IFormatter outputFormatter, Action<string, string, IFormatter> action)
        {
            this.dll = dll;

            var setup = new AppDomainSetup();

            setup.ConfigurationFile = Path.GetFullPath(config);

            setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            domain = AppDomain.CreateDomain("NSpecDomain.Run", null, setup);

            var type = typeof(Wrapper);

            var assemblyName = type.Assembly.GetName().Name;

            var typeName = type.FullName;

            domain.AssemblyResolve += Resolve;

            var wrapper = (Wrapper)domain.CreateInstanceAndUnwrap(assemblyName, typeName);

            wrapper.Execute(dll, filter, outputFormatter, action);

            AppDomain.Unload(domain);
        }
Exemple #24
0
 public LogConfig(IFormatter formatter, LogCategoryRegistrar categoryRegistry = null)
 {
     Formatter = formatter;
     CategoryRegistrar = categoryRegistry ?? new LogCategoryRegistrar();
     TargetConfigs = new List<TargetConfig>();
     Levels = new bool[LogLevels.Levels.Length];
 }
Exemple #25
0
 HelpPrinter(IFormatter formatter)
 {
     this.formatter = formatter;
     var parser = new Parser();
     parser.LoadPlugin(typeof(UnitValue).Assembly);
     doc = Documentation.Create(parser.Context);
 }
Exemple #26
0
 public PickUpCommand(IConsoleFacade console, IRepositoryFactoryFactory factory, IGameObjectQueries goQueries, IFormatter[] formatters)
     : base(console, factory, goQueries, formatters)
 {
     AddCommandName("pickup");
     AddCommandName("get");
     AddCommandName("grab");
 }
        /// <summary>
        /// Build middle server with a given port.
        /// </summary>
        /// <param name="port"></param>
        public UniVRPNityServer(int port = Network.UniVRPNityServerDefaultPort,
            bool verbose = true,
            int updateInterval = DefaultUpdateInterval)
        {
            Console.WriteLine("==== UniVRPNity middle server ====");
            formatter = new BinaryFormatter();
            remotes = new VrpnObjects();
            this.verbose = verbose;
            this.updateInterval = updateInterval;
            //Create a socket for listening connections
            middleServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
            IPEndPoint ipLocal = new IPEndPoint(IPAddress.Loopback, port);

            try
            {
                middleServer.Bind(ipLocal);
                Console.WriteLine("\r Running on port " + port);

                //Run server
                StartListening();

            }
            catch (SocketException)
            {
                Console.Error.WriteLine("Error : Cannot reach " + ipLocal.ToString() + " address at port " + port);
                Console.Error.WriteLine("An other application is probably using this port.");
                Console.ReadKey();
            }
        }
Exemple #28
0
 public IPort Bind(int portNumber, IFormatter formatter)
 {
     TcpPort port = new TcpPort(portNumber, formatter);
     port.Open();
     ports.Add(port);
     return port;
 }
Exemple #29
0
 public Message(byte[] chunk, int chunkSize, int offset, IFormatter formatter)
 {
     this.chunk = chunk;
     this.chunkSize = chunkSize;
     this.offset = offset;
     this.formatter = formatter;
 }
 /// <inheritdoc />
 public virtual string Format(object obj, IFormatter formatter)
 {
     var value = (Type) obj;
     var result = new StringBuilder();
     AppendType(result, value);
     return result.ToString();
 }
Exemple #31
0
 public void Serialize <T>(IFormatter f, JsonSchemaValidationContext c, T o)
 {
     GenericSerializer <T> .Serialize(this, f, c, o);
 }
 public void ToJsonScheama(IFormatter f)
 {
     f.Key("type"); f.Value("object");
 }
 public Internal(IFormatter formatter)
     : base(formatter)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SimpleExpressionBinding"/> class.
 /// </summary>
 /// <param name="sourceExpression">
 /// The source expression.
 /// </param>
 /// <param name="targetExpression">
 /// The target expression.
 /// </param>
 /// <param name="formatter">
 /// The formatter to use.
 /// </param>
 public SimpleExpressionBinding(string sourceExpression, string targetExpression, IFormatter formatter)
     : base(formatter)
 {
     this.sourceExpression = Expression.Parse(sourceExpression);
     this.targetExpression = Expression.Parse(targetExpression);
 }
        public bool TryGetFormatter(Type type, FormatterLocationStep step, ISerializationPolicy policy, out IFormatter formatter)
        {
            if (!type.IsArray)
            {
                formatter = null;
                return(false);
            }

            if (type.GetArrayRank() == 1)
            {
                if (FormatterUtilities.IsPrimitiveArrayType(type.GetElementType()))
                {
                    formatter = (IFormatter)Activator.CreateInstance(typeof(PrimitiveArrayFormatter <>).MakeGenericType(type.GetElementType()));
                }
                else
                {
                    formatter = (IFormatter)Activator.CreateInstance(typeof(ArrayFormatter <>).MakeGenericType(type.GetElementType()));
                }
            }
            else
            {
                formatter = (IFormatter)Activator.CreateInstance(typeof(MultiDimensionalArrayFormatter <,>).MakeGenericType(type, type.GetElementType()));
            }

            return(true);
        }
Exemple #36
0
 public void Serialize <T>(IFormatter f, JsonSchemaValidationContext c, T o)
 {
     f.Serialize(GenericCast <T, int> .Cast(o));
 }
Exemple #37
0
 public void ToJsonSchema(IFormatter f)
 {
     f.Key("type"); f.Value("integer");
 }
        public ReferenceFormatter(CerasSerializer serializer)
        {
            _serializer = serializer;

            _typeFormatter = (IFormatter <Type>)serializer.GetSpecificFormatter(typeof(Type));
        }
Exemple #39
0
        public FileModel(FileAndType ft, object content, FileAndType original = null, IFormatter serializer = null)
        {
            OriginalFileAndType = original ?? ft;

            if (OriginalFileAndType.File.StartsWith("~/"))
            {
                Key = OriginalFileAndType.File;
            }
            else
            {
                Key = "~/" + OriginalFileAndType.File;
            }

            FileAndType    = ft;
            ModelWithCache = new ModelWithCache(content, serializer);
        }
 public FileStorage(string folderName, string fileName, IFormatter formatter)
 {
     FolderName = folderName;
     FileName   = fileName;
     Formatter  = formatter;
 }
 protected SelectFormatter(IFormatter <TInner> innerSerializer, bool mapForSize = false)
 {
     _innerSerializer = innerSerializer;
     _mapForSize      = mapForSize;
 }
Exemple #42
0
 public Book(IFormatter formatter)
     : base(formatter)
 {
 }
 public FileDataService()
 {
     this.formatter = new BinaryFormatter();
 }
 public SelectFuncFormatter(IFormatter <TInner> innerSerializer, Func <TOuter, TInner> toInner, Func <TInner, TOuter> toOuter, bool mapForSize = false) :
     base(innerSerializer, mapForSize)
 {
     _toInner = toInner;
     _toOuter = toOuter;
 }
Exemple #45
0
 public PokingServer(int port, object reactingObject, IFormatter formatter = null, ILogger logger = null, bool useCompression = false)
     : base(new IPEndPoint(IPAddress.Any, port), formatter, logger, useCompression)
 {
     this.reactingObject = reactingObject;
 }
 public FileDataService(IFormatter formatter)
 {
     this.formatter = formatter;
 }
 public SerializationBLL()
     : base()
 {
     m_Formatter = new BinaryFormatter();
 }
 /// <summary>
 /// Creates new instance.
 /// </summary>
 /// <param name="eventStore">The underlaying event store.</param>
 /// <param name="commandStore">The underlaying command store.</param>
 /// <param name="eventFormatter">The formatter for serializing event payloads.</param>
 /// <param name="commandFormatter">The formatter for serializing commands.</param>
 /// <param name="factory">The process root factory.</param>
 /// <param name="eventDispatcher">The dispatcher for newly created events in the processes.</param>
 /// <param name="commandDispatcher">The dispatcher for newly created commands in the processes.</param>
 /// <param name="snapshotProvider">The snapshot provider.</param>
 /// <param name="snapshotStore">The store for snapshots.</param>
 public ProcessRootRepository(IEventStore eventStore, ICommandStore commandStore, IFormatter eventFormatter, ISerializer commandFormatter,
                              IAggregateRootFactory <T> factory, IEventDispatcher eventDispatcher, ICommandDispatcher commandDispatcher, ISnapshotProvider snapshotProvider, ISnapshotStore snapshotStore)
     : base(eventStore, eventFormatter, factory, eventDispatcher, snapshotProvider, snapshotStore)
 {
     Ensure.NotNull(commandStore, "commandStore");
     Ensure.NotNull(commandDispatcher, "commandDispatcher");
     Ensure.NotNull(commandFormatter, "commandFormatter");
     this.commandStore      = commandStore;
     this.commandFormatter  = commandFormatter;
     this.commandDispatcher = commandDispatcher;
 }
 public void AddFormatter(IFormatter <Tinput> formatter)
 {
 }
Exemple #50
0
 public FileNotifier(IFormatter formatter, Func <Counterexample, string> pathGenerator)
     : base(formatter)
 {
     _pathGenerator = pathGenerator;
 }
Exemple #51
0
 ///<summary>
 /// Creates a new instance of this HasTextFilteringFormatter.
 ///</summary>
 /// <param name="defaultValue">the default value to be returned, if input text doesn't contain text</param>
 ///<param name="underlyingFormatter">an optional underlying formatter</param>
 /// <remarks>
 /// If no underlying formatter is specified, the values
 /// get passed through "as-is" after being filtered
 /// </remarks>
 public HasTextFilteringFormatter(string defaultValue, IFormatter underlyingFormatter)
     : base(underlyingFormatter)
 {
     _defaultValue = defaultValue;
 }
 public void DeleteFormatter(IFormatter <Tinput> formatter)
 {
 }
 public PokingClientConnection(object reactingObject, IFormatter customFormatter = null, ILogger logger = null, bool useCompression = false)
     : base(customFormatter, logger, useCompression)
 {
     Reactor = new Reactor(this, reactingObject);
 }
Exemple #54
0
 /// <summary>
 /// Initializes a new message.
 /// </summary>
 /// <param name="name">The name of the message.</param>
 /// <param name="payload">The payload of the message.</param>
 /// <param name="formatter">The payload serializer.</param>
 /// <param name="type">MIME type of the message.</param>
 public Message(string name, T payload, IFormatter <T> formatter, string?type = null)
     : this(name, payload, formatter, new ContentType(type.IfNullOrEmpty(MediaTypeNames.Application.Octet)))
 {
 }
Exemple #55
0
        public void FormatAssociativeTest()
        {
            IFormatter f = Service <IFormatter> .Instance;
            MathSystem s = project.CurrentSystem;

            s.RemoveUnusedObjects();

            project.Interpret("v1 <- (a+b)+(c+d);");
            Signal v1 = s.LookupNamedSignal("v1");

            Assert.AreEqual("(a+b)+(c+d)", f.Format(v1, FormattingOptions.Compact), "V1A");
            Signal v1S = Std.AutoSimplify(v1);

            Assert.AreEqual("a+b+c+d", f.Format(v1S, FormattingOptions.Compact), "V1B");

            project.Interpret("v2 <- (a-b)+(c-d);");
            Signal v2 = s.LookupNamedSignal("v2");

            Assert.AreEqual("(a-b)+(c-d)", f.Format(v2, FormattingOptions.Compact), "V2A");
            Signal v2S = Std.AutoSimplify(v2);

            Assert.AreEqual("a+-1*b+c+-1*d", f.Format(v2S, FormattingOptions.Compact), "V2B");

            project.Interpret("w1 <- (a-b)-(c-d);");
            Signal w1 = s.LookupNamedSignal("w1");

            Assert.AreEqual("(a-b)-(c-d)", f.Format(w1, FormattingOptions.Compact), "W1A");
            Signal w1S = Std.AutoSimplify(w1);

            Assert.AreEqual("a+-1*b+-1*c+d", f.Format(w1S, FormattingOptions.Compact), "W1B");

            project.Interpret("w2 <- (a+b)-(c+d);");
            Signal w2 = s.LookupNamedSignal("w2");

            Assert.AreEqual("(a+b)-(c+d)", f.Format(w2, FormattingOptions.Compact), "W2A");
            Signal w2S = Std.AutoSimplify(w2);

            Assert.AreEqual("a+b+-1*c+-1*d", f.Format(w2S, FormattingOptions.Compact), "W2B");

            project.Interpret("x1 <- (a*b)*(c*d);");
            Signal x1 = s.LookupNamedSignal("x1");

            Assert.AreEqual("(a*b)*(c*d)", f.Format(x1, FormattingOptions.Compact), "X1A");
            Signal x1S = Std.AutoSimplify(x1);

            Assert.AreEqual("a*b*c*d", f.Format(x1S, FormattingOptions.Compact), "X1B");

            project.Interpret("x2 <- (a/b)*(c/d);");
            Signal x2 = s.LookupNamedSignal("x2");

            Assert.AreEqual("(a/b)*(c/d)", f.Format(x2, FormattingOptions.Compact), "X2A");
            Signal x2S = Std.AutoSimplify(x2);

            Assert.AreEqual("a*b^(-1)*c*d^(-1)", f.Format(x2S, FormattingOptions.Compact), "X2B");

            project.Interpret("y1 <- (a/b)/(c/d);");
            Signal y1 = s.LookupNamedSignal("y1");

            Assert.AreEqual("(a/b)/(c/d)", f.Format(y1, FormattingOptions.Compact), "Y1A");
            Signal y1S = Std.AutoSimplify(y1);

            Assert.AreEqual("a*b^(-1)*c^(-1)*d", f.Format(y1S, FormattingOptions.Compact), "Y1B");

            project.Interpret("y2 <- (a*b)/(c*d);");
            Signal y2 = s.LookupNamedSignal("y2");

            Assert.AreEqual("(a*b)/(c*d)", f.Format(y2, FormattingOptions.Compact), "Y2A");
            Signal y2S = Std.AutoSimplify(y2);

            Assert.AreEqual("a*b*c^(-1)*d^(-1)", f.Format(y2S, FormattingOptions.Compact), "Y2B");
        }
Exemple #56
0
 ///<summary>
 /// Creates a new instance of this HasTextFilteringFormatter using null as default value.
 ///</summary>
 ///<param name="underlyingFormatter">an optional underlying formatter</param>
 /// <remarks>
 /// If no underlying formatter is specified, the values
 /// get passed through "as-is" after being filtered
 /// </remarks>
 public HasTextFilteringFormatter(IFormatter underlyingFormatter)
     : this(null, underlyingFormatter)
 {
 }
 public Document(IFormatter formatter)
 {
     this.formatter = formatter;
 }
Exemple #58
0
 public DefaultConsoleWriter(IFormatter formatter)
 {
     this.formatter = formatter;
 }
Exemple #59
0
        private void ParseDataNode(XmlReader reader)
        {
            string name         = reader[ResXResourceWriter.NameStr];
            string typeName     = reader[ResXResourceWriter.TypeStr];
            string mimeTypeName = reader[ResXResourceWriter.MimeTypeStr];

            reader.Read();
            object value = null;

            if (reader.NodeType == XmlNodeType.Element)
            {
                value = reader.ReadElementString();
            }
            else
            {
                value = reader.Value.Trim();
            }

            if (mimeTypeName != null && mimeTypeName.Length > 0)
            {
                if (String.Equals(mimeTypeName, ResXResourceWriter.BinSerializedObjectMimeType) ||
                    String.Equals(mimeTypeName, ResXResourceWriter.Beta2CompatSerializedObjectMimeType) ||
                    String.Equals(mimeTypeName, ResXResourceWriter.CompatBinSerializedObjectMimeType))
                {
                    string text = (string)value;
                    byte[] serializedData;
                    serializedData = FromBase64WrappedString(text);

                    if (binaryFormatter == null)
                    {
                        binaryFormatter        = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                        binaryFormatter.Binder = new ResXSerializationBinder(typeResolver);
                    }
                    IFormatter formatter = binaryFormatter;
                    if (serializedData != null && serializedData.Length > 0)
                    {
                        value = formatter.Deserialize(new MemoryStream(serializedData));
                        if (value is ResXNullRef)
                        {
                            value = null;
                        }
                    }
                }
                else if (String.Equals(mimeTypeName, ResXResourceWriter.SoapSerializedObjectMimeType) ||
                         String.Equals(mimeTypeName, ResXResourceWriter.CompatSoapSerializedObjectMimeType))
                {
                    string text = (string)value;
                    byte[] serializedData;
                    serializedData = FromBase64WrappedString(text);

                    if (serializedData != null && serializedData.Length > 0)
                    {
                        // Performance : don't inline a new SoapFormatter here.  That will always bring in
                        //               the soap assembly, which we don't want.  Throw this in another
                        //               function so the class doesn't have to get loaded.
                        //
                        IFormatter formatter = CreateSoapFormatter();
                        value = formatter.Deserialize(new MemoryStream(serializedData));
                        if (value is ResXNullRef)
                        {
                            value = null;
                        }
                    }
                }
                else if (String.Equals(mimeTypeName, ResXResourceWriter.ByteArraySerializedObjectMimeType))
                {
                    if (typeName != null && typeName.Length > 0)
                    {
                        Type type = ResolveType(typeName);
                        if (type != null)
                        {
                            TypeConverter tc = TypeDescriptor.GetConverter(type);
                            if (tc.CanConvertFrom(typeof(byte[])))
                            {
                                string text = (string)value;
                                byte[] serializedData;
                                serializedData = FromBase64WrappedString(text);

                                if (serializedData != null)
                                {
                                    value = tc.ConvertFrom(serializedData);
                                }
                            }
                        }
                        else
                        {
                            Debug.Fail("Could not find type for " + typeName);
                            // Throw a TypeLoadException here, don't silently
                            // eat this info.  ResolveType failed, so
                            // Type.GetType should as well.
                            Type.GetType(typeName, true);
                        }
                    }
                }
            }
            else if (typeName != null && typeName.Length > 0)
            {
                Type type = ResolveType(typeName);
                if (type != null)
                {
                    if (type == typeof(ResXNullRef))
                    {
                        value = null;
                    }
                    else if (typeName.IndexOf("System.Byte[]") != -1 && typeName.IndexOf("mscorlib") != -1)
                    {
                        // Handle byte[]'s, which are stored as base-64 encoded strings.
                        // We can't hard-code byte[] type name due to version number
                        // updates & potential whitespace issues with ResX files.
                        value = FromBase64WrappedString((string)value);
                    }
                    else
                    {
                        TypeConverter tc = TypeDescriptor.GetConverter(type);
                        if (tc.CanConvertFrom(typeof(string)))
                        {
                            string text = (string)value;
                            value = tc.ConvertFromInvariantString(text);
                        }
                        else
                        {
                            Debug.WriteLine("Converter for " + type.FullName + " doesn't support string conversion");
                        }
                    }
                }
                else
                {
                    Debug.Fail("Could not find type for " + typeName);
                    // Throw a TypeLoadException for this type which we
                    // couldn't load to include fusion binding info, etc.
                    Type.GetType(typeName, true);
                }
            }
            else
            {
                // if mimeTypeName and typeName are not filled in, the value must be a string
                Debug.Assert(value is string, "Resource entries with no Type or MimeType must be encoded as strings");
            }

            if (name == null)
            {
                throw new ArgumentException(SR.GetString(SR.InvalidResXResourceNoName, value));
            }
            resData[name] = value;
        }
        public bool TryGetFormatter(Type type, FormatterLocationStep step, ISerializationPolicy policy, out IFormatter formatter)
        {
            if (!typeof(Delegate).IsAssignableFrom(type))
            {
                formatter = null;
                return(false);
            }

            formatter = (IFormatter)Activator.CreateInstance(typeof(DelegateFormatter <>).MakeGenericType(type));
            return(true);
        }