Ejemplo n.º 1
0
        private void AnalyzeStringBuilder()
        {
            Console.WriteLine("\n" + Utility.LineSeprator);
            Console.WriteLine("StringBuilder analysis");
            Console.WriteLine("Object HashCode: " + _stringBuilderType?.GetHashCode());
            Console.WriteLine("\nText Added =>  _stringBuilderType = new StringBuilder(\"Text Initialized\")");
            _stringBuilderType = new StringBuilder("Text Initialized");
            Console.WriteLine("String Builder Value: " + _stringBuilderType);
            Console.WriteLine("Object HashCode: " + _stringBuilderType.GetHashCode());

            Console.WriteLine("\nText Appended => _stringBuilderType.Append(\"Text Appended.\")");
            _stringBuilderType.Append("Text Appended.");
            Console.WriteLine("String Builder Value: " + _stringBuilderType);
            Console.WriteLine("Object HashCode: " + _stringBuilderType.GetHashCode());

            Console.WriteLine("\nText override =>   _stringBuilderType.Clear();\n"
                              + " _stringBuilderType.Append(\"Text Override\"); ");
            _stringBuilderType.Clear();
            _stringBuilderType.Append("Text Override");
            Console.WriteLine("String Builder Value: " + _stringBuilderType);
            Console.WriteLine("Object HashCode: " + _stringBuilderType.GetHashCode());

            Console.WriteLine("\nEverytime when a operation is performed object is not changed only content is changed.\nStringBuilder is a mutable type object.");
            Console.WriteLine(Utility.LineSeprator);
        }
Ejemplo n.º 2
0
        public override int GetHashCode()
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(Numero);
            builder.Append(Capitulo);
            builder.Append(Libro);
            builder.Append(CodigoBiblia);

            return(builder.GetHashCode());
        }
Ejemplo n.º 3
0
        private static string GetCaption()
        {
            var stringBuilder = new StringBuilder();

            for (int count = 0; count < 26; count++)
            {
                var currentSymbol = (char)random.Next(48, 127);
                stringBuilder.Append(currentSymbol);
            }

            return(stringBuilder.GetHashCode().ToString());
        }
Ejemplo n.º 4
0
 public override int GetHashCode()
 {
     unchecked
     {
         int    result = EntityId.GetHashCode();
         string name   = Name == null ? "" : Name;
         result = (result * 397) ^ name.GetHashCode();
         result = (result * 397) ^ AppendedDistance.GetHashCode();
         result = (result * 397) ^ (int)Status;
         return(result);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Redefines GetHashCode method.
        /// </summary>
        /// <returns>Hash code.</returns>
        public override int GetHashCode()
        {
            StringBuilder hashString = new StringBuilder();

            hashString.Append(Min);
            hashString.Append(Max);
            foreach (var pt in Points)
            {
                hashString.Append(pt);
            }
            return(hashString.GetHashCode());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Overrides the <see cref="GetHashCode"/> method for a <see cref="FieldObjectBase"/>.
        /// </summary>
        /// <returns>Returns an <see cref="int"/> representing the unique hash code for the <see cref="FieldObjectBase"/>.</returns>
        public override int GetHashCode()
        {
            string        delimiter = "||";
            StringBuilder sb        = new StringBuilder();

            sb.Append(this.FieldNumber
                      + delimiter + this.FieldValue
                      + delimiter + this.Enabled
                      + delimiter + this.Lock
                      + delimiter + this.Required);
            return(sb.GetHashCode());
        }
Ejemplo n.º 7
0
        public static void Release(StringBuilder sb)
        {
            if (sb.Capacity <= MAX_BUILDER_SIZE)
            {
                // Assert we are not replacing another string builder. That could happen when Acquire is reentered.
                // User of StringBuilderCache has to make sure that calling method call stacks do not also use StringBuilderCache.
                Debug.Assert(StringBuilderCache.t_cachedInstance == null, "Unexpected replacing of other StringBuilder.");
                StringBuilderCache.t_cachedInstance = sb;
            }
#if DEBUG && !CLR2COMPATIBILITY && !MICROSOFT_BUILD_ENGINE_OM_UNITTESTS
            MSBuildEventSource.Log.ReusableStringBuilderFactoryStop(hash: sb.GetHashCode(), returningCapacity: sb.Capacity, returningLength: sb.Length, type: sb.Capacity <= MAX_BUILDER_SIZE ? "sbc-return" :  "sbc-discard");
#endif
        }
Ejemplo n.º 8
0
        public void ExtensionMethodForReverseAndReturnNewInstanceTest()
        {
            StringBuilder builder = new StringBuilder();

            builder.Append("A");
            builder.Append("B");
            builder.Append("C");

            var sb = builder.ReverseAndReturnNewInstance();

            sb.GetHashCode().ShouldNotBe(builder.GetHashCode());
            sb.ToString().ShouldBe("CBA");
        }
    public static void BuildAssets()
    {
        //VarParse varParse = new VarParse();
        //varParse.UpdateValues(new RoomSettings(), "RoomSettings");
        //Debug.Log(varParse.jsonData.ToJson());

        ExitGames.Client.Photon.Hashtable d = new ExitGames.Client.Photon.Hashtable();
        var s1 = new StringBuilder();
        var s2 = new StringBuilder();
        s1.Append("/");
        s2.Append("/");
        d.Add(s1, null);
        Debug.Log(s1.GetHashCode() == s2.GetHashCode());
    }
Ejemplo n.º 10
0
        /// <summary>
        /// Overrides the <see cref="GetHashCode"/> method for a <see cref="RowObject"/>.
        /// </summary>
        /// <returns>Returns an <see cref="int"/> representing the unique hash code for the <see cref="RowObject"/>.</returns>
        public override int GetHashCode()
        {
            string        delimiter = "||";
            StringBuilder sb        = new StringBuilder();

            sb.Append(this.ParentRowId
                      + delimiter + this.RowAction
                      + delimiter + this.RowId);
            foreach (FieldObject fieldObject in this.Fields)
            {
                sb.Append(delimiter + fieldObject.GetHashCode());
            }
            return(sb.GetHashCode());
        }
    public static void BuildAssets()
    {
        //VarParse varParse = new VarParse();
        //varParse.UpdateValues(new RoomSettings(), "RoomSettings");
        //Debug.Log(varParse.jsonData.ToJson());

        ExitGames.Client.Photon.Hashtable d = new ExitGames.Client.Photon.Hashtable();
        var s1 = new StringBuilder();
        var s2 = new StringBuilder();

        s1.Append("/");
        s2.Append("/");
        d.Add(s1, null);
        Debug.Log(s1.GetHashCode() == s2.GetHashCode());
    }
        /// <summary>
        /// Overrides the <see cref="GetHashCode"/> method for a <see cref="FormObject"/>.
        /// </summary>
        /// <returns>Returns an <see cref="int"/> representing the unique hash code for the <see cref="FormObject"/>.</returns>
        public override int GetHashCode()
        {
            string        delimiter = "||";
            StringBuilder sb        = new StringBuilder();

            sb.Append(this.FormId + delimiter + this.MultipleIteration.ToString(CultureInfo.InvariantCulture));
            sb.Append(this.CurrentRow != null ? delimiter + this.CurrentRow.GetHashCode().ToString(CultureInfo.InvariantCulture) : "");
            if (this.OtherRows != null)
            {
                foreach (RowObject rowObject in this.OtherRows)
                {
                    sb.Append(delimiter + rowObject.GetHashCode());
                }
            }
            return(sb.GetHashCode());
        }
Ejemplo n.º 13
0
        public void Equal_Literal_vs_StringBuilder_Test()
        {
            var value1 = "string";
            var value2 = new StringBuilder("string").ToString();

            #region Compare by value
            Assert.IsTrue(value1.Equals(value2));
            #endregion

            #region Compare by HashCode
            Assert.IsTrue(value1.GetHashCode().Equals(value2.GetHashCode()));
            #endregion

            #region Compare by Reference
            Assert.IsFalse(ReferenceEquals(value1, value2));
            #endregion
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            Clear();
            StringBuilder nombres = new StringBuilder("Manuel Beltran"); //Podemos crear cadenas de texto mutables que si pueden ser modificables

            nombres[0] = 'p';                                            // esto modifica en laposicion 0 del array de la cadena de tecto y la sustutye por el caracter
            nombres.AppendLine();                                        // metodo que genera un salto de linea
            nombres.Append(" Diaz-Meco").Append(" y tengo 20 años");     // sierve para añadir al final de una cadena de texto, mas texto

            nombres.Capacity = 130;                                      // la capacidad de caracteres de texto que suportara
            // y podemos añadir mas texto
            WriteLine(nombres.ToString());
            WriteLine(nombres.GetHashCode());
            WriteLine(nombres.Length); // numero que mide nuestra cadena de texto
            WriteLine(nombres.AppendFormat(" Hobbie: {0}", "informatica"));


            //WriteLine(nombres);
        }
Ejemplo n.º 15
0
        private static void ExamStringBuilder()
        {
            Console.WriteLine("###################### StringBuilder");

            // Capacity는 기존 Capacity 만큼의 문자열이 찰 경우 해당 크기의 두 배로!
            StringBuilder builder = new StringBuilder();

            Console.WriteLine("Capacity={0}", builder.MaxCapacity);
            Console.WriteLine("Capacity={0}, Length={1}", builder.Capacity, builder.Length);

            // Append로 리턴되는 객체또한 자기자신 This
            StringBuilder builderA = builder.Append("ABCDEFGHIJKLMNOP");

            Console.WriteLine("builderA={0}, builder={1}", builder.GetHashCode(), builderA.GetHashCode());
            Console.WriteLine("Capacity={0}, Length={1}", builder.Capacity, builder.Length);
            builder.Append("Q");
            Console.WriteLine("Capacity={0}, Length={1}", builder.Capacity, builder.Length);
            builder.Append(builder.ToString());
            Console.WriteLine("Capacity={0}, Length={1}", builder.Capacity, builder.Length);
            Console.WriteLine("###################### StringBuilder");
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Returns the hash code for this identity. <see cref="EntityBase{T}"/> hash codes
        /// are equal to <see cref="IdentityBase"/> hash codes.
        /// </summary>
        /// <returns>The hash code.</returns>
        public override int GetHashCode()
        {
            DictionaryEntry[] entries = this.GetIdentityEntries();
            if (entries.Length == 0)
            {
                return(base.GetHashCode());
            }
            if (entries.Length == 1)
            {
                return(entries[0].GetHashCode());
            }

            StringBuilder hashstring = new StringBuilder();

            for (int idx = 0; idx < entries.Length; idx++)
            {
                hashstring.Append(entries[idx].GetHashCode().ToString(CultureInfo.InvariantCulture));
            }

            return(hashstring.GetHashCode());
        }
Ejemplo n.º 17
0
            internal static StringBuilder Get(int capacity)
            {
#if DEBUG && ASSERT_BALANCE
                int balance = Interlocked.Increment(ref s_getVsReleaseBalance);
                Debug.Assert(balance == 1, "Unbalanced Get vs Release. Either forgotten Release or used from multiple threads concurrently.");
#endif

                StringBuilder?returned = Interlocked.Exchange(ref s_sharedBuilder, null);

                if (returned == null)
                {
                    // Currently loaned out so return a new one with capacity in given bracket.
                    // If user wants bigger capacity than maximum capacity, respect it.
                    returned = new StringBuilder(SelectBracketedCapacity(capacity));
#if DEBUG
                    MSBuildEventSource.Log.ReusableStringBuilderFactoryStart(hash: returned.GetHashCode(), newCapacity: capacity, oldCapacity: 0, type: "miss");
#endif
                }
                else if (returned.Capacity < capacity)
                {
                    // It's essential we guarantee the capacity because this
                    // may be used as a buffer to a PInvoke call.
                    int newCapacity = SelectBracketedCapacity(capacity);
#if DEBUG
                    MSBuildEventSource.Log.ReusableStringBuilderFactoryStart(hash: returned.GetHashCode(), newCapacity: newCapacity, oldCapacity: returned.Capacity, type: "miss-need-bigger");
#endif
                    // Let the current StringBuilder be collected and create new with bracketed capacity. This way it allocates only char[newCapacity]
                    //   otherwise it would allocate char[new_capacity_of_last_chunk] (in set_Capacity) and char[newCapacity] (in Clear).
                    returned = new StringBuilder(newCapacity);
                }
                else
                {
#if DEBUG
                    MSBuildEventSource.Log.ReusableStringBuilderFactoryStart(hash: returned.GetHashCode(), newCapacity: capacity, oldCapacity: returned.Capacity, type: "hit");
#endif
                }

                return(returned);
            }
Ejemplo n.º 18
0
        public override int GetHashCode()
        {
            var builder = new StringBuilder();

            foreach (var message in _errorsToAdd)
            {
                builder.Append(message.GetHashCode().ToString() + "|");
            }
            foreach (var message in _errorsToRemove)
            {
                builder.Append(message.GetHashCode().ToString() + "|");
            }

            foreach (var message in _warningsToAdd)
            {
                builder.Append(message.GetHashCode().ToString() + "|");
            }
            foreach (var message in _warningsToRemove)
            {
                builder.Append(message.GetHashCode().ToString() + "|");
            }

            foreach (var message in _failedToAdd)
            {
                builder.Append(message.GetHashCode().ToString() + "|");
            }
            foreach (var message in _ignoredToAdd)
            {
                builder.Append(message.GetHashCode().ToString() + "|");
            }

            foreach (var message in _testsToRemove)
            {
                builder.Append(message.GetHashCode().ToString() + "|");
            }
            return(builder.GetHashCode());
        }
Ejemplo n.º 19
0
        public static void SaltHashing()
        {
            string password = "******";

            Guid salt = Guid.NewGuid();

            string PassWithRandonSalt = password + salt;

            byte[] ranPassInBytes = Encoding.UTF8.GetBytes(PassWithRandonSalt);

            HashAlgorithm sha512 = SHA512.Create();

            byte[] PasswordHashed = sha512.ComputeHash(ranPassInBytes);

            StringBuilder PasswordHashedString = new StringBuilder();

            foreach (var b in PasswordHashed)
            {
                PasswordHashedString.Append(b);
            }
            Console.WriteLine("the password hashed is {0}", PasswordHashedString.ToString());
            //to return the original hashcode use GetHashCode()
            Console.WriteLine("the hashcode is {0}", PasswordHashedString.GetHashCode());
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Overrides the <see cref="GetHashCode"/> method for a <see cref="OptionObjectBase"/>.
        /// </summary>
        /// <returns>Returns an <see cref="int"/> representing the unique hash code for the <see cref="OptionObjectBase"/>.</returns>
        public override int GetHashCode()
        {
            string        delimiter = "||";
            StringBuilder sb        = new StringBuilder();

            sb.Append(this.EntityID
                      + delimiter + this.EpisodeNumber.ToString(CultureInfo.InvariantCulture)
                      + delimiter + this.ErrorCode.ToString(CultureInfo.InvariantCulture)
                      + delimiter + this.ErrorMesg
                      + delimiter + this.Facility
                      + delimiter + this.NamespaceName
                      + delimiter + this.OptionId
                      + delimiter + this.OptionStaffId
                      + delimiter + this.OptionUserId
                      + delimiter + this.ParentNamespace
                      + delimiter + this.ServerName
                      + delimiter + this.SessionToken
                      + delimiter + this.SystemCode);
            foreach (FormObject formObject in this.Forms)
            {
                sb.Append(delimiter + formObject.GetHashCode());
            }
            return(sb.GetHashCode());
        }
Ejemplo n.º 21
0
		/// <summary>
		/// Returns the hash code for this identity. <see cref="EntityBase{T}"/> hash codes 
		/// are equal to <see cref="IdentityBase"/> hash codes.
		/// </summary>
		/// <returns>The hash code.</returns>
		public override int GetHashCode()
		{
			DictionaryEntry[] entries = this.GetIdentityEntries();
			if (entries.Length == 0)
				return base.GetHashCode();
			if (entries.Length == 1)
				return entries[0].GetHashCode();

			StringBuilder hashstring = new StringBuilder();
			for (int idx = 0; idx < entries.Length; idx++)
			{
				hashstring.Append(entries[idx].GetHashCode().ToString(CultureInfo.InvariantCulture));
			}

			return hashstring.GetHashCode();
		}
Ejemplo n.º 22
0
 public override int GetHashCode()
 {
     return(_stringBuilder?.GetHashCode() ?? _value.GetHashCode());
 }
Ejemplo n.º 23
0
 /// <summary>
 ///     Gets the hash code for the underlying StringBuilder object
 /// </summary>
 public override int GetHashCode()
 {
     Debug.Assert(_sb != null, "_sb != null");
     return(_sb.GetHashCode());
 }
Ejemplo n.º 24
0
 public override int GetHashCode()
 {
     return(script.GetHashCode());
 }
Ejemplo n.º 25
0
 public override int GetHashCode()
 {
     return(Methods.GetHashCode());
 }
 public override int GetHashCode()
 {
     return(_Builder.GetHashCode());
 }
 public override int GetHashCode()
 {
     return(value.GetHashCode());
 }
Ejemplo n.º 28
0
        public static StringBuilder Acquire(int capacity = 16 /*StringBuilder.DefaultCapacity*/)
        {
            if (capacity <= MAX_BUILDER_SIZE)
            {
                StringBuilder sb = StringBuilderCache.t_cachedInstance;
                StringBuilderCache.t_cachedInstance = null;
                if (sb != null)
                {
                    // Avoid StringBuilder block fragmentation by getting a new StringBuilder
                    // when the requested size is larger than the current capacity
                    if (capacity <= sb.Capacity)
                    {
                        sb.Length = 0; // Equivalent of sb.Clear() that works on .Net 3.5
#if DEBUG && !CLR2COMPATIBILITY && !MICROSOFT_BUILD_ENGINE_OM_UNITTESTS
                        MSBuildEventSource.Log.ReusableStringBuilderFactoryStart(hash: sb.GetHashCode(), newCapacity: capacity, oldCapacity: sb.Capacity, type: "sbc-hit");
#endif
                        return(sb);
                    }
                }
            }

            StringBuilder stringBuilder = new StringBuilder(capacity);
#if DEBUG && !CLR2COMPATIBILITY && !MICROSOFT_BUILD_ENGINE_OM_UNITTESTS
            MSBuildEventSource.Log.ReusableStringBuilderFactoryStart(hash: stringBuilder.GetHashCode(), newCapacity: capacity, oldCapacity: stringBuilder.Capacity, type: "sbc-miss");
#endif
            return(stringBuilder);
        }
Ejemplo n.º 29
0
 public override int GetHashCode() => (_sb != null ? _sb.GetHashCode() : 0);
Ejemplo n.º 30
0
 public MyProfilerBlock(string name)
 {
     Name      = new StringBuilder(name);
     BlockHash = Name.GetHashCode();
     ThreadId  = System.Threading.Thread.CurrentThread.ManagedThreadId;
 }
 /// <returns>A hash code for this instance that is suitable for use in hashing algorithms and data structures </returns>
 public override int GetHashCode()
 {
     return(_reportString.GetHashCode());
 }
Ejemplo n.º 32
0
 public override int GetHashCode()
 {
     return(name.GetHashCode());
 }
Ejemplo n.º 33
0
        public override int GetHashCode()
        {
            var builder = new StringBuilder();
            foreach (var message in _errorsToAdd)
                builder.Append(message.GetHashCode().ToString() + "|");
            foreach (var message in _errorsToRemove)
                builder.Append(message.GetHashCode().ToString() + "|");

            foreach (var message in _warningsToAdd)
                builder.Append(message.GetHashCode().ToString() + "|");
            foreach (var message in _warningsToRemove)
                builder.Append(message.GetHashCode().ToString() + "|");

            foreach (var message in _failedToAdd)
                builder.Append(message.GetHashCode().ToString() + "|");
            foreach (var message in _ignoredToAdd)
                builder.Append(message.GetHashCode().ToString() + "|");

            foreach (var message in _testsToRemove)
                builder.Append(message.GetHashCode().ToString() + "|");
            return builder.GetHashCode();
        }
Ejemplo n.º 34
0
 public MyProfilerBlock(string name)
 {
     Name = new StringBuilder(name);
     BlockHash = Name.GetHashCode();
     ThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
 }