如何覆盖子项目中的属性 [英] how to override the properties in child project
问题描述
我正在从事 Windows Phone 应用开发,
I am working on Windows Phone app Development,
我有3个项目
1) 图书馆项目
2) 子项目 1 引用图书馆项目
2) Child Project 1 referencing the library project
3) 子项目 2 引用图书馆项目
3) Child Project 2 referencing the library project
在库项目中,它包含所有 xaml 文件、.cs 文件等...在我的子项目中,它只包含一个 MainPage.xaml 及其 .cs 文件,我将它导航到我的库项目中的页面.
In Library project it contains all xaml files,.cs files etc... In my child project it contain only a MainPage.xaml and its .cs file where I am navigating it to a page in my library project.
但是我的库项目代码中的条件很少,它将根据这些条件工作,例如:
But there are few condition in my library project code and it will work based on those conditions like :
在我的图书馆项目中,一个类可以包含:
In my library project a class can contain:
if(language == "JAVA"){
// alert with text as "Android"
}else{
// alert with text as "Windows"
}
这里的字符串 JAVA 可能在库项目中定义如下:
here the string JAVA might be defined in library project like this:
public String LanguageName(){
return "JAVA";
}
但在我的子项目中,它可以被覆盖,例如:
But in my child project it can be override like:
public override String LanguageName(){
return "C#";
}
因此,当我执行时应该向我显示一个带有 Windows 作为文本的警报,如果它没有在子项目中定义,那么它应该使用默认值作为 Android 进行警报.
So when I execute in should show me a alert with Windows as text , if its not defined in child project then it should alert with default value as Android.
如何实现?
推荐答案
要override
一个方法,基方法必须是virtual
:
To override
a method, the base method must be virtual
:
// in base class
public virtual String LanguageName(){
return "JAVA";
}
// in derived class
public override String LanguageName(){
return "C#";
}
这篇关于如何覆盖子项目中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!