I'm trying to reference a member of an object of type 'ExternalSourceProvider' that's been instantiated through reflection like this:
Type type = GetProviderType(vendor);
ConstructorInfo constructorInfo = type.GetConstructor(new Type[] { typeof(NameValueCollection) });
ExternalSourceProvider vendorSourceProvider = (ExternalSourceProvider)constructorInfo.Invoke(new Object[] { requestData });
I now want to set the value for a static member of the newly instantiated object something like this:
(ExternalSourceProvider)vendorSourceProvider.App = this.App;
I get the error:
Member ExternalSourceProvider.App cannot be accessed with an instance reference, qualify it with a type name instead.
Which is because C# doesn't allow calling static methods with an instance reference
I'm trying to create a pattern where I call an "ExternalSourceProvider.App" member across all children that inherit the base class of type ExternalSourceProvider, so that "ExternalSourceProvider.App" is guaranteed identical across all inheriting children.
How can I achieve what I'm trying to do?
ExternalSourceProvider
in your code at compile time, you don't need reflection to get toExternalSourceProvider.App
; you'd only need reflection if you were accessing a static member of a type not known at compile time..
operator has higher precedence than the cast operator. So, I suspect the cast isn't doing what you want.