English 中文(简体)
辅助性帮助 鲁ting、编纂错误
原标题:Attribute help with Routing, compiler error

我建立了称为<代码>的习俗属性。

[AttributeUsage(AttributeTargets.Property)]
public class RouteAttribute : Attribute
{
    public string Url { get; set; }
    public bool CheckPhysicalUrlAccess { get; set; }
    public RouteValueDictionary Defaults { get; set; }
    public RouteValueDictionary Constraints { get; set; }
    public RouteValueDictionary DataTokens { get; set; }
}

用于在我的助手班上添加行道,其中包括我的现场的导游名单,这样我就能够方便地管理我的工地。

Having a problem with adding a default though, getting compiler error:

[Route("~/MyPage/Home.aspx", new RouteValueDictionary { { "query", "value" } })]
public string HomePage
{
  get { return "Home" }
}

To avoid confusion, the value is set to the routeurl, physical url is from attribute, reason for this is, I am converting an existing site, and rather than changing links everywhere, once I m done with page, I go to my class and change the physical url to new page

犯错误:

属性论点必须经常表达、表达类型或阵列的形成,表明属性参数类型

最佳回答

特性构造者的论点价值储存在元数据中。 这严重限制了你可以说明的内容。 单纯的价值类型、类型和这些数值的简单一层。 不允许制定法典,这是汇编者所抱怨的,new的操作者要求制定守则。

在属地建筑商的身体上,你可以做些什么是没有限制的,该法典后来在反省法检查属性时生效。 提出类似建议:

public class RouteAttribute : Attribute
{
    public RouteAttribute(string url, string query, string value) {
       this.url = url;
       this.dunno = new RouteValueDictionary(query, value);
    }
    // etc..
}
...
[Route("~/MyPage/Home.aspx", "query", "value")]
public string HomePage
{
  get { return "Home" }
}

这显然需要工作,我不知道字典的含义。 仔细看它有副作用或需要资源,你不知道在子体建成时的运行状态。

问题回答

An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

错误准确告诉你问题是什么。

页: 1

new RouteValueDictionary { { "query", "value" } }

这不是一种固定的表达方式,而不是一种表达方式,而不是一种阵列的表达方式,这是不合法的。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签