ReadAsText() public method

Populate this instance from the given Stream as a text KeyValue.
public ReadAsText ( Stream input ) : bool
input Stream The input to read from.
return bool
コード例 #1
0
ファイル: KeyValue.cs プロジェクト: zua07/Nexus-Mod-Manager
        /// <summary>
        /// Attempts to create an instance of <see cref="KeyValue"/> from the given input text.
        /// </summary>
        /// <param name="input">The input text to load.</param>
        /// <returns>a <see cref="KeyValue"/> instance if the load was successful, or <c>null</c> on failure.</returns>
        /// <remarks>
        /// This method will swallow any exceptions that occur when reading, use <see cref="ReadAsText"/> if you wish to handle exceptions.
        /// </remarks>
        public static KeyValue LoadFromString(string input)
        {
            byte[] bytes = Encoding.UTF8.GetBytes(input);

            using (var stream = new MemoryStream(bytes))
            {
                var kv = new KeyValue(null, null);

                try
                {
                    if (kv.ReadAsText(stream) == false)
                    {
                        return(null);
                    }

                    return(kv);
                }
                catch (Exception)
                {
                    return(null);
                }
            }
        }
コード例 #2
0
ファイル: KeyValue.cs プロジェクト: zua07/Nexus-Mod-Manager
        static KeyValue LoadFromFile(string path, bool asBinary)
        {
            if (File.Exists(path) == false)
            {
                return(null);
            }

            try
            {
                using (var input = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    var kv = new KeyValue(null, null);

                    if (asBinary)
                    {
                        if (kv.ReadAsBinary(input) == false)
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        if (kv.ReadAsText(input) == false)
                        {
                            return(null);
                        }
                    }

                    return(kv);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
コード例 #3
0
		/// <summary>
		/// Attempts to create an instance of <see cref="KeyValue"/> from the given input text.
		/// </summary>
		/// <param name="input">The input text to load.</param>
		/// <returns>a <see cref="KeyValue"/> instance if the load was successful, or <c>null</c> on failure.</returns>
		/// <remarks>
		/// This method will swallow any exceptions that occur when reading, use <see cref="ReadAsText"/> if you wish to handle exceptions.
		/// </remarks>
		public static KeyValue LoadFromString(string input)
		{
			byte[] bytes = Encoding.UTF8.GetBytes(input);

			using (var stream = new MemoryStream(bytes))
			{
				var kv = new KeyValue(null, null);

				try
				{
					if (kv.ReadAsText(stream) == false)
						return null;

					return kv;
				}
				catch (Exception)
				{
					return null;
				}
			}
		}
コード例 #4
0
		static KeyValue LoadFromFile(string path, bool asBinary)
		{
			if (File.Exists(path) == false)
			{
				return null;
			}

			try
			{
				using (var input = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
				{
					var kv = new KeyValue(null, null);

					if (asBinary)
					{
						if (kv.ReadAsBinary(input) == false)
						{
							return null;
						}
					}
					else
					{
						if (kv.ReadAsText(input) == false)
						{
							return null;
						}
					}

					return kv;
				}
			}
			catch (Exception)
			{
				return null;
			}
		}