Why does my C # client that uses library A should have a using statement for library B (which is used by A)

I have:

  • The main class of the program - uses library A
  • Library A - has partial classes that are mixed in methods from library B
  • Library B - a combination of methods and interfaces

So, in Library B, when I include a partial Node class that implements INode (defined in Library B), I suddenly get an error in my main class, where it uses Node from Library A. The error tells me in the Main class I have to have instructions for use in library B.

Any ideas?

EDIT - excluding code

    // *** PROGRAM ***
    class Program
    {
        static void Main(string[] args)
        {
            var context = new Model1Container();
            Node myNode;  // ** WITHOUT A using for Library B I have an error here ***
         }
     }


// ** LIBRARY A
namespace TopologyDAL
{
    public partial class Node
    {
        // Auto generated from EF
    }

    public partial class Node : INode<int>   // to add extension methods from Library B
    {
        public int Key
    }
}

// ** LIBRARY B
namespace ToplogyLibrary
{
    public static class NodeExtns
    {
        public static void FromNodeMixin<T>(this INode<T> node) {
           // XXXX
        }
    }
    public interface INode<T> 
    {
        // Properties
        T Key { get; }

        // Methods
    }

}

EDIT 2 - To clarify whether this was a link or using an error:

, , "Node myNode;" :

1 ".`1" , . ', = 1.0.0.0, Culture = , PublicKeyToken = . U:\ Dropbox\source\ToplogyLibrary\TopologyDAL_ConsoleTest\Program.cs 11 13 DAL_ConsoleTest

VS , Library2 . "" . , .

3 - , , mixin ( B), using B? .

+1
6

, , , A , B, , A, B.

, B-Main.

. A , B, Main B. :

_____________             _____________               _____________
| Main       |references  | Library A  |references    | Library B  |
|           -|------------|->         -|--------------|->          |
|            |            | public     |              | SomeType   |
|            |            |  SomeType  |              |            |
|            |            |            |              |            |
-------------             -------------               -------------

, , B, A. :

  • EDITED , A (Node), B (INode<int>).
  • , A, B .
  • , A, B .

Assembly3 Assembly1, .

_____________             _____________               _____________
| Main       |references  | Library A  |references    | Library B  |
|           -|------------|->         -|--------------|->          |
|            |            | public     |              | SomeType   |
|            |references  |  SomeType  |              |            |
|           -|------------|------------|--------------|->          |
|            |            |            |              |            |
-------------             -------------               -------------
+5

LibraryA , , LibraryB, , using.

+5

Library A mix B, using , A B , , #. , B, A.

+1

, , Node A, . , Node , INode<int> B.

Node B.

0

, B, A B API. Node INode<T>, .

- B . , , , B , , .

, - , , , , A. () B, , A. , - - , ( ), , .

, Library A, :

namespace TopologyDAL
{
    public partial class Node
    {
        // Auto generated from EF
    }

    public partial class Node
    {
        public int Key { ... }

        private class NodeProxy : INode<int>
        {
            private readonly Node _node;

            public NodeProxy(Node node)
            {
                _node = node;
            }

            public int Key { get { return _node.Key; } }
        }

        private readonly NodeProxy _nodeProxy;

        public Node()
        {
            _nodeProxy = new NodeProxy(this);
        }
    }
}

, B, _nodeProxy this.

, , B B A, A , .. , ? , , , , B ?

, " !":) , , - , . -, - A, , , B.

, Node :

public void FromNodeMixin()
{
    _nodeProxy.FromNodeMixin();
}

, B. ( ) , B. , A B; A, - B , , .


, , , . -, - . , , . , DLL, .

, , B, , , B . , , Library A , . B , , B , , DLL .

0

# - , . 2 , .

-1

Source: https://habr.com/ru/post/1747470/


All Articles