본문 바로가기
C#

03# 외부 dll 타입제어(dev express)

by NaHyungMin 2016. 4. 18.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
private static DataTable GetConvertTable()
{            
    DataTable table = new DataTable();
 
    DataColumnCollection cols = table.Columns;
    cols.Add("ClassName"typeof(string));
    cols.Add("ObjectName"typeof(string));
    cols.Add("Value"typeof(string));
    
    return table;        
}         
 
public static DataTable GetClassField(string dllName, string className, Type type)
{            
    DataTable table = GetConvertTable();
 
    try            
    {                
        string fullName = string.Format(@"{0}.Views.{1}", dllName, className);
        System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(string.Format(@".\{0}.dll", dllName));
        System.Type classType = assembly.GetType(fullName);
        //Simple.Framework.UI.Checkup.Views.Request2
        //Simple.Framework.UI.CheckUp.Views.Request2 
        //{Name = "Request2" FullName = "Simple.Framework.UI.CheckUp.Views.Request2"}
        var objClass =  Activator.CreateInstance(classType);
        Type t = objClass.GetType();
        // Instance fields.               
        FieldInfo[] fi = t.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
         
        foreach (FieldInfo f in fi.ToList())
        {                    
            var fieldValue = f.GetValue(objClass);                     
            
            if (fieldValue != null)                    
            {                        
                //LabelControl                        
                if (fieldValue.GetType() == typeof(DevExpress.XtraEditors.LabelControl) && fieldValue.GetType() == type)
                {                            
                    table.TableName = "LabelControl";                           
                    DataRow row = table.NewRow();                            
                    row["ClassName"= fullName;                            
                    row["ObjectName"= ((DevExpress.XtraEditors.LabelControl)fieldValue).Name;                            
                    row["Value"= ((DevExpress.XtraEditors.LabelControl)fieldValue).Text;                             
                    table.Rows.Add(row);                        
                }                        
                //ComboBoxEdit                        
                else if (fieldValue.GetType() == typeof(DevExpress.XtraEditors.ComboBoxEdit) && fieldValue.GetType() == type)
                {                         
                }                        
                //LookUpEdit                        
                else if (fieldValue.GetType() == typeof(DevExpress.XtraEditors.LookUpEdit) && fieldValue.GetType() == type)
                {                        
                }
                 //SimpleGrid
                else if (fieldValue.GetType() == type)
                {
                }                   
             }                
        }            
    }            
    catch (Exception ex)            
    {                 
        //ExceptionMessage.ShowExceptionMessage(ex);            
    }             
 
    return table;
}
cs