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

  • SEARCH
  • Home
  • 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 7621059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:06:07+00:00 2026-05-31T04:06:07+00:00

The objects I am putting together are to allow an object to expose itself

  • 0

The objects I am putting together are to allow an object to expose itself as something that can be transformed by another object of the same type. Think along the lines of merge, but the operations are not generic/straightforward such that you could use reflection to simply get all the properties and perform some predetermined set of operations. I have therefore decided to try and implement it as objects that expose themselves as Transformable and attach to them an object that knows how to perform the transformation (which can be interchanged). The compilable code I have so far is:

public interface ITransformer<TType> where TType : class
{
    void Transform(TType source, TType destination);
}

public interface ITransformable<TType> where TType : class
{
    bool Locked { get; set; }
    ITransformer<TType> Transformer { get; set; }

    void TransformFrom(TType source);
}

public class MyTransformer : ITransformer<MyTransformable>
{
    public void Transform(MyTransformable source, MyTransformable destination)
    {
        // Perform some logic for the transform
    }
}

public class MyTransformable : ITransformable<MyTransformable>
{
    public bool Locked { get; set; }
    public ITransformer<MyTransformable> Transformer { get; set; }

    public string Value1 { get; set; }
    public uint Value2 { get; set; }
    public bool Value3 { get; set; }

    public void TransformFrom(MyTransformable source)
    {
        Transformer.Transform(source, this);
    }
}

As you can see, the type MyTransformable contains some data (Value1 – Value3) as well as a Locked state and the Transformer object will know how to perform the transform for this item (generics ensuring only transformers capable of acting on the MyTransformer type are allowed).

My problem is that I don’t want all new objects of type Transformable to have to repeat the call to

public void TransformFrom(MyTransformable source)
{
    Transformer.Transform(source, this);
}

So was hoping I could change MyTransformable to

public abstract class Transformable<TType> : ITransformable<TType> where TType : class
{
    public bool Locked { get; set; }
    public ITransformer<TType> Transformer { get; set; }

    public void TransformFrom(TType source)
    {
        Transformer.Transform(source, this);  // ERROR! this is type Transformable<TType> not TType
    }
}

public class MyTransformable : Transformable<MyTransformable>
{

}

But of course this won’t compile due to the error I highlight. I feel like I have missed the point somewhere along the line. Could anyone point me in the right direction on this?

  • 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-05-31T04:06:09+00:00Added an answer on May 31, 2026 at 4:06 am

    What you need to do is add a hook for the derived type to expose the final, real TType implementation (or simply this). This is best done through an abstract property.

    public abstract class Transformable<TType> : ITransformable<TType>
    {
        public bool Locked { get; set; }
        public ITransformer<TType> Transformer { get; set; }
    
        protected abstract TType Value { get; }
    
        public void TransformFrom(TType source)
        {
            Transformer.Transform(source, Value); 
        }
    }
    
    public class MyOtherTransformable : Transformable<MyTransformable>
    {
        protected override MyTransformable Value
        {
            get { return this; }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm taking data that is in a List of Record objects and putting their
I am putting together a simple simulated network in java, where i can add
I'm putting together a WCF service that handles a large search (currently 50-60 parameters,
Need help with a problem. Goal I'm putting together an iOS book app that
In putting together a simple Clock application I discovered that Android requires you to
I've been putting together a list of pages that we need to update with
Yacc does not permit objects to be passed around. Because the %union can only
Assume my objects are in perfect working order (i.e. TDD makes me think they
As a personal project, I'm putting together a C# WPF calendar. I'm stuck on
Question How can I animate and form rows together? Explanation One 'for loop' is

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.