Click here to Skip to main content
15,890,043 members
Home / Discussions / C#
   

C#

 
AnswerRe: Need to Connect to DB2 database using C# Pin
PIEBALDconsult11-Jun-08 15:43
mvePIEBALDconsult11-Jun-08 15:43 
QuestionProgramatically Modifying app.config file Pin
#realJSOP11-Jun-08 4:30
mve#realJSOP11-Jun-08 4:30 
AnswerRe: Programatically Modifying app.config file Pin
Judah Gabriel Himango11-Jun-08 4:55
sponsorJudah Gabriel Himango11-Jun-08 4:55 
GeneralRe: Programatically Modifying app.config file Pin
#realJSOP11-Jun-08 5:23
mve#realJSOP11-Jun-08 5:23 
GeneralRe: Programatically Modifying app.config file Pin
Judah Gabriel Himango11-Jun-08 5:30
sponsorJudah Gabriel Himango11-Jun-08 5:30 
AnswerRe: Programatically Modifying app.config file Pin
leppie11-Jun-08 6:02
leppie11-Jun-08 6:02 
GeneralRe: Programatically Modifying app.config file Pin
#realJSOP11-Jun-08 6:42
mve#realJSOP11-Jun-08 6:42 
QuestionReflection Pin
c242311-Jun-08 4:06
c242311-Jun-08 4:06 
Hi,

I have a compiled class library/dll (written in C#) and I need to get a property of an object inside it from another project. Unfortunately, the DLL structure (namespaces and type names) is virtually guarenteed to change AFTER my app has been deployed. So I've been trying to use reflection to get to the object required (having read some settings data like namespaces and type names from a db). At the moment I'm tripping up on the use of System.Reflection.Assembly - it works fine when I reflect on the current project, but when I try to read the DLL I have problems - any help would be appreciated! (Pseudo)Code follows:

public void Main()
{
    Console.WriteLine(Foo("MyClassLibrary.DLL", "Person", "Name"));
}

public string Foo(string NameOfAssembly, string TypeName, string PropertyName)
{
    //Load assembly from DLL(???)
    Assembly assembly = Assembly.Load(NameOfAssembly);

    //Ugly loop to get the type specified by TypeName
    foreach (Type t in a.GetTypes())
    {
        if (string.Equals(TypeName, t.Name))
        {
            //Note: GetType(x, true) <- True specifies that an exception should
            //                          be thrown when type cannot be found
            type = Type.GetType(TypeName, true);
        }
    }

    //Code to query database for object
    object currentObject = GetObject();

    //Use reflection to find property value
    PropertyInfo propinfo = currentObject.GetType().GetProperty(PropertyName);
    return propinfo.GetValue(currentObject, null).ToString();
}

[Note: We are using our own in-house tools for data access, so the above code has some database stuff removed, and for simplicity try-catch blocks are also removed]


Does anybody have any help they can offer on reflecting on a DLL?

Thanks,
Chris


[Update: Corrected a typo]
AnswerRe: Reflection Pin
c242311-Jun-08 4:30
c242311-Jun-08 4:30 
AnswerRe: Reflection Pin
PIEBALDconsult11-Jun-08 15:45
mvePIEBALDconsult11-Jun-08 15:45 
GeneralRe: Reflection Pin
c242311-Jun-08 22:12
c242311-Jun-08 22:12 
QuestionRTS_CONTROL_TOGGLE or Win32 handle to the serial port Pin
aei_totten11-Jun-08 4:04
aei_totten11-Jun-08 4:04 
QuestionChatting in lan Pin
pekhaleyogesh11-Jun-08 4:00
pekhaleyogesh11-Jun-08 4:00 
AnswerRe: Chatting in lan Pin
John Ad11-Jun-08 4:13
John Ad11-Jun-08 4:13 
AnswerCP IGNORE Pin
leckey11-Jun-08 4:41
leckey11-Jun-08 4:41 
QuestionCreating Forms By Type Pin
Dirso11-Jun-08 3:34
Dirso11-Jun-08 3:34 
AnswerRe: Creating Forms By Type Pin
leppie11-Jun-08 3:54
leppie11-Jun-08 3:54 
GeneralRe: Creating Forms By Type Pin
Dirso11-Jun-08 6:12
Dirso11-Jun-08 6:12 
QuestionDumping xml schema from the Type/Graph Pin
Eric Burns11-Jun-08 3:25
Eric Burns11-Jun-08 3:25 
AnswerRe: Dumping xml schema from the Type/Graph Pin
leppie11-Jun-08 3:56
leppie11-Jun-08 3:56 
QuestionDrag and drop between my program and explorer [modified] Pin
Razvan Dimescu11-Jun-08 2:49
Razvan Dimescu11-Jun-08 2:49 
AnswerRe: Drag and drop between my program and explorer Pin
Eslam Afifi11-Jun-08 3:06
Eslam Afifi11-Jun-08 3:06 
GeneralRe: Drag and drop between my program and explorer Pin
Razvan Dimescu11-Jun-08 3:14
Razvan Dimescu11-Jun-08 3:14 
GeneralRe: Drag and drop between my program and explorer Pin
Eslam Afifi11-Jun-08 3:21
Eslam Afifi11-Jun-08 3:21 
GeneralRe: Drag and drop between my program and explorer Pin
Razvan Dimescu11-Jun-08 3:31
Razvan Dimescu11-Jun-08 3:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.