服务器端属性在 Silverlight 客户端中不可用
Server side attribute not available in Silverlight client
我有一个自定义属性:
[System.AttributeUsage(System.AttributeTargets.Property)]
public class MyCustomAttribute : System.Attribute
{
}
它在名为 MyCustomAttribute.shared.cs
的文件中声明,这使得 class 在客户端可见,因为它出现在客户端的 auto-complete/InteliSense 中。
我已将它添加到我的 class 上的 属性,这是从数据库返回并通过 WCF RIAServices 传递给 Silverlight 客户端的 Entity
:
public partial class MyClass
{
[Required(AllowEmptyStrings=true)]
[Display(ResourceType=typeof(ResourceFile), Name="ResourceName")]
[MyCustom]
public string MyProperty { get; set; }
}
但是,当我尝试查看 属性 是否附加了属性时,它不在列表中:
PropertyInfo prop = GetProperty(myType, "MyProperty");
object[] attributes = prop.GetCustomAttributes(false);
foreach (object attribute in attributes)
{
if (attribute is MyCustomAttribute)
{
// Do my stuff here
}
}
None 返回的属性是 MyCustomAttribute
.
我检查了客户端生成的代码,属性 看起来像这样:
/// <summary>
/// Gets or sets the 'BarcodeNumber' value.
/// </summary>
[ConcurrencyCheck()]
[DataMember()]
[Display(Name="ResourceName", ResourceType=typeof(ResourceFile))]
[Required(AllowEmptyStrings=true)]
[RoundtripOriginal()]
public string MyProperty
{
....
}
所以,显然我的属性没有被复制到客户端。
我错过了什么?
我缺少的是我需要编写一个自定义代码生成器来扩展默认代码生成器,以便它可以识别我的新属性。
该过程记录在网络上的各个地方:
.NET - WCF RIA Services code generatie naar je hand zetten(文章为英文)
T4 Code Generator for WCF RIA Services
但是,我们认为仅在一个属性上实现一个属性会有些矫枉过正 属性,因此使用了不同的方法(基于业务逻辑)来实现我们需要的功能。
我有一个自定义属性:
[System.AttributeUsage(System.AttributeTargets.Property)]
public class MyCustomAttribute : System.Attribute
{
}
它在名为 MyCustomAttribute.shared.cs
的文件中声明,这使得 class 在客户端可见,因为它出现在客户端的 auto-complete/InteliSense 中。
我已将它添加到我的 class 上的 属性,这是从数据库返回并通过 WCF RIAServices 传递给 Silverlight 客户端的 Entity
:
public partial class MyClass
{
[Required(AllowEmptyStrings=true)]
[Display(ResourceType=typeof(ResourceFile), Name="ResourceName")]
[MyCustom]
public string MyProperty { get; set; }
}
但是,当我尝试查看 属性 是否附加了属性时,它不在列表中:
PropertyInfo prop = GetProperty(myType, "MyProperty");
object[] attributes = prop.GetCustomAttributes(false);
foreach (object attribute in attributes)
{
if (attribute is MyCustomAttribute)
{
// Do my stuff here
}
}
None 返回的属性是 MyCustomAttribute
.
我检查了客户端生成的代码,属性 看起来像这样:
/// <summary>
/// Gets or sets the 'BarcodeNumber' value.
/// </summary>
[ConcurrencyCheck()]
[DataMember()]
[Display(Name="ResourceName", ResourceType=typeof(ResourceFile))]
[Required(AllowEmptyStrings=true)]
[RoundtripOriginal()]
public string MyProperty
{
....
}
所以,显然我的属性没有被复制到客户端。
我错过了什么?
我缺少的是我需要编写一个自定义代码生成器来扩展默认代码生成器,以便它可以识别我的新属性。
该过程记录在网络上的各个地方:
.NET - WCF RIA Services code generatie naar je hand zetten(文章为英文)
T4 Code Generator for WCF RIA Services
但是,我们认为仅在一个属性上实现一个属性会有些矫枉过正 属性,因此使用了不同的方法(基于业务逻辑)来实现我们需要的功能。