Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8640075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:11:24+00:00 2026-06-12T11:11:24+00:00

Please consider two restrictions – Can’t move MyProperty to interface or abstract class. FooEventHandler

  • 0

Please consider two restrictions –

  1. Can’t move MyProperty to interface or abstract class.
  2. FooEventHandler is a dotnet framework method hence can’t change paramter type.

I have MyProperty defined in several classes.

class A
    {
        public string MyProperty { get; set; }
    }
    class B
    {
        public string MyProperty { get; set; }
    }
    class C
    {
        public string MyProperty { get; set; }
    }

Method FooEventHandler updates this property for all parameters it receives.

public object FooEventHandler(object obj)
    {
        object toReturn = null;
        if (obj.GetType() == typeof(A))
        {
            (obj as A).MyProperty = "updated";
            toReturn = obj;
        }
        else if (obj.GetType() == typeof(B))
        {
            (obj as B).MyProperty = "updated";
            toReturn = obj;
        }
        else if (obj.GetType() == typeof(C))
        {
            (obj as C).MyProperty = "updated";
            toReturn = obj;
        }
        return toReturn;
    }

And FooEventHandler is called repeatedly like this –

static void Main(string[] args)
    {
        Program program = new Program();
        A objA = new A();
        program.FooEventHandler(objA);
        B objB = new B();
        program.FooEventHandler(objB);
        C objC = new C();
        program.FooEventHandler(objC);
    }

Please suggest a way to remove redundant code in Foo, considering above two restrictions in general.

To be more precise, I have encountered this issue while using ParameterInspector in WCF. I am trying to modify propery of all the requests intercepted here and had to write Switch Case based on operationName.

A, B, C, D classes as said above are proxies. So don’t want to modify them at first place. Since updating service Reference will overwrite my iterface changes.

public object BeforeCall(string operationName, object[] inputs){
    // update inputs[0] properties
    }

Thank you for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:11:25+00:00Added an answer on June 12, 2026 at 11:11 am

    You can actually have your classes implement an interface, to make this easier to work with. The key is that the generated service reference classes are partial, meaning you can do this in a separate file, which won’t be overwritten when the code is regenerated:

    namespace ServiceReferenceNamespace {
     public partial class A : IMyProperty { }
     public partial class B : IMyProperty { }
     public partial class C : IMyProperty { }
    }
    

    Where IMyProperty is:

    public interface IMyProperty { string MyProperty { get; set; } }
    

    Then you can change your FooEventHandler method to take an IMyProperty, or take an object and check obj is IMyProperty (or use as, so the check is only done once). This lets you use the property simply, without any reflection or dynamic complexities and the runtime performance impacts of those approaches.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please consider two objects of class Product: class Product < ActiveRecord::Base { :id =>
Consider I have a these two properties: public class Test { [Required(ErrorMessage = Please
Please consider the following two entities: @Entity @Table(name = PROFILE) public class Profile extends
Please consider such scenerio: I have component called TMenuItemSelector which has two published properties:
I have doubt with android backstack , please consider the scenario I have two
please consider this code : 1)public static class MyClass 2){ 3) public static DateTime
Please consider the following code: public class Person ( public string FirstName {get; set;}
Please consider the following java source: package com.stackoverflow; public class CondSpeed { private static
Please consider this simplified example: type TForm43 = class(TForm) drwgrd1: TDrawGrid; procedure drwgrd1DrawCell(Sender: TObject;
Please consider the two following snippets of code: (function f() { var x; try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.