2using System.Collections;
3using System.Collections.Generic;
5using System.Runtime.Serialization;
20 [APITypeAlias(
"NestedLayer")]
23 #region Public Properties
31 [DataMember(Order = 20)]
47 [DataMember(Order = 21, Name =
"sources"), InternalMember]
48 private List<IReference<ILayerSource>> SourcesAsReferenceList
51 set =>
sources =
new Sources(value);
53 #endregion Public Properties
65 public sealed class Sources :
APIType, IList<IReference<ILayerSource>>, IList
66 , IReadOnlyList<IReference<ILayerSource>>
69 public List<IReference<ILayerSource>>
References {
get;
set; }
75 References =
new List<IReference<ILayerSource>>();
119 this(
sources?.Select(r => ResolveReference(r, automaticTyping))) { }
133 new Sources(sourceReferenceList);
139 public static implicit
operator List<IReference<ILayerSource>>(
Sources sourcesInstance) =>
141 #endregion Constructors
143 #region Public Methods
153 References.Add(ResolveReference(reference, automaticTyping));
183 #endregion Public Methods
185 #region Private Methods
194 if (automaticTyping && TryCreateLayerReference(weaklyTyped, out
IReference<ILayer> converted))
196 return ThrowInvalidLossSourceException(weaklyTyped);
204 bool suppress_throw =
false)
210 if (weaklyTyped?.CollectionName !=
null &&
213 if (suppress_throw)
return false;
216 string additionalMessage =
null;
218 additionalMessage =
"You can use LossSet references as loss sources by " +
219 "simply attaching them to the sink layer's list of loss_sets, or by " +
220 "wrapping them with a no-op layer and including that layer as a source.";
221 ThrowInvalidLossSourceException(reference, additionalMessage);
225 if ((weaklyTyped?.resolved ??
false) && weaklyTyped.
GetValue() is
ILayer layerValue)
227 Type layerType = layerValue.GetType();
229 if (layerType != typeof(
ILayer))
231 typeof(
IReference<>).MakeGenericTypeFast(layerValue.GetType()), reference);
243 IReference reference,
string additionalMessage =
null)
245 string message = $
"Invalid reference type {reference.GetType().NiceTypeName()}" +
246 " encountered. All sources should either be Layer or LayerView references.";
247 if (additionalMessage !=
null)
248 message += $
" {additionalMessage}";
249 throw new InvalidCastException(message);
251 #endregion Private Methods
253 #region List<T> Delegated Implementation
296 #region Explicit Implementations
297 IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)
References).GetEnumerator();
298 int IList.Add(
object value) => ((IList)
References).Add(value);
299 bool IList.Contains(
object value) => ((IList)
References).Contains(value);
300 void ICollection.CopyTo(Array array,
int index) => ((ICollection)
References).CopyTo(array, index);
301 object ICollection.SyncRoot => ((ICollection)
References).SyncRoot;
302 bool ICollection.IsSynchronized => ((ICollection)
References).IsSynchronized;
303 int IList.IndexOf(
object value) => ((IList)
References).IndexOf(value);
304 void IList.Insert(
int index,
object value) => ((IList)
References).Insert(index, value);
305 void IList.Remove(
object value) => ((IList)
References).Remove(value);
306 bool IList.IsFixedSize => ((IList)
References).IsFixedSize;
307 object IList.this[
int index]
312 #endregion Explicit Implementations
313 #endregion List<T> Delegated Implementation
Base class used by all types and resources.
Abstract representation of a layer. This resource type cannot be instantiated instead derived resourc...
static readonly string CLASS_COLLECTION_NAME
The collection endpoint at which resources of this type reside on the server.
A wrapper for a List<T> of IReference<ILayerSource> references that simplifies the construction and u...
Sources(IEnumerable< IReference > sources, bool automaticTyping=true)
Construct a new sources list from any enumerable of references.
IEnumerator< IReference< ILayerSource > > GetEnumerator()
void Insert(int index, IReference< ILayerSource > item)
bool Remove(IReference< ILayerSource > item)
Sources(List< IReference< ILayerSource > > sources)
Construct a new sources list and bind its internal list of references to the supplied source list.
void Add(IReference< ILayerView > layerViewReference)
Add a IReference<ILayerView> (LayerView reference) to this nested layer's sources.
Sources(params IReference[] sources)
Construct a new sources list from any number of references arguments.
void Add(ILayer layer)
Add an inlined IReference<Layer> to this nested layer's sources.
void CopyTo(IReference< ILayerSource >[] array, int arrayIndex)
void Add(IReference< ILayer > layerReference)
Add a IReference<ILayer> (saved Layer reference) to this nested layer's sources.
int IndexOf(IReference< ILayerSource > item)
List< IReference< ILayerSource > > References
The underlying list of IReference<ILayerSource> references.
Sources()
Construct a new empty sources list.
bool Contains(IReference< ILayerSource > item)
void Add(IReference reference, bool automaticTyping=true)
Allows a weakly-typed reference to be added to this collection, with the possibility of runtime check...
Sources(IEnumerable< IReference< ILayerSource > > sources)
Construct a new sources list by copying the enumerable of references with the expected compile-time t...
Allows one or more source layers or layer_views to be attached as loss sources to some other layer de...
Nested()
Construct a new Nested Layer with the default perspective and empty list of source layers.
Sources sources
A list of the source layers forwarding losses to this layer.
IReference< ILayerSource > sink
The layer that will take on the sources' forwarded losses.
Base class for all LossSet sub-types. A LossSet is a resource that generates sample (trial) losses wh...
static readonly string CLASS_COLLECTION_NAME
The collection endpoint at which resources of this type reside on the server.
Implements the reference entity interface, with support for resolving references using lazy loading.
An interface for an object that provides access to some layer instance.
Abstract representation of a layer.
Base interface for all reference entities.
string CollectionName
The name of the collection at which this resource resides.
T GetValue(IEnumerable< Parameter > requestParameters=null, int? timeout=null, bool updateCache=false)
Gets the resource that this reference refers to by requesting it from the server.