//stcTmp 是个结构体 public struct stc1
{ public string sTable; public string sColumn;
public stcColumn(int n)
{
sTable = "";
sColumn = "";
}
}
stc1 stcTmp =new stc1(0);
foreach (FieldInfo fiTmp in stcTmp.GetType().GetFields())
{
if (fiTmp != null)
{
fiTmp.SetValue(stcTmp, "aaa");
}
}这句 fiTmp.SetValue(stcTmp, "aaa")无效,请问各位高手哪里错了?
{ public string sTable; public string sColumn;
public stcColumn(int n)
{
sTable = "";
sColumn = "";
}
}
stc1 stcTmp =new stc1(0);
foreach (FieldInfo fiTmp in stcTmp.GetType().GetFields())
{
if (fiTmp != null)
{
fiTmp.SetValue(stcTmp, "aaa");
}
}这句 fiTmp.SetValue(stcTmp, "aaa")无效,请问各位高手哪里错了?
foreach(FieldInfo var in a.GetType().GetFields(BindingFlags.NonPublic)) {
if (var.DeclaringType == typeof(int))
{
var.SetValue(a, i);
}
} private object Set(object o)
{
FieldInfo[] fields =o.GetType().GetFields();
Type t=o.GetType();
if(fields[0].FieldType.ToString()=="System.Int32 ")
{
fields[0].SetValue(o,i);
}
return o;
}
object obj = stcTmp;
foreach (FieldInfo fiTmp in stcTmp.GetType().GetFields())
{
if (fiTmp != null)
{
fiTmp.SetValue(obj, "aaa");
}
}
stcTmp = (stc1)obj;