当前位置: 首页>>代码示例>>C#>>正文


C# List.Add方法代码示例

本文整理汇总了C#中NHibernate.Collection.List.Add方法的典型用法代码示例。如果您正苦于以下问题:C# List.Add方法的具体用法?C# List.Add怎么用?C# List.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NHibernate.Collection.List的用法示例。


在下文中一共展示了List.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetSnapshot

		public override ICollection GetSnapshot(ICollectionPersister persister)
		{
			EntityMode entityMode = Session.EntityMode;

			List<object> clonedList = new List<object>(list.Count);
			foreach (object current in list)
			{
				object deepCopy = persister.ElementType.DeepCopy(current, entityMode, persister.Factory);
				clonedList.Add(deepCopy);
			}
			return clonedList;
		}
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:12,代码来源:PersistentList.cs

示例2: GetDeletes

		// For a one-to-many, a <bag> is not really a bag;
		// it is *really* a set, since it can't contain the
		// same element twice. It could be considered a bug
		// in the mapping dtd that <bag> allows <one-to-many>.

		// Anyway, here we implement <set> semantics for a
		// <one-to-many> <bag>!

		public override IEnumerable GetDeletes(ICollectionPersister persister, bool indexIsFormula)
		{
			IType elementType = persister.ElementType;
			EntityMode entityMode = Session.EntityMode;
			List<object> deletes = new List<object>();
			IList sn = (IList) GetSnapshot();
			int i = 0;
			foreach (object old in sn)
			{
				bool found = false;
				if (bag.Count > i && elementType.IsSame(old, bag[i++], entityMode))
				{
					//a shortcut if its location didn't change!
					found = true;
				}
				else
				{
					foreach (object newObject in bag)
					{
						if (elementType.IsSame(old, newObject, entityMode))
						{
							found = true;
							break;
						}
					}
				}
				if (!found)
				{
					deletes.Add(old);
				}
			}
			return deletes;
		}
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:41,代码来源:PersistentBag.cs

示例3: RenderLoggableString

		protected internal virtual string RenderLoggableString(object value, ISessionFactoryImplementor factory)
		{
			IList list = new List<object>();
			IType elemType = GetElementType(factory);
			IEnumerable iter = GetElementsIterator(value);
			foreach (object o in iter)
				list.Add(elemType.ToLoggableString(o, factory));

			return CollectionPrinter.ToString(list);
		}
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:10,代码来源:CollectionType.cs

示例4: GetSubselectInitializer

		private ICollectionInitializer GetSubselectInitializer(object key, ISessionImplementor session)
		{
			if (!IsSubselectLoadable)
			{
				return null;
			}

			IPersistenceContext persistenceContext = session.PersistenceContext;

			SubselectFetch subselect =
				persistenceContext.BatchFetchQueue.GetSubselect(new EntityKey(key, OwnerEntityPersister, session.EntityMode));

			if (subselect == null)
			{
				return null;
			}
			else
			{
				// Take care of any entities that might have
				// been evicted!
				List<EntityKey> keysToRemove = new List<EntityKey>(subselect.Result.Count);
				foreach (EntityKey entityKey in subselect.Result)
				{
					if (!persistenceContext.ContainsEntity(entityKey))
					{
						keysToRemove.Add(entityKey);
					}
				}
				subselect.Result.RemoveAll(keysToRemove);

				// Run a subquery loader
				return CreateSubselectInitializer(subselect, session);
			}
		}
开发者ID:khaliyo,项目名称:Spring.net-NHibernate.net-Asp.net-MVC-DWZ-,代码行数:34,代码来源:AbstractCollectionPersister.cs

示例5: ToLoggableString

		public override string ToLoggableString(object value, ISessionFactoryImplementor factory)
		{
			if (value == null)
			{
				return "null";
			}
			Array array = (Array) value;
			int length = array.Length;
			IList list = new List<object>(length);
			IType elemType = GetElementType(factory);
			for (int i = 0; i < length; i++)
			{
				list.Add(elemType.ToLoggableString(array.GetValue(i), factory));
			}
			return CollectionPrinter.ToString(list);
		}
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:16,代码来源:ArrayType.cs

