我是接口和抽象类的新手.我想创建几个接口来定义购物车系统对象的核心方法和变量.然后我想创建实现核心功能的抽象类.这个想法是,其他类可以以不同的方式用于不同的项目.
这是我的(简化)界面:
public interface ICart
{
...
List<ICartItem> CartItems { get; set; }
}
public interface ICartItem
{
int ProductId { get; set; }
int Quantity { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是我的抽象Cart类(再次,只显示相关的行)实现ICart:
public abstract class Cart : ICart
{
private List<CartItem> _cartItems = new List<CartItem>();
public List<CartItem> CartItems
{
get
{
return _cartItems;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的CartItem类实现了ICartItem:
public abstract class CartItem : ICartItem
{
...
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译类时,我得到一个错误说:'Cart'没有实现接口成员'CartItems'.'Cart.CartItems'无法实现'ICart.CartItems',因为它没有匹配的返回类型System.Collections.Generic.List <ICartItem>.
我认为这里的想法是接口可以由许多类实现,这些类以不同的方式执行核心功能并添加新方法等.为什么我的接口需要知道实际使用的是什么类,同样长因为该类实际上正确地实现了接口?
我想创建一个简单的图形用户界面,以允许非技术用户创建 XML 文件而无需手动编辑 XML 源。理想情况下,我想要一个拖放界面,但如果失败了,真的什么都没有。XML 文件的内容类似于二叉树的编码流程图,所以也许像 Visio 之类的东西,带有另存为 xml 选项?这是所需的 XML 输出的快速示例:
<?xml version="1.0" encoding="utf-8"?>
<steps>
<step id="1" type="prompt">
<prompt>
Welcome.
</prompt>
<next>1.1</next>
</step>
<step id="1.1" type="question">
<prompt>
Do you have what you need?
</prompt>
<yes>1.2</yes>
<no>1.1.1</no>
</step>
...
</steps>
Run Code Online (Sandbox Code Playgroud)
是否有任何现有的工具可以推荐用于此目的?理想情况下是开源的或具有免费的个人许可证,但我有兴趣了解所有选项。
谢谢,
大卫
我有一些包含缩写的网站内容.我有一个公认的网站缩写列表,以及他们的解释.我想创建一个正则表达式,这将允许我用一些标记替换内容中找到的所有已识别缩写.
例如:
内容:
This is just a little test of the memb to see if it gets picked up. Deb of course should also be caught here.
缩写:
memb = Member; deb = Debut;
结果:
This is just a little test of the [a title="Member"]memb[/a] to see if it gets picked up. [a title="Debut"]Deb[/a] of course should also be caught here.
(这只是简单的示例标记).
谢谢.
编辑:
CraigD的答案几乎就在那里,但也有问题.我只想匹配整个单词.我还想保持每个单词被替换的正确大写,以便deb仍然是deb,并且Deb仍然是原始文本的Deb.例如,这个输入:
This is just a little test of the memb. And another memb, but not amemba. …
我试图在Android中绑定TextView的文本颜色.这是我的(截断的)xaml:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:MvxBind=" TextColor CategoryTextColor(Category)"/>
Run Code Online (Sandbox Code Playgroud)
其中CategoryTextColorValueConverter如下:
public class CategoryTextColorConverter : MvxValueConverter<ShowCategory, Color>
{
protected override Color Convert (ShowCategory value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == ShowCategory.AllShows)
{
return Color.Blue;
}
return Color.Red;
}
}
Run Code Online (Sandbox Code Playgroud)
调用转换器并按预期返回颜色,但文本颜色在TextView上永远不会更改.我有一个类似的背景颜色绑定工作正常.我在这里看到在MvvmCross中我如何做自定义绑定属性,也许我需要创建自定义绑定,但我找不到MvxBaseAndroidTargetBinding
.也许我需要从nuget安装一个单独的包?