我在c#上课
public class CompositeResource : Control
{
[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
public ResourceCollection Resources { get { return _resources; } }
}
public class Resource
{
[Bindable(true), DefaultValue(""), Editor("System.Web.UI.Design.UrlEditor, System.Design, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor)), Description("Specifies the URL of a resource to reference in the CompositeControl. The URL may be relative, root relative or absolute."), UrlProperty]
public String Url { get; set; }
[Bindable(true), DefaultValue(""), Description("Specifies the name of a resource to be used as a reference in the CompositeControl. The ReferenceName is typically used in conjunction with the Sprite control.")]
public String ReferenceName { get; set; }
}
public class ResourceCollection : List<Resource>
{
}
Run Code Online (Sandbox Code Playgroud)
我只需要添加多个资源
CompositeResource cr = new CompositeResource();
cr.Type = Xpedite.Resources.ResourceType.Css;
cr.ReferenceName = "hello";
cr.Resources.Add({new Resource().Url="\style\p1.css",new Resource().Url="\style\p2.css" });
Run Code Online (Sandbox Code Playgroud)
但是当我想要添加多个资源并且每个资源实例都具有类似url的属性时,最后一行给出了错误.我想我错了,但无法捕捉到哪里有问题.
我认为你的代码应该是这样的:
cr.Resources.Add(new Resource(){ Url= @"\style\p1.css" });
cr.Resources.Add(new Resource(){ Url= @"\style\p2.css" });
Run Code Online (Sandbox Code Playgroud)
您当前的代码不是有效的C#代码.
你的语法错了
cr.Resources.Add({new Resource().Url="\style\p1.css",new Resource().Url="\style\p2.css" });
Run Code Online (Sandbox Code Playgroud)
应该
cr.Resources.Add(new Resource() { Url = @"\style\p1.css" });
cr.Resources.Add(new Resource() { Url = @"\style\p2.css" });
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
127 次 |
| 最近记录: |