A
am_public
Hi,
I have to do a sealed class with some functions that ruturns me a
string with a required length.
I.e.
public class MyClass
{
static Object lockStringFixedLength = new Object();
public static string GetStringFixedLength(
string stringToChange,
int length,
char charToUse,
bool insertAtLeft,
bool cutIfLonger
)
{
lock( lockStringFixedLengthString )
{
string fixedString = "";
if ( stringToChange.Length == length )
return stringToChange;
if ( stringToChange.Length < length )
{
string stringToAdd =
new string( charToUse, length - stringToChange.Length );
if ( insertAtLeft )
{
fixedString = stringToAdd + stringToChange;
}
else
{
fixedString = stringToChange + stringToAdd;
}
}
else
{
fixedString = ( cutIfLonger )
? stringToChange.Substring( 0, length )
: stringToChange;
}
return fixedString;
}
}
I need to add many overloads for default options.
I.e.
public static string GetStringFixedLength(
string stringToChange,
int length,
char charToUse
)
{
return GetStringFixedLength(
stringToChange,
length,
charToUse,
false,
true
);
}
public static string GetStringFixedLength(
string stringToChange,
int length
)
{
return GetStringFixedLength(
stringToChange,
length,
' ',
false,
true
);
}
Should I declare and create a static object for every overload to use
in a lock block, or can I do something else? I need many overloads
(more than 20, and I need to write many other functions with a lot of
overloads in the same class).
Some tips?
Thanks a lot.
I have to do a sealed class with some functions that ruturns me a
string with a required length.
I.e.
public class MyClass
{
static Object lockStringFixedLength = new Object();
public static string GetStringFixedLength(
string stringToChange,
int length,
char charToUse,
bool insertAtLeft,
bool cutIfLonger
)
{
lock( lockStringFixedLengthString )
{
string fixedString = "";
if ( stringToChange.Length == length )
return stringToChange;
if ( stringToChange.Length < length )
{
string stringToAdd =
new string( charToUse, length - stringToChange.Length );
if ( insertAtLeft )
{
fixedString = stringToAdd + stringToChange;
}
else
{
fixedString = stringToChange + stringToAdd;
}
}
else
{
fixedString = ( cutIfLonger )
? stringToChange.Substring( 0, length )
: stringToChange;
}
return fixedString;
}
}
I need to add many overloads for default options.
I.e.
public static string GetStringFixedLength(
string stringToChange,
int length,
char charToUse
)
{
return GetStringFixedLength(
stringToChange,
length,
charToUse,
false,
true
);
}
public static string GetStringFixedLength(
string stringToChange,
int length
)
{
return GetStringFixedLength(
stringToChange,
length,
' ',
false,
true
);
}
Should I declare and create a static object for every overload to use
in a lock block, or can I do something else? I need many overloads
(more than 20, and I need to write many other functions with a lot of
overloads in the same class).
Some tips?
Thanks a lot.