110,536
社区成员
发帖
与我相关
我的任务
分享
Assembly AppPrintTicket = Assembly.LoadFile(CommandLibrary.CommandClass.AppStartPath + "\\Tx.PrintTemplate.dll");
Type printReltype = AppPrintTicket.GetType("Tx.PrintTemplate.Epson.Default.TicketPrint", false, true);
Object printRelObj = Activator.CreateInstance(printReltype);
foreach (PropertyInfo _tmpProp in modelReltype.GetProperties()) //获取属性
{
}
Assembly AppPrintTicket = Assembly.LoadFile(CommandLibrary.CommandClass.AppStartPath + "\\Tx.PrintTemplate.dll");
Type printReltype = AppPrintTicket.GetType("Tx.PrintTemplate.Epson.Default.TicketPrint", false, true);
Object printRelObj = Activator.CreateInstance(printReltype);
FieldInfo fi = printReltype.GetField("bindingSource", BindingFlags.Public | BindingFlags.Instance);
if (fi != null)
{
Type bsType = fi.FieldType;
BindingSource bs = fi.GetValue(printRelObj) as BindingSource;
bs.Add(XXX);
}
public void InvokeDoubleBuffered(Control printReltype)
{
System.Reflection.PropertyInfo propertyInfo = printReltype.GetType().GetProperty("bindingSource", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
propertyInfo.SetValue(this, 你想赋的值, null);
}
[System.AttributeUsage(System.AttributeTargets.Class |
System.AttributeTargets.Struct,
AllowMultiple = true) // multiuse attribute
]
public class Author : System.Attribute
{
string name;
public double version;
public Author(string name)
{
this.name = name;
version = 1.0; // Default value
}
public string GetName()
{
return name;
}
}
[Author("H. Ackerman")]
private class FirstClass
{
// ...
}
// No Author attribute
private class SecondClass
{
// ...
}
[Author("H. Ackerman"), Author("M. Knott", version = 2.0)]
private class ThirdClass
{
// ...
}
class TestAuthorAttribute
{
static void Main()
{
PrintAuthorInfo(typeof(FirstClass));
PrintAuthorInfo(typeof(SecondClass));
PrintAuthorInfo(typeof(ThirdClass));
}
private static void PrintAuthorInfo(System.Type t)
{
System.Console.WriteLine("Author information for {0}", t);
System.Attribute[] attrs = System.Attribute.GetCustomAttributes(t); // reflection
foreach (System.Attribute attr in attrs)
{
if (attr is Author)
{
Author a = (Author)attr;
System.Console.WriteLine(" {0}, version {1:f}", a.GetName(), a.version);
}
}
}
}
Author information for FirstClass
H. Ackerman, version 1.00
Author information for SecondClass
Author information for ThirdClass
H. Ackerman, version 1.00
M. Knott, version 2.00