S
S
Space Purr2020-01-31 10:39:02
css
Space Purr, 2020-01-31 10:39:02

How to use the same code with different libraries?

Hello.

I'm using a model library which uses two other libraries to deal with the context of a model depending on its type.
Let it be Type1 and Type2 .

The principle of operation for both libraries is completely the same, the classes are identical, only the paths to these classes differ.
For example, for the first Type1.Resource and for the second Type2.Resource .

To work with the model, I created two classes LinksMasterType1 and LinksMasterType2 , with completely identical code, but with a different set of plug-in libraries.

For the first:
using Type1.Resource;
For the second, respectively, Type2.Resource.

The classes have one common interface, ILinksMaster .

Further, depending on the model type, I initialize the required class and work in the program through it.

ILinksMaster linksMaster = null;
switch(type)
     case(type1)
          linksMaster = new LinksMasterType1();
          break;
     case(type2)
          linksMaster = new LinksMasterType2();
          break;


And everything works, but if something has changed, then I have to make changes to both classes.

Is it possible to somehow either dynamically link libraries, or use any other way that will allow me to keep only one LinksMaster class, but use different types of variables depending on the conditions.

Thank you.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
F
forspamonly2, 2019-05-09
@mikhail096

Maxim Lensky , it’s quite possible to make it with the addition of blocks, and divkas, and so that it stretches.

R
RAX7, 2019-05-09
@RAX7

Another option

P
profesor08, 2019-05-10
@profesor08

Three columns and a background below them. The size of the background depends on the width of the side, just like the columns. Since their size changes in the same way, it will be enough to move the background. And then the browser itself will do everything.
PS Don't forget to tear off the designer's legs. The task is doable, both in css and js, but I doubt that the designer is competent in this matter. And in general, it’s better not to generate such crap in fantasies, it looks so-so, it makes no sense.

R
Roman, 2020-01-31
@SpacePurr

The interface is a good idea. But for this you need to think it over well. There is another way to use reflection and dynamic connection of assemblies, but this is resource-intensive.

F
freeExec, 2020-01-31
@freeExec

Generic classes

class Link<T>
        {
            public string WhatClass()
            {
                if (typeof(T) == typeof(int))
                    return "Number";
                else
                    if (typeof(T) == typeof(string))
                    return "Text";

                return "X3";
            }
        }

        static void Main(string[] args)
        {
            var link = new Link<string>();
            var cl = link.WhatClass();
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question