コード例 #1
0
ファイル: OclCollection.cs プロジェクト: mff-uk/exolutio
 private static void ClosureTo <T>(OclClassifier newElementType, IEnumerable <OclAny> source, ICollection <OclAny> dst, Func <T, OclAny> body)
     where T : OclAny
 {
     //Iterate over added items
     foreach (OclAny s in source)
     {
         //Do not add duplicates
         if (!dst.Contains(s))
         {
             dst.Add(s);
             //Execute body for newly added item
             OclAny newItems = body((T)s);
             //Ignore null
             if (!IsNull(newItems))
             {
                 OclClassifier type = newItems.oclType();
                 if (type.ConformsToInternal(OclCollectionType.Collection(OclAny.Type)))
                 {
                     //Collection must be of new element type
                     if (type.ConformsToInternal(OclCollectionType.Collection(newElementType)))
                     {
                         ClosureTo(newElementType, (OclCollection)newItems, dst, body);
                     }
                     else
                     {
                         throw new InvalidCastException();
                     }
                 }
                 else
                 {
                     //Non-collection must be kind of new element type
                     if (type.ConformsToInternal(newElementType))
                     {
                         //Add the result
                         OclAny[] arr = { newItems };
                         ClosureTo(newElementType, arr, dst, body);
                     }
                     else
                     {
                         throw new InvalidCastException();
                     }
                 }
             }
         }
     }
 }
コード例 #2
0
ファイル: OclBag.cs プロジェクト: mff-uk/exolutio
 public override OclClassifier oclType()
 {
     return(OclCollectionType.Collection(OclCollectionKind.Bag, elementType));
 }