/// <summary> /// Adds a new object of type <typeparamref name="T"/> to the end of the <see cref="DisposableList{T}"/>. /// </summary> /// <typeparam name="TNew"></typeparam> /// <returns></returns> public TNew AddNew <TNew>() where TNew : T, new() { var newItem = new TNew(); Add(newItem); return(newItem); }
public TNew[] As <TNew>() where TNew : class { TNew[] of = new TNew[count]; for (int i = 0; i < count; i++) { of[i] = array[i] as TNew; } return(of); }
public TNew[] Cast <TNew>() { TNew[] of = new TNew[count]; for (int i = 0; i < count; i++) { of[i] = (TNew)(dynamic)array[i]; } return(of); }
public ValueOrError <TNew> ChangeType <TNew>() where TNew : class { TNew newValue = null; if (_value != null) { newValue = _value as TNew; if (newValue == null) { throw new Exception(string.Format("Cannot cast {0} to {1}.", typeof(T).Name, typeof(TNew).Name)); } } return(new ValueOrError <TNew>(newValue, _error)); }