GetEncodingCharLength() private method

private GetEncodingCharLength ( string value, int numChars, int charOffset, Encoding encoding ) : int
value string
numChars int
charOffset int
encoding System.Text.Encoding
return int
 internal string BuildParamList(TdsParser parser, SqlParameterCollection parameters)
 {
     StringBuilder builder = new StringBuilder();
     bool flag = false;
     bool isYukonOrNewer = parser.IsYukonOrNewer;
     int count = 0;
     count = parameters.Count;
     for (int i = 0; i < count; i++)
     {
         SqlParameter p = parameters[i];
         p.Validate(i, System.Data.CommandType.StoredProcedure == this.CommandType);
         if (ShouldSendParameter(p))
         {
             if (flag)
             {
                 builder.Append(',');
             }
             builder.Append(p.ParameterNameFixed);
             MetaType internalMetaType = p.InternalMetaType;
             builder.Append(" ");
             if (internalMetaType.SqlDbType == SqlDbType.Udt)
             {
                 string udtTypeName = p.UdtTypeName;
                 if (ADP.IsEmpty(udtTypeName))
                 {
                     throw SQL.MustSetUdtTypeNameForUdtParams();
                 }
                 builder.Append(this.ParseAndQuoteIdentifier(udtTypeName, true));
             }
             else if (internalMetaType.SqlDbType == SqlDbType.Structured)
             {
                 string typeName = p.TypeName;
                 if (ADP.IsEmpty(typeName))
                 {
                     throw SQL.MustSetTypeNameForParam(internalMetaType.TypeName, p.ParameterNameFixed);
                 }
                 builder.Append(this.ParseAndQuoteIdentifier(typeName, false));
                 builder.Append(" READONLY");
             }
             else
             {
                 internalMetaType = p.ValidateTypeLengths(isYukonOrNewer);
                 builder.Append(internalMetaType.TypeName);
             }
             flag = true;
             if (internalMetaType.SqlDbType == SqlDbType.Decimal)
             {
                 byte actualPrecision = p.GetActualPrecision();
                 byte actualScale = p.GetActualScale();
                 builder.Append('(');
                 if (actualPrecision == 0)
                 {
                     if (this.IsShiloh)
                     {
                         actualPrecision = 0x1d;
                     }
                     else
                     {
                         actualPrecision = 0x1c;
                     }
                 }
                 builder.Append(actualPrecision);
                 builder.Append(',');
                 builder.Append(actualScale);
                 builder.Append(')');
             }
             else if (internalMetaType.IsVarTime)
             {
                 byte num6 = p.GetActualScale();
                 builder.Append('(');
                 builder.Append(num6);
                 builder.Append(')');
             }
             else if (((!internalMetaType.IsFixed && !internalMetaType.IsLong) && ((internalMetaType.SqlDbType != SqlDbType.Timestamp) && (internalMetaType.SqlDbType != SqlDbType.Udt))) && (SqlDbType.Structured != internalMetaType.SqlDbType))
             {
                 int size = p.Size;
                 builder.Append('(');
                 if (internalMetaType.IsAnsiType)
                 {
                     object coercedValue = p.GetCoercedValue();
                     string str = null;
                     if ((coercedValue != null) && (DBNull.Value != coercedValue))
                     {
                         str = coercedValue as string;
                         if (str == null)
                         {
                             SqlString str4 = (coercedValue is SqlString) ? ((SqlString) coercedValue) : SqlString.Null;
                             if (!str4.IsNull)
                             {
                                 str = str4.Value;
                             }
                         }
                     }
                     if (str != null)
                     {
                         int num4 = parser.GetEncodingCharLength(str, p.GetActualSize(), p.Offset, null);
                         if (num4 > size)
                         {
                             size = num4;
                         }
                     }
                 }
                 if (size == 0)
                 {
                     size = internalMetaType.IsSizeInCharacters ? 0xfa0 : 0x1f40;
                 }
                 builder.Append(size);
                 builder.Append(')');
             }
             else if ((internalMetaType.IsPlp && (internalMetaType.SqlDbType != SqlDbType.Xml)) && (internalMetaType.SqlDbType != SqlDbType.Udt))
             {
                 builder.Append("(max) ");
             }
             if (p.Direction != ParameterDirection.Input)
             {
                 builder.Append(" output");
             }
         }
     }
     return builder.ToString();
 }