111,094
社区成员




char aa = '4';
int ss = Convert.ToInt32(aa);
TestIntEnum en = (TestIntEnum)ss;
string cc = en.ToString();
MessageBox.Show(cc);
public enum TestIntEnum
{
red = '1',
green = '2',
gray = '3',
black = '4'
}
Type memberType = propertyInfo.PropertyType;
Type nullUnderlyingType = Nullable.GetUnderlyingType(memberType);
Type baseType = nullUnderlyingType != null ? nullUnderlyingType : memberType;
MethodInfo convertMethod = typeof(Convert).GetMethod("ToInt32", new Type[] { typeof(object) });
il.Emit(OpCodes.Call, convertMethod);
il.Emit(OpCodes.Box, baseType);
var local = il.DeclareLocal(typeof(int));//创建一个Int局部变量
var local2 = il.DeclareLocal(baseType);//创建一个枚举局部变量
il.Emit(OpCodes.Call, typeof(Convert).GetMethod("ToInt32", new Type[] { typeof(object) }));
il.Emit(OpCodes.Stloc, local);
il.Emit(OpCodes.Ldloc, local);
il.Emit(OpCodes.Box, baseType);
il.Emit(OpCodes.Stloc, local2);
il.Emit(OpCodes.Ldloc, local2);
public enum TestIntEnum
{
red = 1,
green = 2,
gray = 3,
black = 4
}
private class BuilderKey
{
private readonly List<string> _dataRecordNames;
private readonly Type _destinationType;
public BuilderKey(Type destinationType, IDataRecord record)
{
_destinationType = destinationType;
_dataRecordNames = new List<string>(record.FieldCount);
for (int i = 0; i < record.FieldCount; i++)
{
_dataRecordNames.Add(record.GetName(i));
}
}
public override int GetHashCode()
{
int hash = _destinationType.GetHashCode();
foreach (var name in _dataRecordNames)
{
hash = hash * 37 + name.GetHashCode();
}
return hash;
}
public override bool Equals(object obj)
{
var builderKey = obj as BuilderKey;
if (builderKey == null)
return false;
if (this._dataRecordNames.Count != builderKey._dataRecordNames.Count)
return false;
for (int i = 0; i < _dataRecordNames.Count; i++)
{
if (this._dataRecordNames[i] != builderKey._dataRecordNames[i])
return false;
}
return true;
}
}
}