示例6: AddAssociation

		/// <summary>
		/// Adds an association and extracts the aliases the association's 'with clause' is dependent on
		/// </summary>
		private void AddAssociation(string subalias, OuterJoinableAssociation association)
		{
			subalias = subalias.ToLower();

			var dependencies = new List<string>();
			var on = association.On.ToString();
			if (!String.IsNullOrEmpty(on))
			{
				foreach (Match match in aliasRegex.Matches(on))
				{
					string alias = match.Groups[1].Value;
					if (alias == subalias) continue;
					dependencies.Add(alias.ToLower());
				}
			}

			_dependentAliases.Add(new DependentAlias
			{
				Alias = subalias,
				DependsOn = dependencies.ToArray()
			});

			associations.Add(association);
		}
开发者ID:rbirkby,项目名称:nhibernate-core,代码行数:27,代码来源:JoinWalker.cs

示例7: EndLoadingCollections

		/// <summary> 
		/// Finish the process of collection-loading for this bound result set.  Mainly this
		/// involves cleaning up resources and notifying the collections that loading is
		/// complete. 
		/// </summary>
		/// <param name="persister">The persister for which to complete loading. </param>
		public void EndLoadingCollections(ICollectionPersister persister)
		{
			if (!loadContexts.HasLoadingCollectionEntries && (localLoadingCollectionKeys.Count == 0))
			{
				return;
			}

			// in an effort to avoid concurrent-modification-exceptions (from
			// potential recursive calls back through here as a result of the
			// eventual call to PersistentCollection#endRead), we scan the
			// internal loadingCollections map for matches and store those matches
			// in a temp collection.  the temp collection is then used to "drive"
			// the #endRead processing.
			List<CollectionKey> toRemove = new List<CollectionKey>();
			List<LoadingCollectionEntry> matches =new List<LoadingCollectionEntry>();
			foreach (CollectionKey collectionKey in localLoadingCollectionKeys)
			{
				ISessionImplementor session = LoadContext.PersistenceContext.Session;

				LoadingCollectionEntry lce = loadContexts.LocateLoadingCollectionEntry(collectionKey);
				if (lce == null)
				{
					log.Warn("In CollectionLoadContext#endLoadingCollections, localLoadingCollectionKeys contained [" + collectionKey + "], but no LoadingCollectionEntry was found in loadContexts");
				}
				else if (lce.ResultSet == resultSet && lce.Persister == persister)
				{
					matches.Add(lce);
					if (lce.Collection.Owner == null)
					{
						session.PersistenceContext.AddUnownedCollection(new CollectionKey(persister, lce.Key, session.EntityMode),
						                                                lce.Collection);
					}
					if (log.IsDebugEnabled)
					{
						log.Debug("removing collection load entry [" + lce + "]");
					}

					// todo : i'd much rather have this done from #endLoadingCollection(CollectionPersister,LoadingCollectionEntry)...
					loadContexts.UnregisterLoadingCollectionXRef(collectionKey);
					toRemove.Add(collectionKey);
				}
			}
			localLoadingCollectionKeys.ExceptWith(toRemove);

			EndLoadingCollections(persister, matches);
			if ((localLoadingCollectionKeys.Count == 0))
			{
				// todo : hack!!!
				// NOTE : here we cleanup the load context when we have no more local
				// LCE entries.  This "works" for the time being because really
				// only the collection load contexts are implemented.  Long term,
				// this cleanup should become part of the "close result set"
				// processing from the (sandbox/jdbc) jdbc-container code.
				loadContexts.Cleanup(resultSet);
			}
		}
开发者ID:owerkop,项目名称:nhibernate-core,代码行数:62,代码来源:CollectionLoadContext.cs

