0
누구든지이 부분을보고 내가 잘못하고있는 것을 말해 줄 수 있습니까? GetEnumerator 메서드를 구현하는 데 문제가 있습니다. IDE에서 모든 메서드를 만들 수있는 방법을 알아 냈으므로이 메서드를 재정의하는 방법을 배울 수 있습니다. 누구든지 ProductCollection 클래스를 완성 할 수 있도록 도와 주므로 더 잘 이해할 수 있습니다.IDictionary <int, MyClass> 사용자 지정 컬렉션
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// Product
/// </summary>
[Serializable]
public class Product
{
//0 _ItemNumber = null;
//1 _Title = null;
//2 _Author = null;
//3 _ISBN = null;
//4 _ItemMessage = null;
//5 _ISBNEAN = null;
//6 _SystemName = null;
//7 _ItemCategory = null;
//8 _AccessService = null;
//9 _AlternateItem = null;
//10 _FullTitle = null;
//11 _SalesAnalysisCode = null;
//12 _SACSummaryCode = null;
//13 _OwningOrganization = null;
//14 _ProductManager = null;
//15 _ProductFormat = null;
//16 _DefaultWarehouse = null;
//17 _ItemStatusCode = null;
//18 _AccessType = null;
//19 _SubstitutionReason = null;
//20 _Saleable = null;
//21 _OKToBackOrder = null;
//22 _Taxable = null;
//23 _ExcludeShipping = null;
//24 _Commissionable = null;
//25 _Package = null;
//26 _Royalty = null;
//27 _PrintOnDemand = null;
//28 _AllowDescriptionOverride = null;
private string[] _Product = new string[29];
/// <summary>
/// Advantage Product Object
/// </summary>
public Product()
{
}
public string Title
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string Author
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string ItemNumber
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string ISBN
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string ItemMessage
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string ISBNEAN
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string AccessService
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string SystemName
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string ItemCategory
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string AlternateItem
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string FullTitle
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string SalesAnalysisCode
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string SACSummaryCode
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string OwningOrganization
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string ProductManager
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string ProductFormat
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string DefaultWarehouse
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string ItemStatusCode
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string AccessType
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string SubstitutionReason
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string Saleable
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string OKToBackOrder
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string Taxable
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string ExcludeShipping
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string Commissionable
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string Package
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string Royalty
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string PrintOnDemand
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string AllowDescriptionOverride
{
get
{
return _Product[0];
}
set
{
_Product[0] = value;
}
}
public string[] ProductArray
{
get
{
return _Product;
}
set
{
_Product = value;
}
}
}
/// <summary>
///
/// </summary>
public class ProductCollection : IDictionary<int, Product>
{
private Dictionary<int, Product> dictionaryProduct;
public ProductCollection(int numberOfItem)
{
dictionaryProduct = new Dictionary<int, Product>(numberOfItem);
}
void IDictionary<int, Product>.Add(int productKey, Product productValue)
{
dictionaryProduct.Add(productKey, productValue);
}
bool IDictionary<int, Product>.ContainsKey(int productKey)
{
return dictionaryProduct.ContainsKey(productKey);
}
ICollection<int> IDictionary<int, Product>.Keys
{
get
{
return dictionaryProduct.Keys;
}
}
bool IDictionary<int, Product>.Remove(int productKey)
{
return (dictionaryProduct.Remove(productKey));
}
bool IDictionary<int, Product>.TryGetValue(int productKey, out Product productValue)
{
return (dictionaryProduct.TryGetValue(productKey, out productValue));
}
ICollection<Product> IDictionary<int, Product>.Values
{
get
{
return dictionaryProduct.Values;
}
}
Product IDictionary<int, Product>.this[int productKey]
{
get
{
return dictionaryProduct[productKey];
}
set
{
dictionaryProduct[productKey] = value;
}
}
void ICollection<KeyValuePair<int, Product>>.Add(KeyValuePair<int, Product> productItem)
{
throw new NotImplementedException();
}
void ICollection<KeyValuePair<int, Product>>.Clear()
{
dictionaryProduct.Clear();
}
bool ICollection<KeyValuePair<int, Product>>.Contains(KeyValuePair<int, Product> productItem)
{
return (dictionaryProduct.Contains(productItem));
}
void ICollection<KeyValuePair<int, Product>>.CopyTo(KeyValuePair<int, Product>[] productArray, int arrayIndex)
{
throw new NotImplementedException();
}
int ICollection<KeyValuePair<int, Product>>.Count
{
get
{
return dictionaryProduct.Count;
}
}
bool ICollection<KeyValuePair<int, Product>>.IsReadOnly
{
get
{
throw new NotImplementedException();
}
}
bool ICollection<KeyValuePair<int, Product>>.Remove(KeyValuePair<int, Product> productItem)
{
throw new NotImplementedException();
}
IEnumerator<KeyValuePair<int, Product>> IEnumerable<KeyValuePair<int, Product>>.GetEnumerator()
{
throw new NotImplementedException();
}
public IEnumerator<KeyValuePair<int, Product>> GetEnumerator()
{
throw new NotImplementedException();
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
}
일주일 후, 더 후, 나는 밖으로 주조와 데이터 소스에 바인더 제본 할 수있는 제품에 대한 사용자 지정 사전 클래스 객체가 있습니다. 다른 사람이이 문제를 개선 할 수있는 방법이나 문제점을 보았습니까? 난 당신이 완전히 IEnumerable 인터페이스를 정의하지 않았기 때문에 그것이 불평 생각 ProductEnumerator
public IEnumerator IEnumerable.GetEnumerator()
{
return (IEnumerator) GetEnumerator();
}
이 추가
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
[Serializable]
public class Product
{
// 0 _ItemNumber = null;
// 1 _Title = null;
// 2 _Author = null;
// 3 _ItemNumber = null;
// ..etc
private string[] _Product = new string[29];
public Product()
{
}
public string Title
{
get
{
return _Product[1];
}
set
{
_Product[1] = value;
}
}
public string Author
{
get
{
return _Product[2];
}
set
{
_Product[2] = value;
}
}
public string ISBN
{
get
{
return _Product[3];
}
set
{
_Product[3] = value;
}
}
public string ItemNumber
{
get
{
return _Product[4];
}
set
{
_Product[4] = value;
}
}
}
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
/// <summary>
///
/// </summary>
public class ProductCollection : DictionaryBase, IEnumerable
{
public ProductCollection this[int productKey]
{
get
{
return ((ProductCollection)(Dictionary[productKey]));
}
set
{
Dictionary[productKey] = value;
}
}
public bool Contains(Product objectProduct)
{
return Dictionary.Contains(objectProduct);
}
public void Add(Product objectProduct)
{
Dictionary.Add(objectProduct.ItemNumber, objectProduct);
}
public void Remove(int productKey)
{
Dictionary.Remove(productKey);
}
IEnumerator IEnumerable.GetEnumerator()
{
foreach (Product productObject in this.Dictionary.Values)
{
yield return productObject;
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
Product objectProduct = new Product();
objectProduct.Title = "Hello Title";
objectProduct.Author = "Hello Author";
objectProduct.ISBN = "Hello ISBN";
objectProduct.ItemNumber = "Hello ItemNumber";
ProductCollection productCollection = new ProductCollection();
productCollection.Add(objectProduct);
rpProducts.DataSource = productCollection;
rpProducts.DataBind();
}
<asp:Repeater ID="rpProducts" runat="server">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Title") %>
<br />
<%# DataBinder.Eval(Container.DataItem, "Author") %>
</ItemTemplate>
</asp:Repeater>
오류 메시지 읽기! 정확히 무엇이 잘못되었는지 알려줍니다. 모든 컴파일 오류가 선언적 이었으면합니다. – Nix
게시 한 코드가이 오류 메시지와 일치하지 않는 것 같습니다. ProductCollection은 존재하지 않는'this.List'와'base.List' 멤버뿐만 아니라 다른 에러를 가리키고 있습니다. – Thorarin
IDE에서이 클래스를 만들면 누구나 모든 NotImplementedException 메서드를 도울 수 있습니다. – Cpurepair785