Skip to main content
deleted 82 characters in body
Source Link
Chris Halcrow
  • 401
  • 2
  • 6
  • 15

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, whereso that "ExternalSourceProvider.App" is guaranteed identical across all inheriting children.

How can I achieve what I'm trying to do? Does the 'qualifying it with a type name' give me any hint as to what I need to do?

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, where "ExternalSourceProvider.App" is guaranteed identical across all inheriting children.

How can I achieve what I'm trying to do? Does the 'qualifying it with a type name' give me any hint as to what I need to do?

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?

added 144 characters in body
Source Link
Chris Halcrow
  • 401
  • 2
  • 6
  • 15

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.MobileAppApp cannot be accessed with an instance reference, qualify it with a type name instead.

What does 'qualifying it with a type name' mean, and why is this required? What I'm accessingWhich is abecause C# doesn't allow calling static method ofmethods 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 andof type ExternalSourceProvider, where "ExternalSourceProvider.App" is guaranteed identical across all inheriting children.

How can I need some help to understandachieve what I'm trying to do (and ideally, I'd like to understand why? Does the required pattern is being enforced, so'qualifying it with a type name' give me any idea ofhint as to what I should search up would be awesome. I'm currently reading http://www.damirscorner.com/blog/posts/20140310-DynamicBindingOfStaticAndInstanceMethods.html).need to do?

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.MobileApp cannot be accessed with an instance reference, qualify it with a type name instead.

What does 'qualifying it with a type name' mean, and why is this required? What I'm accessing is a static method of a base class and I need some help to understand what to do (and ideally, I'd like to understand why the required pattern is being enforced, so any idea of what I should search up would be awesome. I'm currently reading http://www.damirscorner.com/blog/posts/20140310-DynamicBindingOfStaticAndInstanceMethods.html).

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, where "ExternalSourceProvider.App" is guaranteed identical across all inheriting children.

How can I achieve what I'm trying to do? Does the 'qualifying it with a type name' give me any hint as to what I need to do?

Source Link
Chris Halcrow
  • 401
  • 2
  • 6
  • 15

C# - how to qualify a static member in object derived through reflection

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.MobileApp cannot be accessed with an instance reference, qualify it with a type name instead.

What does 'qualifying it with a type name' mean, and why is this required? What I'm accessing is a static method of a base class and I need some help to understand what to do (and ideally, I'd like to understand why the required pattern is being enforced, so any idea of what I should search up would be awesome. I'm currently reading http://www.damirscorner.com/blog/posts/20140310-DynamicBindingOfStaticAndInstanceMethods.html).