namespace WDBuyNET.DMSFrame.Utils
{
public static class TypeExtentions
{
public static bool IsPrimitive(
this Type t)
{
bool result;
if (t.IsGenericType)
{
result = (TypeExtentions.IsNullableType(t) &&
TypeExtentions.IsPrimitive(Nullable.GetUnderlyingType(t)));
}
else
{
bool arg_14F_0;
if (!(t ==
typeof(
string)) && !(t ==
typeof(
short)) && !(t ==
typeof(
ushort)) && !(t ==
typeof(
int)) && !(t ==
typeof(
uint)) && !(t ==
typeof(
long)) && !(t ==
typeof(
ulong)) && !(t ==
typeof(
float)) && !(t ==
typeof(
double)) && !(t ==
typeof(
decimal)) && !(t ==
typeof(
char)) && !(t ==
typeof(
byte)) && !(t ==
typeof(
bool)) && !(t ==
typeof(DateTime)))
{
arg_14F_0 = (t ==
typeof(Guid));
}
else
{
arg_14F_0 =
true;
}
result =
arg_14F_0;
}
return result;
}
public static bool IsStringType(
this Type type)
{
bool arg_80_0;
if (!(type ==
typeof(
string)) && !(type ==
typeof(
bool)) && !(type ==
typeof(DateTime)) && !(type ==
typeof(Guid)) && !(type ==
typeof(
bool?)) && !(type ==
typeof(DateTime?
)))
{
arg_80_0 = (type ==
typeof(Guid?
));
}
else
{
arg_80_0 =
true;
}
return arg_80_0;
}
public static bool IsBooleanType(
this Type type)
{
return TypeExtentions.GetUnderlyingType(type) ==
typeof(
bool);
}
public static bool AllowsNullValue(
this Type type)
{
return !type.IsValueType ||
TypeExtentions.IsNullableType(type);
}
public static bool IsNullableType(
this Type type)
{
return type.IsGenericType && type.GetGenericTypeDefinition() ==
typeof(Nullable);
}
public static Type GetUnderlyingType(
this Type type)
{
return TypeExtentions.IsNullableType(type) ?
Nullable.GetUnderlyingType(type) : type;
}
public static string Join(
this string[] array,
char splitChar)
{
StringBuilder stringBuilder =
new StringBuilder();
for (
int i =
0; i < array.Length; i++
)
{
stringBuilder.Append(array[i]);
stringBuilder.Append(splitChar);
}
return stringBuilder.ToString().TrimEnd(
new char[]
{
splitChar
});
}
public static object DefaultValue(
this Type type)
{
return type.IsValueType ? Activator.CreateInstance(type) :
null;
}
public static string MD5(
this string text)
{
byte[] bytes =
Encoding.Default.GetBytes(text);
MD5CryptoServiceProvider mD5CryptoServiceProvider =
new MD5CryptoServiceProvider();
byte[] array =
mD5CryptoServiceProvider.ComputeHash(bytes);
string text2 =
"";
byte[] array2 =
array;
for (
int i =
0; i < array2.Length; i++
)
{
byte b =
array2[i];
text2 = ((b >=
16) ? (text2 + b.ToString(
"X")) : (text2 +
"0" + b.ToString(
"X")));
}
return text2.ToLower();
}
}
}
转载于:https://www.cnblogs.com/hongjiumu/archive/2012/09/15/2686622.html