[Microsoft.VisualBasic.VBFixedString(6)]
public string zip;下面怎么用才能 得到那个6的数值再使如果超过6位的数字进行截断呢
欲使该特性起作用。于是自己
public static void setstring(member m)
{
Type ctype = m.GetType();
FieldInfo[] f = ctype.GetFields();
foreach (FieldInfo fInfo in f)
{
foreach (Attribute at in Attribute.GetCustomAttributes(fInfo))
{
if (at.TypeId.ToString()== "Microsoft.VisualBasic.VBFixedStringAttribute")
{
//如何在这儿得到那个6的数值再使如果超过6位的数字进行截断呢
}
}
}
public string zip;下面怎么用才能 得到那个6的数值再使如果超过6位的数字进行截断呢
欲使该特性起作用。于是自己
public static void setstring(member m)
{
Type ctype = m.GetType();
FieldInfo[] f = ctype.GetFields();
foreach (FieldInfo fInfo in f)
{
foreach (Attribute at in Attribute.GetCustomAttributes(fInfo))
{
if (at.TypeId.ToString()== "Microsoft.VisualBasic.VBFixedStringAttribute")
{
//如何在这儿得到那个6的数值再使如果超过6位的数字进行截断呢
}
}
}
public static void setstring(member m)
{
Type ctype = m.GetType();
FieldInfo[] f = ctype.GetFields();
foreach (FieldInfo fInfo in f)
{
// Console.WriteLine("{0}___{1}", fInfo.Name, fInfo.ToString());
foreach (Attribute at in Attribute.GetCustomAttributes(fInfo))
{
// Console.WriteLine("{0}___{1}", at.TypeId.ToString(), at.ToString());
if (at.TypeId.ToString() == "Microsoft.VisualBasic.VBFixedStringAttribute")
{
if(at is Microsoft.VisualBasic.VBFixedStringAttribute)
{
//System.Console.WriteLine("{0}",((Microsoft.VisualBasic.VBFixedStringAttribute)at).Length);
int i=((Microsoft.VisualBasic.VBFixedStringAttribute)at).Length;
m.zip =m.zip.Substring(0, i);
}
}
}
} }
调试通过