示例8: RemoveEntity

		/// <summary> 
		/// Remove an entity from the session cache, also clear
		/// up other state associated with the entity, all except
		/// for the <tt>EntityEntry</tt>
		/// </summary>
		public object RemoveEntity(EntityKey key)
		{
			object tempObject = entitiesByKey[key];
			entitiesByKey.Remove(key);
			object entity = tempObject;
			List<EntityUniqueKey> toRemove = new List<EntityUniqueKey>();
			foreach (KeyValuePair<EntityUniqueKey, object> pair in entitiesByUniqueKey)
			{
				if (pair.Value == entity) toRemove.Add(pair.Key);
			}
			foreach (EntityUniqueKey uniqueKey in toRemove)
			{
				entitiesByUniqueKey.Remove(uniqueKey);
			}

			entitySnapshotsByKey.Remove(key);
			nullifiableEntityKeys.Remove(key);
			BatchFetchQueue.RemoveBatchLoadableEntityKey(key);
			BatchFetchQueue.RemoveSubselect(key);
			return entity;
		}
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:26,代码来源:StatefulPersistenceContext.cs

示例9: Dispatch

        public override IAuditWorkUnit Dispatch(IWorkUnitMergeVisitor first)
        {
            if (first is PersistentCollectionChangeWorkUnit) {
                PersistentCollectionChangeWorkUnit original = (PersistentCollectionChangeWorkUnit) first;

                // Merging the collection changes in both work units.

                // First building a map from the ids of the collection-entry-entities from the "second" collection changes,
                // to the PCCD objects. That way, we will be later able to check if an "original" collection change
                // should be added, or if it is overshadowed by a new one.
                IDictionary<Object, PersistentCollectionChangeData> newChangesIdMap = new Dictionary<Object, PersistentCollectionChangeData>();
                foreach (PersistentCollectionChangeData persistentCollectionChangeData in getCollectionChanges()) {
                    newChangesIdMap.Add(
                            getOriginalId(persistentCollectionChangeData),
                            persistentCollectionChangeData);
                }

                // This will be the list with the resulting (merged) changes.
                List<PersistentCollectionChangeData> mergedChanges = new List<PersistentCollectionChangeData>();

                // Including only those original changes, which are not overshadowed by new ones.
                foreach (PersistentCollectionChangeData originalCollectionChangeData in original.getCollectionChanges()) {
                    if (!newChangesIdMap.ContainsKey(getOriginalId(originalCollectionChangeData))) {
                        mergedChanges.Add(originalCollectionChangeData);
                    }
                }

                // Finally adding all of the new changes to the end of the list
                mergedChanges = (List<PersistentCollectionChangeData>)mergedChanges.Concat(getCollectionChanges());

                return new PersistentCollectionChangeWorkUnit(sessionImplementor, EntityName, verCfg, EntityId, mergedChanges,
                        ReferencingPropertyName);
            } else {
                throw new Exception("Trying to merge a " + first + " with a PersitentCollectionChangeWorkUnit. " +
                        "This is not really possible.");
            }
        }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:37,代码来源:PersistentCollectionChangeWorkUnit.cs

示例10: PostFlush

		/// <summary> 
		/// 1. Recreate the collection key -> collection map
		/// 2. rebuild the collection entries
		/// 3. call Interceptor.postFlush()
		/// </summary>
		protected virtual void PostFlush(ISessionImplementor session)
		{
			if (log.IsDebugEnabled)
			{
				log.Debug("post flush");
			}

			IPersistenceContext persistenceContext = session.PersistenceContext;
			persistenceContext.CollectionsByKey.Clear();
			persistenceContext.BatchFetchQueue.ClearSubselects();
			//the database has changed now, so the subselect results need to be invalidated

			// NH Different implementation: In NET an iterator is immutable;
			// we need something to hold the persistent collection to remove, and it must be less intrusive as possible
			IDictionary cEntries = persistenceContext.CollectionEntries;
			List<IPersistentCollection> keysToRemove = new List<IPersistentCollection>(cEntries.Count);
			foreach (DictionaryEntry me in cEntries)
			{
				CollectionEntry collectionEntry = (CollectionEntry) me.Value;
				IPersistentCollection persistentCollection = (IPersistentCollection) me.Key;
				collectionEntry.PostFlush(persistentCollection);
				if (collectionEntry.LoadedPersister == null)
				{
					keysToRemove.Add(persistentCollection);
				}
				else
				{
					//otherwise recreate the mapping between the collection and its key
					CollectionKey collectionKey =
						new CollectionKey(collectionEntry.LoadedPersister, collectionEntry.LoadedKey, session.EntityMode);
					persistenceContext.CollectionsByKey[collectionKey] = persistentCollection;
				}
			}
			foreach (IPersistentCollection key in keysToRemove)
			{
				persistenceContext.CollectionEntries.Remove(key);
			}
			session.Interceptor.PostFlush((ICollection) persistenceContext.EntitiesByKey.Values);
		}
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:44,代码来源:AbstractFlushingEventListener.cs

