首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >CS0103:名称*在当前上下文中不存在

CS0103:名称*在当前上下文中不存在
EN

Stack Overflow用户
提问于 2021-09-02 13:31:04
回答 1查看 861关注 0票数 0

在我只添加了另一个变量和一个getter之前,代码就开始工作了。现在一切都不正常了。解决方案中所有项目的.NET版本是相同的(4.7)。错误截图

我不能再运行这个项目了,因为它没有正确地启动(有个错误)。怎么一回事?这种情况已经发生了好几个月了。我从我的高年级学生那里得到的答案是,这个解决方案是一个巨大的问题,Visual有时会错误地处理它,因此这个错误就是由此产生的灾难。区别在于,这次重新启动Visual /my并没有“解决”它。在清理和重建之后,我试着重新开始,但没有取得任何成果。有人知道该怎么做吗?

代码在我将<%# GetCssClass %>添加到.ascx文件之前工作。在我加了这个之后,一切都变坏了,即使我撤销了加起来,也没有什么是有效的。

.ascx

代码语言:javascript
运行
复制
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="EventICTGenerator.ascx.cs" Inherits="CMSApp.CMSWebParts.MyCompany.DetailPages.Event.EventICTGenerator" %>
<%@ Register Src="~/CMSWebParts/MyCompany/Controls/ICSCalendarControl.ascx" TagPrefix="uc1" TagName="ICSCalendarControl" %>

<uc1:ICSCalendarControl runat="server" ID="ICSCalendarControl" LinkCssClass='event-header__info-actions-save <%# GetCssClass %>' 
      ResourceString="MyCompany.event.SaveTheDate"
      EventName='<%# EventName %>' 
      EventLocation='<%# EventLocation %>' 
      EventAddress='<%# EventAddress %>' 
      EventStartDate='<%# EventStartDate %>' 
      EventEndDate='<%# EventEndDate %>' 
      EventSummary='<%# EventSummary %>' />

<%# Position %>

.ascx.cs

代码语言:javascript
运行
复制
using CMS.DocumentEngine;
using CMS.Helpers;
using CMS.PortalEngine.Web.UI;

using System;
using System.Linq;

namespace CMSApp.CMSWebParts.MyCompany.DetailPages.Event
{
    public partial class EventICTGenerator : CMSAbstractWebPart
    {
        protected string EventName = "";
        protected string EventLocation = "";
        protected string EventAddress = "";
        protected DateTime EventStartDate = DateTime.Now;
        protected DateTime EventEndDate = DateTime.Now;
        protected string EventSummary = "";
        protected int widgetPosition = -1;

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (!StopProcessing)
            {
                SetupControl();
                BindEventData(EventDocumentID);
            }
        }

        private void SetupControl()
        {
            BindEventData(EventDocumentID);
            this.DataBind();
            widgetPosition = Position;
        }

        protected string EventDocumentID
        {
            get
            {
                return ValidationHelper.GetString(GetValue("EventID"), string.Empty);
            }
        }

        protected string EventLink
        {
            get
            {
                return ValidationHelper.GetString(GetValue("Link"), string.Empty);
            }
        }

        protected int Position
        {
            get
            {
                return ValidationHelper.GetInteger(GetValue("Position"), -1);
            }
        }

        protected string GetCssClass
        {
            get
            {
                return Position switch
                {
                    1 => "generic-content_align generic-content_align–left",
                    2 => "generic-content_align generic-content_align–center",
                    3 => "generic-content_align generic-content_align–right",
                    _ => "",
                };
            }
        }

        protected string EventLinkText
        {
            get
            {
                return ValidationHelper.GetString(GetValue("LinkText"), string.Empty);
            }
        }

        private string LinkTextAndUrl()
        {
            return $"{EventLinkText} <{EventLink}>";
        }

        private void BindEventData(string documentID)
        {
            TreeNode item = DocumentHelper.GetDocuments("MyCompany.Event")
                .Columns("EventName, LocationName, LocationAddress, ShortDescription, Date, EndDate")
                .OnCurrentSite()
                .WhereEquals("DocumentID", documentID)
                .FirstOrDefault();

            if (item != null)
            {
                string summary = ValidationHelper.GetString(item.GetValue("ShortDescription"), string.Empty);

                this.EventName = ValidationHelper.GetString(item.GetValue("EventName"), string.Empty);
                this.EventLocation = ValidationHelper.GetString(item.GetValue("LocationName"), string.Empty);
                this.EventAddress = ValidationHelper.GetString(item.GetValue("LocationAddress"), string.Empty);
                this.EventSummary = $"{summary}\n{LinkTextAndUrl()}";
                this.EventStartDate = ValidationHelper.GetDateTime(item.GetValue("Date"), DateTime.Now);
                this.EventEndDate = ValidationHelper.GetDateTime(item.GetValue("EndDate"), DateTime.Now);
            }
        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 2021-09-02 14:52:22

“解决”的办法是改变我的开关箱。我输入它就像

代码语言:javascript
运行
复制
 switch
                {
                    1 => "generic-content_align generic-content_align–left",
                    2 => "generic-content_align generic-content_align–center",
                    3 => "generic-content_align generic-content_align–right",
                    _ => "",
                };

VS告诉我,我的开关箱不好,这就是为什么我一开始就把它改成了那种形式。然后它并没有告诉我它有什么问题,也没有以任何方式指出它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69031279

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档