Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ';使用静力学';和同名的方法_C#_Static_Using - Fatal编程技术网

C# ';使用静力学';和同名的方法

C# ';使用静力学';和同名的方法,c#,static,using,C#,Static,Using,我有两个静态类“封送器”,它们处理数据类型的反序列化/序列化,第一个是我的库的一部分,它序列化默认类型(如uint),第二个是我的应用程序的一部分,并序列化特定类型 快速示例: // LibMarshaler.cs: public static class LibMarshaler { public static void Write(Archive a, string b) { Write(b.Length); // Works Write(En

我有两个静态类“封送器”,它们处理数据类型的反序列化/序列化,第一个是我的库的一部分,它序列化默认类型(如uint),第二个是我的应用程序的一部分,并序列化特定类型

快速示例:

// LibMarshaler.cs:
public static class LibMarshaler
{
    public static void Write(Archive a, string b)
    {
        Write(b.Length); // Works
        Write(Encoding.UTF8.GetBytes(b)); // Works
    }

    public static void Write(Archive a, int b)
    {
        a.Write(b);
    }

    public static void Write(Archive a, byte[] b)
    {
        a.AppendBytes(b);
    }
}

// AppMarshaler.cs
using static LibMarshaler;

public static class AppMarshaler
{
    public static void Write(Archive a, CustomType1 b)
    {
        Write(a, b.exampleString); // error, can't find the function
        Write(a, b.customType2); // works, is part of the same file
    }

    public static void Write(Archive a, CustomType2 b)
    {
        Write(a, b.exampleString); // error, can't find the function
    }
}
我意识到这是因为AppMarshaler正在定义自己的“写”函数,因此C#编译器会取消其他文件中定义的所有其他函数。但我没有其他选择,因为我所有的代码都是生成的,并且都依赖于这些函数


有没有办法绕过它,为什么会这样?我没有覆盖任何现有函数签名..

LibMarshaler.write
生成的代码应该使用类似于
global::The.Full.Namespace.LibMarshaler.write的东西-它不需要漂亮,但需要防止名称冲突。基本上,
的oposite使用static
。我不使用完全限定名的原因是它是生成的,我不知道它属于哪个封送处理程序。稍后,可能会有多个应用程序封送处理程序,因此它需要具有可伸缩性。