示例11: GetDeletes

		public override IEnumerable GetDeletes(ICollectionPersister persister, bool indexIsFormula)
		{
			IList deletes = new List<object>();
			IList sn = (IList) GetSnapshot();
			int end;
			if (sn.Count > list.Count)
			{
				for (int i = list.Count; i < sn.Count; i++)
				{
					deletes.Add(indexIsFormula ? sn[i] : i);
				}
				end = list.Count;
			}
			else
			{
				end = sn.Count;
			}
			for (int i = 0; i < end; i++)
			{
				if (list[i] == null && sn[i] != null)
				{
					deletes.Add(indexIsFormula ? sn[i] : i);
				}
			}
			return deletes;
		}
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:26,代码来源:PersistentList.cs

示例12: GetDeletes

		public override IEnumerable GetDeletes(ICollectionPersister persister, bool indexIsFormula)
		{
			IList deletes = new List<object>();
			IDictionary sn = (IDictionary) GetSnapshot();
			foreach (DictionaryEntry e in sn)
			{
				object key = e.Key;
				if (!map.Contains(key))
				{
					deletes.Add(indexIsFormula ? e.Value : key);
				}
			}
			return deletes;
		}
开发者ID:tkellogg,项目名称:NHibernate3-withProxyHooks,代码行数:14,代码来源:PersistentMap.cs

示例13: InitValidator

        /// <summary>
        /// Initialize the <see cref="ClassValidator"/> type.
        /// </summary>
        /// <param name="clazz"></param>
        /// <param name="nestedClassValidators"></param>
        private void InitValidator(System.Type clazz, IDictionary<System.Type, IClassValidator> nestedClassValidators)
        {
            entityValidators = new List<ValidatorDef>();
            membersToValidate = new List<Member>();
            childGetters = new List<MemberInfo>();
            defaultInterpolator = new DefaultMessageInterpolatorAggregator();
            defaultInterpolator.Initialize(messageBundle, defaultMessageBundle, culture);

            //build the class hierarchy to look for members in
            nestedClassValidators.Add(clazz, this);
            HashSet<System.Type> classes = new HashSet<System.Type>();
            AddSuperClassesAndInterfaces(clazz, classes);

            // Create the IClassMapping for each class of the validator
            var classesMaps = new List<IClassMapping>(classes.Count);
            foreach (System.Type type in classes)
            {
                IClassMapping mapping = factory.ClassMappingFactory.GetClassMapping(type, validatorMode);
                if (mapping != null)
                    classesMaps.Add(mapping);
                else
                    log.Warn("Validator not found in mode " + validatorMode + " for class " + clazz.AssemblyQualifiedName);
            }

            //Check on all selected classes
            foreach (IClassMapping map in classesMaps)
            {
                foreach (Attribute classAttribute in map.GetClassAttributes())
                {
                    ValidateClassAtribute(classAttribute);
                }

                foreach (MemberInfo member in map.GetMembers())
                {
                    var memberAttributes = map.GetMemberAttributes(member);
                    CreateMemberAttributes(member, memberAttributes);
                    CreateChildValidator(member, memberAttributes);

                    foreach (Attribute memberAttribute in memberAttributes)
                    {
                        IValidator propertyValidator = CreateOrGetValidator(memberAttribute);

                        if (propertyValidator != null)
                        {
                            var tagable = memberAttribute as ITagableRule;
                            membersToValidate.Add(new Member
                                                  	{
                                                  		ValidatorDef =
                                                  			new ValidatorDef(propertyValidator, tagable != null ? tagable.TagCollection : null),
                                                  		Getter = member
                                                  	});
                        }
                    }
                }
            }
        }
