简体   繁体   English

为什么我的C ++代码看不到这个C#类成员?

[英]Why can't my C++ code see this C# class member?

I have several custom classes in a C# project that I then reference in a C++ project. 我在C#项目中有几个自定义类,然后我在C ++项目中引用它。 The C# code looks something like this C#代码看起来像这样

namespace AllOptions
{
    public class AllOptions {
        public AlgorithmOptions algOptions{ get; set; }
        public DatabaseOptions dataOptions{ get; set; }
    }

    public class AlgorithmOptions {
        List<Algorithm> algorithms { get; set; }

        public void SetDefaults(){
            this.algorithms.Clear();
        }
    }
    public class Algorithm {
        public bool AllowSalt { get; set; }
    }
    public class DatabaseOptions {
        public List<string> databaseSrouces { get; set; }
    }
}

And then from C++ I am trying to access the various parts of the AllOptions but not all of them are coming through. 然后从C ++我试图访问AllOptions的各个部分,但并非所有部分都通过。

//Is declared at the beginning
public: VerifyOptions::VerifyOptions Options;

//Then later on I try to access the database options and algorithm options
this->Options.databaseOptions->databaseSources = someStringList; //works fine

//This cannot find the algorithm list
this->Options.algorithmOptions->algorithms = someAlgorithmList; //does not work

The algorithms says "Class AllOptions::AlgorithmOptions has no member algorithms". 算法说“Class AllOptions :: AlgorithmOptions没有成员算法”。 Why can't the C++ code see this particular C# member? 为什么C ++代码不能看到这个特定的C#成员?

EDIT My question was tagged as a possible duplicate to this Default access modifier in C# question. 编辑我的问题被标记为C#问题中此默认访问修饰符的可能重复。 However I believe these to be different questions that happened to result in the same answer. 但是我认为这些是导致相同答案的不同问题。 If I am wrong in thinking that please tag it again and I will change it. 如果我想错了,请再次标记,我会改变它。

AlgorithmOptions.algorithms is a private member. AlgorithmOptions.algorithms是一个私有成员。 Only the containing class can access its private members. 只有包含类才能访​​问其私有成员。 In contrast, DatabaseOptions.databaseSources is a public member, and you can access it from anywhere. 相比之下, DatabaseOptions.databaseSources是一个公共成员,您可以从任何地方访问它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#代码无法“查看”我的C ++ dll中的方法 - C# code can't “see” the methods in my C++ dll c# - 为什么我的Dictionary类看不到ToArray()方法? - c# - Why can't my Dictionary class see the ToArray() method? 即使目录存在,我的C#代码也无法在C驱动器中看到我的目录。 - My C# code can't see my directory in my C drive…even though the directory exists 为什么在C#项目中看不到某些C ++ DLL(支持CLR)? - Why can't i see some C++ DLL ( support CLR ) in C# project ? 我为什么看不到我的 <example> s和<code>s from Intellisense? using C# and Visual Studio 2017-2019</code> <code>s from Intellisense? using C# and Visual Studio 2017-2019</code> - Why can't I see my <example>s and <code>s from Intellisense? using C# and Visual Studio 2017-2019 为什么我的ListViewItem无法在C#类ListView中进行编辑 - why my ListViewItem can't be edit in c# class ListView 为什么我不能从C#的内部类中引用静态成员? - Why can't I reference a static member from an inner class in C#? 我的不同 function 不工作,我不明白为什么 c# - my Distinct function is not working and i can't see why c# 为什么反射可以在C#中访问类的受保护/私有成员? - Why can reflection access protected/private member of class in C#? 我在 C# 中看不到另一个命名空间的引用类 - I can't see a referenced class of another namespace in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM