我有一个关于在我的xml架构(xsd)中添加限制的问题.我有一个复杂的类型:
<xsd:complexType name="xxx">
<xsd:attribute/>
.....
</xsd:complexType>
Run Code Online (Sandbox Code Playgroud)
我在这个复杂类型中有很多属性,其中很少有字符串类型.现在我希望将这些字符串类型属性限制为y no.chars,我该如何添加此限制?
谢谢!-Ankush
我试图将标签的内容绑定到类实例的字符串属性,但没有太大成功.
XAML:
<Window x:Class="WPFBindingTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Label Height="28" Margin="12,55,106,0" Name="label1" Background="Bisque"
Content="{Binding Source=MyFoo, Path=W1}" VerticalAlignment="Top" />
<Label Height="28" Margin="12,12,106,0" Name="label2" Background="Bisque"
Content="{Binding Source=MyFoo, Path=W2}" VerticalAlignment="Top" />
<Button Height="23" HorizontalAlignment="Right" Margin="0,0,32,48"
Name="button1" VerticalAlignment="Bottom" Width="89"
Click="button1_Click">
Set Properties
</Button>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
C#:
namespace WPFBindingTest
{
public partial class Window1 : Window
{
public Foo MyFoo;
public Window1()
{
InitializeComponent();
MyFoo = new Foo();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
MyFoo.W1 = "Hello";
MyFoo.W2 = "Dave";
} …
Run Code Online (Sandbox Code Playgroud) 我试图确定派生类的属性值,当它通过基类参数传递给方法时.
例如,下面是完整的代码示例:
class Program
{
static void Main(string[] args)
{
DerivedClass DC = new DerivedClass();
ProcessMessage(DC);
}
private static void ProcessMessage(BaseClass baseClass)
{
Console.WriteLine(GetTargetSystemFromAttribute(baseClass));
Console.ReadLine();
}
private static string GetTargetSystemFromAttribute<T>(T msg)
{
TargetSystemAttribute TSAttribute = (TargetSystemAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(TargetSystemAttribute));
if (TSAttribute == null)
throw new Exception(string.Format("Message type {0} has no TargetSystem attribute and/or the TargetSystemType property was not set.", typeof(T).ToString()));
return TSAttribute.TargetSystemType;
}
}
public class BaseClass
{}
[TargetSystem(TargetSystemType="OPSYS")]
public class DerivedClass : BaseClass
{}
[AttributeUsage(AttributeTargets.Class)]
public sealed class TargetSystemAttribute : Attribute …
Run Code Online (Sandbox Code Playgroud) 我想转换一个for循环,它将迭代器的每次递增增加2,使用TPL进入Parallel For循环.数据不依赖于顺序或以任何方式受约束,但我只想处理源数组的每个其他元素中的数据(在下面的代码中是_Datalist),因此需要增加2.
我的For循环:
for (int i = 1; i < _DataList.Length - 1; i += 2)
{
// Do work for _DataList[i]
}
Run Code Online (Sandbox Code Playgroud)
是否有可能告诉并行循环我想要增加2而不是1?
这是并行循环,但显然我每次迭代只增加1:
Task.Factory.StartNew(() =>
Parallel.For(1, _DataList.Length, i =>
{
// do work for _DataList[i]
})
);
Run Code Online (Sandbox Code Playgroud)
我可以告诉内部循环体忽略i的奇数值,但这看起来很麻烦 - 有没有办法在循环初始化中做某种方式?
可能是微不足道的问题..我想实现我自己的错误处理程序来记录错误并监视正在发生的事情.此时我不想向客户提供自己的错误.我希望它是透明的 - 就像默认的WCF行为一样.我应该如何ProvideFault
实现这一目标?
namespace IDATT.Web.Services
{
using System;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;
public class MyServiceErrorHandler : IErrorHandler
{
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
// ????
}
public bool HandleError(Exception error)
{
return true;
}
}
}
Run Code Online (Sandbox Code Playgroud)