开发者ID:spib,项目名称:nhcontrib,代码行数:61,代码来源:ClassValidator.cs

示例14: GetParameterTypes

		/// <returns><see cref="IList" /> of <see cref="IType" /></returns>
		protected SqlType[] GetParameterTypes(QueryParameters parameters, bool addLimit, bool addOffset)
		{
			List<IType> paramTypeList = new List<IType>();
			int span = 0;

			for (int index = 0; index < parameters.PositionalParameterTypes.Length; index++)
			{
				int location = parameters.PositionalParameterLocations[index];
				location = parameters.FindAdjustedParameterLocation(location);
				IType type = parameters.PositionalParameterTypes[index];
				ArrayHelper.SafeSetValue(paramTypeList, location, type);
				span += type.GetColumnSpan(Factory);
			}

			for (int index = 0; index < parameters.FilteredParameterTypes.Count; index++)
			{
				int location = parameters.FilteredParameterLocations[index];
				IType type = parameters.FilteredParameterTypes[index];
				ArrayHelper.SafeSetValue(paramTypeList, location, type);
				span += type.GetColumnSpan(Factory);
			}

			if (parameters.NamedParameters != null && parameters.NamedParameters.Count > 0)
			{
				// convert the named parameters to an array of types
				foreach (KeyValuePair<string, TypedValue> namedParameter in parameters.NamedParameters)
				{
					string name = namedParameter.Key;
					TypedValue typedval = namedParameter.Value;
					int[] locs = GetNamedParameterLocs(name);
					span += typedval.Type.GetColumnSpan(Factory) * locs.Length;

					for (int i = 0; i < locs.Length; i++)
					{
						int location = locs[i];
						location = parameters.FindAdjustedParameterLocation(location);

						// can still clash with positional parameters
						//  could consider throwing an exception to locate problem (NH-1098)
						while ((location < paramTypeList.Count) && (paramTypeList[location] != null))
							location++;

						ArrayHelper.SafeSetValue(paramTypeList, location, typedval.Type);
					}
				}
			}

			if (addLimit && Factory.Dialect.SupportsVariableLimit)
			{
				if (Factory.Dialect.BindLimitParametersFirst)
				{
					paramTypeList.Insert(0, NHibernateUtil.Int32);
					if (addOffset)
					{
						paramTypeList.Insert(0, NHibernateUtil.Int32);
					}
				}
				else
				{
					paramTypeList.Add(NHibernateUtil.Int32);
					if (addOffset)
					{
						paramTypeList.Add(NHibernateUtil.Int32);
					}
				}

				span += addOffset ? 2 : 1;
			}

			return ConvertITypesToSqlTypes(paramTypeList, span);
		}
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:72,代码来源:Loader.cs

示例15: AfterInitialize

		public override bool AfterInitialize(ICollectionPersister persister)
		{
			// NH Different behavior : NH-739
			// would be nice to prevent this overhead but the operation is managed where the ICollectionPersister is not available
			bool result;
			if (persister.IsOneToMany && HasQueuedOperations)
			{
				int additionStartFrom = bag.Count;
				IList additionQueue = new List<object>(additionStartFrom);
				foreach (object o in QueuedAdditionIterator)
				{
					if (o != null)
					{
						for (int i = 0; i < bag.Count; i++)
						{
							// we are using ReferenceEquals to be sure that is exactly the same queued instance 
							if (ReferenceEquals(o, bag[i]))
							{
								additionQueue.Add(o);
								break;
							}
						}
					}
				}

				result = base.AfterInitialize(persister);

				if(!result)
				{
					// removing duplicated additions
					foreach (object o in additionQueue)
					{
						for (int i = additionStartFrom; i < bag.Count; i++)
						{
							if (ReferenceEquals(o, bag[i]))
							{
								bag.RemoveAt(i);
								break;
							}
						}
					}
				}
			}
			else
			{
				result = base.AfterInitialize(persister);
			}
			return result;
		}
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:49,代码来源:PersistentBag.cs


注:本文中的NHibernate.Collection.List.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。