2011-10-12 142 views
0

我得到一個錯誤,當我嘗試建立:不含定義或擴展方法

不含定義或擴展方法

我有一類這樣的:

[Serializable]  
public class JobFile 
{ 
    private FileInfo mFileInfo; 
    private string mJobNumber = string.Empty; 
    private string mBaseJobNumber = string.Empty; 
    private Guid mDocumentTytpeid = Guid.Empty; 

    public string DocumentTypeDescription 
    { 
     get 
     { 
      string description; 
      DocumentType DocType; 
      DocType = DocumentType.GetDocType(DocumentTypeCode);   
      if (DocType.Code == null)      
       description = "Unknown"; 
      else     
       description = DocType.Description;     
      return description; 
     } 
    } 

    public Guid DocumentTypeID 
    { 
     get 
     {    
      DocumentType DocType; 
      DocType = DocumentType.GetDocType(DocumentTypeCode); 
      if (DocType.Code == null) 
       mDocumentTytpeid = Guid.Empty;     
      else 
       mDocumentTytpeid = DocType.Id; 
      return mDocumentTytpeid; 
     } 
    } 

現在我試圖讓Documenttypeid的價值在我的其他類,像這樣:

foreach (FileInfo fi in files) 
{ 
    JobFile jf = null; 
    jf = new JobFile(ref fi); 
    f.DocumentTypeId = jf.DocumentTypeID; //<-- error is here 
} 

有誰知道什麼可能是錯的,以及如何解決它? 謝謝。

+4

in'f.DocumentTypeId','f'的類型是什麼? –

+2

循環中聲明瞭「f」的位置?它不應該是'fi'嗎? –

+0

請發佈完整的錯誤文本。並且自己格式化你的代碼,這是不可讀的。 – abatishchev

回答

1

問題出在f.DocumentTypeId

假設它也是一個JobFile,它是f.DocumentTypeID(注意ID沒有標識)。 C#區分大小寫。此外,只有一個get屬性訪問器,而不是set


如果f是某種其他類型,請告訴我們代碼。

+0

謝謝,f實際上是另一個班級,對不起,我沒有把那部分放在那裏,我試圖簡短。我將file.cs類(f)中的變量設置爲在那裏執行插入操作。 –

+0

如果'f'的類型是'JobFile',那麼我的答案應該可以解決您的問題。 –

+0

它不是f類型的類型文件(Library.File.File f = new Library.File.File();) –

1

錯誤消息非常清楚什麼是錯的。你試圖使用不存在的屬性,並看到如何錯誤是在這條線存在的:

f.DocumentTypeId = jf.DocumentTypeID; 

它只能是兩兩件事之一:

  1. f做不存在
  2. f.DocumentTypeId不存在。
  3. jf.DocumentTypeID不存在

老實說,我會檢查,以確保f.DocumentTypeId不應該是f.DocumentTypeID。 C#對這樣的事情很挑剔,像這樣的小錯誤會導致你收到的錯誤。

相關問題