dimanche 29 mai 2016

How to assign a value to a static field dynamically create objects?

I want to create an object using reflection class PropertyCondition(in assembly UIAutomationClient.dll).In order to obtain the desired class constructor , I use the following code:

        var assembly = AppDomain.CurrentDomain.GetAssemblies().First(x => x.FullName.Contains("AutomationClient"));

        var propertyConditionType = assembly.DefinedTypes.First(x => x.Name == "PropertyCondition");
        var automationElementType = assembly.DefinedTypes.First(x => x.Name == "AutomationElement");

        var automationIdPropertyType = automationElementType.GetField("AutomationIdProperty").FieldType;
        var constructor = propertyConditionType.GetConstructor(new Type[] { automationIdPropertyType, typeof(object) });

But how do I pass in constructor AutomationElement.AutomationIdProperty ?

Thank you.





Aucun commentaire:

Enregistrer un commentaire