Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 12, 2011 10:32 AM by seasol
0 Points
2 Posts
Jan 12, 2011 10:32 AM|LINK
Hello
I have a problem with StateManagedCollection when i try to make it generic. This is the code:
[ AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) ] public abstract class GenericCollection<T> : StateManagedCollection { private static readonly Type[] _knownTypes; private int capacity; static GenericCollection() { GenericCollection< T>._knownTypes = new Type[] { typeof(T) }; } public GenericCollection(){} public int Add(T item) { return ((IList)this).Add(item); } public bool Contains(T item) { return ((IList)this).Contains(item); } public void CopyTo(T[] array, int index) { this.CopyTo(array, index); } protected abstract override object CreateKnownType(int index); protected override Type[] GetKnownTypes() { return BaseItemCollection<T>._knownTypes; } public int IndexOf(T value) { return ((IList)this).IndexOf(value); } public void Insert(int index, T item) { ((IList)this).Insert(index, item); } protected override void OnClear() { base.OnClear(); } protected override void OnRemoveComplete(int index, object value) { base.OnRemoveComplete(index, value); } protected override void OnValidate(object value) { base.OnValidate(value); } public void Remove(T item) { this.Remove(item); } public void RemoveAt(int index) { this.RemoveAt(index); } public int Capacity { get { return this.capacity; } set { this.capacity = value; } } public T this[int i] { //HERE THROW STACKOVERFLOW EXCEPTION get { return (T)this[i]; } set { this[i] = value; } } }
This is the collection that i try to make it generic
[ AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) ] public sealed class ItemCollection : GenericCollection<Item> { protected override object CreateKnownType(int index) { return new Item(); } protected override void SetDirtyObject(object o) { if (o is Item) { ((Item)o).SetDirty(); } } }
[ Browsable(false), TemplateInstance(TemplateInstance.Single), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), PersistenceMode(PersistenceMode.InnerProperty) ] public ITemplate Template { get { return _temlpate; } set { _temlpate = value; } } [ Category("Behavior"), DefaultValue(""), Description(""), NotifyParentProperty(true), ] public string Name { get { object animation = ViewState["Name"]; return (animation == null) ? string.Empty : (string)animation; } set { ViewState["Name"] = value; } } }
stackoverflowexception
SeaSol
0 Points
2 Posts
StateManagedCollection throw stackOverfolow exception.
Jan 12, 2011 10:32 AM|LINK
Hello
I have a problem with StateManagedCollection when i try to make it generic. This is the code:
[ AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) ] public abstract class GenericCollection<T> : StateManagedCollection { private static readonly Type[] _knownTypes; private int capacity; static GenericCollection() { GenericCollection< T>._knownTypes = new Type[] { typeof(T) }; } public GenericCollection(){} public int Add(T item) { return ((IList)this).Add(item); } public bool Contains(T item) { return ((IList)this).Contains(item); } public void CopyTo(T[] array, int index) { this.CopyTo(array, index); } protected abstract override object CreateKnownType(int index); protected override Type[] GetKnownTypes() { return BaseItemCollection<T>._knownTypes; } public int IndexOf(T value) { return ((IList)this).IndexOf(value); } public void Insert(int index, T item) { ((IList)this).Insert(index, item); } protected override void OnClear() { base.OnClear(); } protected override void OnRemoveComplete(int index, object value) { base.OnRemoveComplete(index, value); } protected override void OnValidate(object value) { base.OnValidate(value); } public void Remove(T item) { this.Remove(item); } public void RemoveAt(int index) { this.RemoveAt(index); } public int Capacity { get { return this.capacity; } set { this.capacity = value; } } public T this[int i] { //HERE THROW STACKOVERFLOW EXCEPTION get { return (T)this[i]; } set { this[i] = value; } } }This is the collection that i try to make it generic
[ AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) ] public sealed class ItemCollection : GenericCollection<Item> { protected override object CreateKnownType(int index) { return new Item(); } protected override void SetDirtyObject(object o) { if (o is Item) { ((Item)o).SetDirty(); } } }This is the Item that i try to put:
[ Browsable(false), TemplateInstance(TemplateInstance.Single), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), PersistenceMode(PersistenceMode.InnerProperty) ] public ITemplate Template { get { return _temlpate; } set { _temlpate = value; } } [ Category("Behavior"), DefaultValue(""), Description(""), NotifyParentProperty(true), ] public string Name { get { object animation = ViewState["Name"]; return (animation == null) ? string.Empty : (string)animation; } set { ViewState["Name"] = value; } } }</div></div>
stackoverflowexception