|
class NameCreationService : System.ComponentModel.Design.Serialization.
INameCreationService
{
// Creation of a unique name for the control
public string CreateName(System.ComponentModel.IContainer container, Type dataType)
{
int i = 0;
string name = dataType.Name;
while (true)
{
i++;
// It is checked if the name is not used
if (container.Components[name + i.ToString()] == null)
break;
}
return name + i.ToString();
}
// Example drawn from the MSDN
// If the name of the control contains a caracter different from miniature, of a masjucule, of a number return false
public bool IsValidName(string name)
{
for (int i = 0; i < name.Length; i++)
{
char ch = name[i];
UnicodeCategory uc = Char.GetUnicodeCategory(ch);
switch (uc)
{
case UnicodeCategory.UppercaseLetter:
case UnicodeCategory.LowercaseLetter:
case UnicodeCategory.DecimalDigitNumber:
break;
default:
return false;
}
}
return true;
}
// Example drawn from the MSDN
// If the name of the control contains a caracter different from miniature, of a masjucule, of a number throw a exception
public bool ValidateName(string name)
{
for (int i = 0; i < name.Length; i++)
{
char ch = name[i];
UnicodeCategory uc = Char.GetUnicodeCategory(ch);
switch (uc)
{
case UnicodeCategory.UppercaseLetter:
case UnicodeCategory.LowercaseLetter:
case UnicodeCategory.DecimalDigitNumber:
break;
default:
throw new Exception("Le nom '" + name + "' n'est pas un identifiant valide.");
}
}
}
} |