G
GiJeet
Someone please help me. I am trying to create a generic validation
method that simply checks to ensure the type has a value.
Here is the method that calls the validation method:
public void CheckParameterTest(string someString,
List<SqlParameter> sqlParams, List<Customers> customers) {
ValidateParams(sqlParams);
}
Here is the generic validation method.
I just want to check that the List<whatever>.Count property is not
zero.
I can't seem to get the count of the list. Please help
private void ValidateParams<T>(T param) {
Type type = param.GetType();
if (type.IsGenericType && type.GetGenericTypeDefinition() ==
typeof(List<>)) {
Type[] typeParameters = type.GetGenericArguments();
//typeParameters.Length always returns 1 even if the list.Count is
zero!
// I can get the type in the list but still can't get the count of
the list!
Type itemType = type.GetGenericArguments()[0];
}
//string check will go here
}
Thanks.
method that simply checks to ensure the type has a value.
Here is the method that calls the validation method:
public void CheckParameterTest(string someString,
List<SqlParameter> sqlParams, List<Customers> customers) {
ValidateParams(sqlParams);
}
Here is the generic validation method.
I just want to check that the List<whatever>.Count property is not
zero.
I can't seem to get the count of the list. Please help
private void ValidateParams<T>(T param) {
Type type = param.GetType();
if (type.IsGenericType && type.GetGenericTypeDefinition() ==
typeof(List<>)) {
Type[] typeParameters = type.GetGenericArguments();
//typeParameters.Length always returns 1 even if the list.Count is
zero!
// I can get the type in the list but still can't get the count of
the list!
Type itemType = type.GetGenericArguments()[0];
}
//string check will go here
}
Thanks.