编译时出现多个意外错误

时间:2014-09-23 20:47:56

标签: c# visual-studio-2012 linq-to-sql

我的代码中出现了这些奇怪的编译器错误:

} expected

Invalid token 'return' in class, struct, or interface member declaration

Method must have a return type

Identifier expected

; expected

Type or namespace definition, or end-of-file expected

所有这些错误都以GetTicketInfo方法为中心。

这段代码正在编译和工作好几天,现在突然间Visual Studio 2012出现了问题。

我做错了什么?代码如下。

using System;
using System.Linq;

namespace www.classes
{
  public class HelpDeskTicket
  {
    public int TicketId { get; set; }
    public String Title { get; set; }
    public String Description { get; set; }
    public String Category { get; set; }
    public String Requestor { get; set; }
    public String Status { get; set; }
    public DateTime CreatedOn { get; set; }
    public DateTime DueDate { get; set; }
    public long CategoryId { get; set; }
    public long StatusId { get; set; }
    public String TicketType { get; set; }
    public Guid RequestedBy { get; set; }
    public Guid AssignedTo { get; set; }
    public String AssignedToName { get; set; }
    public String ImpactAnalysis { get; set; }
    public String TestingRequirements { get; set; }
    public String ImpactOnSOP { get; set; }
    public String TrainingRequirements { get; set; }
    public String SourceVersion { get; set; }
    public int ReleaseNumber { get; set; }
    public DateTime UATApprovalDate { get; set; }
    public String UATUserName { get; set; }
    public Guid? UATUserID { get; set; }
    public DateTime SecurityApprovalDate { get; set; }
    public Guid? SecurityOfficer { get; set; }
    public String SecurityUserName { get; set; }
    public DateTime PrivacyApprovalDate { get; set; }
    public Guid? PrivacyOffcer { get; set; }
    public String PrivacyUserName { get; set; }
    public DateTime CIOApprovalDate { get; set; }
    public DateTime? ITApprovalDate { get; set; }
    public String ITApproverName { get; set; }
    public Guid? ITApprovalBy { get; set; }
    public Guid? CIO { get; set; }
    public String CIOUserName { get; set; }
    public DateTime ProductionDate { get; set; }

    private static IQueryable<HelpDeskTicket> GetInfo(int ticketId, DbDataContext dc, DateTime _default)
    {
        return from ticket in dc.TicketLists
                       join category in dc.TicketCategories on ticket.CategoryID equals category.TicketCategoryID
                       join status in dc.StatusLists on ticket.StatusID equals status.StatusID
                       where ticket.TicketID == ticketId
                       select new HelpDeskTicket
                       {
                           TicketId = ticket.TicketID,
                           Title = ticket.Title,
                           Description = ticket.Description,
                           Category = category.CategoryName,
                           Requestor = GetRequestor(ticket.RequestedBy.Value, dc),
                           Status = status.Status,
                           CreatedOn = ticket.CreatedOn,
                           DueDate = ticket.DueDate.HasValue ? ticket.DueDate.Value : _default,
                           CategoryId = ticket.CategoryID.Value,
                           StatusId = ticket.StatusID.Value,
                           TicketType = ticket.TicketType,
                           RequestedBy = ticket.RequestedBy.Value,
                           AssignedTo = ticket.AssignedTo.Value,
                           AssignedToName = GetAssignee(ticket.AssignedTo.Value, dc),
                           ImpactAnalysis = ticket.ImpactAnalysis,
                           TestingRequirements = ticket.TestingReq,
                           ImpactOnSOP = ticket.ImpactOnSOP,
                           TrainingRequirements = ticket.TrainingReq,
                           SourceVersion = ticket.SourceVersion,
                           ReleaseNumber = ticket.ReleaseNumber.GetValueOrDefault(0),
                           UATUserID = ticket.UATUserid,
                           UATApprovalDate =
                               ticket.UATApprovalDate.HasValue ? ticket.UATApprovalDate.Value : _default,
                           UATUserName = GetTester(ticket.UATUserid.Value, dc),
                           SecurityOfficer = ticket.SecurityUserid,
                           SecurityUserName = GetSecurityOfficer(ticket.SecurityUserid.Value, dc),
                           SecurityApprovalDate =
                               ticket.SecurityApprovalDate.HasValue
                                   ? ticket.SecurityApprovalDate.Value
                                   : _default,
                           PrivacyOffcer = ticket.PrivacyUserid,
                           PrivacyUserName = GetPrivacyOfficer(ticket.PrivacyUserid.Value, dc),
                           PrivacyApprovalDate =
                               ticket.PrivacyApprovalDate.HasValue
                                   ? ticket.PrivacyApprovalDate.Value
                                   : _default,
                           CIO = ticket.CIOUserid,
                           CIOUserName = GetCIO(ticket.CIOUserid, dc),
                           CIOApprovalDate =
                               ticket.CIOApprovalDate.HasValue ? ticket.CIOApprovalDate.Value : _default,
                           ProductionDate =
                               ticket.ProductionDate.HasValue ? ticket.ProductionDate.Value : _default,
                           ITApproverName = GetITApprovalUser(ticket.ITUserId, dc),
                           ITApprovalDate = ticket.ITApprovalDate,
                           ITApprovalBy = ticket.ITUserId
                       };
    }

    public static HelpDeskTicket GetTicketInfo(int ticketId, DbDataContext dc)
    {
        private DateTime _default = new DateTime(1900, 1, 1);

        return GetInfo(ticketId, dc, _default).SingleOrDefault();
    }
  }
}

2 个答案:

答案 0 :(得分:4)

public static HelpDeskTicket GetTicketInfo(int ticketId, DbDataContext dc)
{
    private DateTime _default = new DateTime(1900, 1, 1);

    return GetInfo(ticketId, dc, _default).SingleOrDefault();
}

我很肯定这个代码几天前没有工作,使用访问修饰符private就像你做的那样不合法,只需删除它。

答案 1 :(得分:2)

虽然这不是StackOverflow倾向于欣赏的问题类型 - 但我们都遇到过愚蠢的错误。这是一个语法问题。

从方法中删除private关键字。

private DateTime _default = new DateTime(1900, 1, 1);

DateTime _default = new DateTime(1900, 1, 1);