예제 #1
0
		/// <summary>
		/// 回收引用对象
		/// </summary>
		public void Release(IReference item)
		{
			if (item == null)
				return;

			if (item.GetType() != ClassType)
				throw new Exception($"Invalid type {item.GetType()}");

			if (_pool.Contains(item))
				throw new Exception($"The item {item.GetType()} already exists.");

			SpawnCount--;
			item.OnRelease();
			_pool.Enqueue(item);
		}
예제 #2
0
        public void OnDeSpawn(IReference re)
        {
            Type          t             = re.GetType();
            ReferencePool referencePool = mReferencePools[t];

            referencePool.OnDeSpawn(re);
        }
예제 #3
0
        /// <summary>
        /// 将引用归还引用池。
        /// </summary>
        /// <param name="referenceType">引用类型。</param>
        /// <param name="reference">引用。</param>
        public static void Release(Type referenceType, IReference reference)
        {
            if (referenceType == null)
            {
                throw new GameFrameworkException("Reference type is invalid.");
            }

            if (!referenceType.IsClass || referenceType.IsAbstract)
            {
                throw new GameFrameworkException("Reference type is not a non-abstract class type.");
            }

            if (reference == null)
            {
                throw new GameFrameworkException("Reference is invalid.");
            }

            Type type = reference.GetType();

            if (referenceType != type)
            {
                throw new GameFrameworkException(string.Format("Reference type '{0}' not equals to reference's type '{1}'.", referenceType.FullName, type.FullName));
            }

            reference.Clear();
            lock (s_ReferencePool)
            {
                GetReferencePool(referenceType.FullName).Enqueue(reference);
            }
        }
예제 #4
0
        public static void Release(Type referenceType, IReference reference)
        {
            if (referenceType == null)
            {
            }

            if (!referenceType.IsClass || referenceType.IsAbstract)
            {
            }
            if (reference == null)
            {
            }

            Type type = reference.GetType();

            if (referenceType != type)
            {
                throw;
            }

            reference.Clear();
            lock (s_ReferencePool)
            {
                GetReferencePool(referenceType.FullName).Enqueue(reference);
            }
        }
        private void CheckForResolveProblems(IHighlightingConsumer consumer, IReference reference)
        {
            var error = reference.CheckResolveResult();

            if (error == null)
            {
                throw new InvalidOperationException("ResolveErrorType is null for reference " +
                                                    reference.GetType().FullName);
            }

            if (error == ResolveErrorType.OK)
            {
                return;
            }

            if (myResolveHighlighterRegistrar.ContainsHandler(ShaderLabLanguage.Instance, error))
            {
                var highlighting = myResolveHighlighterRegistrar.GetResolveHighlighting(reference, error);
                if (highlighting != null)
                {
                    consumer.AddHighlighting(highlighting);
                }
            }
            else
            {
                consumer.AddHighlighting(new NotResolvedError(reference));
            }
        }
        /// <summary>
        /// 回收引用
        /// </summary>
        /// <param name="refe">对象</param>
        public void Despawn(IReference refe)
        {
            Type type = refe.GetType();
            if (!_spawnPools.ContainsKey(type))
            {
                _spawnPools.Add(type, new ReferenceSpawnPool(Limit));
            }

            _spawnPools[type].Despawn(refe);
        }
예제 #7
0
        public void Despawn(IReference refer)
        {
            Type type = refer.GetType();

            if (!referenceDict.ContainsKey(type))
            {
                referenceDict.TryAdd(type, new ReferenceSpawnPool());
            }
            referenceDict[type].Despawn(refer);
        }
예제 #8
0
        /// <summary>
        /// 回收引用对象
        /// </summary>
        public static void Release(IReference item)
        {
            Type type = item.GetType();

            if (_pools.ContainsKey(type) == false)
            {
                _pools.Add(type, new ReferencePool(type, InitCapacity));
            }
            _pools[type].Release(item);
        }
        /// <summary>
        /// 回收引用对象
        /// </summary>
        public static void Release(IReference item)
        {
            Type type = item.GetType();

            if (_collectors.ContainsKey(type) == false)
            {
                _collectors.Add(type, new ReferenceCollector(type, InitCapacity));
            }
            _collectors[type].Release(item);
        }
        /// <summary>
        /// 将引用归还引用池
        /// </summary>
        /// <param name="reference">引用</param>
        public static void Release(IReference reference)
        {
            if (reference == null)
            {
                throw new Exception("[ReferencePool.Release] Reference is invalid -> reference == null");
            }
            Type referenceType = reference.GetType();

            InternalCheckReferenceType(referenceType);
            GetReferenceCollection(referenceType).Release(reference);
        }
예제 #11
0
        /// <summary>
        /// 将引用归还引用池。
        /// </summary>
        /// <param name="reference">引用。</param>
        public static void Release(IReference reference)
        {
            if (reference == null)
            {
                Log.Error("Reference is invalid.");
            }

            Type referenceType = reference.GetType();

            InternalCheckReferenceType(referenceType);
            GetReferenceCollection(referenceType).Release(reference);
        }
예제 #12
0
        /// <summary>
        /// 将引用归还引用池。
        /// </summary>
        /// <typeparam name="T">引用类型。</typeparam>
        /// <param name="reference">引用。</param>
        public static void Recycle(IReference reference)
        {
            if (reference == null)
            {
                Logger.LogError("Reference is invalid.");
            }

            lock (s_ReferencePool)
            {
                GetReferencePool(reference.GetType()).Enqueue(reference);
            }
        }
예제 #13
0
        /// <summary>
        /// 回收引用对象
        /// </summary>
        public void Release(IReference item)
        {
            if (item == null)
            {
                return;
            }

            if (item.GetType() != ClassType)
            {
                throw new Exception($"Invalid type {item.GetType()}");
            }

            if (_collector.Contains(item))
            {
                throw new Exception($"The item {item.GetType()} already exists.");
            }

            SpawnCount--;
            item.OnRelease();
            _collector.Enqueue(item);
        }
예제 #14
0
        /// <summary>
        /// 将引用归还引用池。
        /// </summary>
        /// <param name="reference">引用。</param>
        public static void Release(IReference reference)
        {
            if (reference == null)
            {
                throw new GameFrameworkException("Reference is invalid.");
            }

            Type referenceType = reference.GetType();

            InternalCheckReferenceType(referenceType);
            GetReferenceCollection(referenceType).Release(reference);
        }
예제 #15
0
        /// <summary>
        /// 回收引用
        /// </summary>
        /// <param name="refe">对象</param>
        public void Despawn(IReference refe)
        {
            if (refe == null)
            {
                return;
            }

            Type type = refe.GetType();

            if (!SpawnPools.ContainsKey(type))
            {
                SpawnPools.Add(type, new ReferenceSpawnPool(_limit));
            }

            SpawnPools[type].Despawn(refe);
        }
예제 #16
0
        /// <summary>
        /// 将引用归还引用池。
        /// </summary>
        /// <param name="referenceType">引用类型。</param>
        /// <param name="reference">引用。</param>
        public static void Release(Type referenceType, IReference reference)
        {
            InternalCheckReferenceType(referenceType);

            if (reference == null)
            {
                throw new GameFrameworkException("Reference is invalid.");
            }

            Type type = reference.GetType();

            if (referenceType != type)
            {
                throw new GameFrameworkException(string.Format("Reference type '{0}' not equals to reference's type '{1}'.", referenceType.FullName, type.FullName));
            }

            GetReferenceCollection(referenceType.FullName).Release(reference);
        }
예제 #17
0
 public static string GetIDStringForReference(IReference reference)
 {
     if (reference is ITypeReference)
     {
         return(TypeHelper.GetTypeName((ITypeReference)reference, NameFormattingOptions.DocumentationId));
     }
     else if (reference is IMethodReference)
     {
         return(MemberHelper.GetMethodSignature((IMethodReference)reference, NameFormattingOptions.DocumentationId));
     }
     else if (reference is IFieldDefinition)
     {
         return(MemberHelper.GetMemberSignature((IFieldReference)reference, NameFormattingOptions.DocumentationId));
     }
     else
     {
         throw new ArgumentException("Un-supported reference type: " + reference.GetType());
     }
 }
예제 #18
0
        private void CheckForResolveProblems(IHighlightingConsumer consumer, IReference reference)
        {
            var error = reference.CheckResolveResult();

            if (error == null)
            {
                throw new InvalidOperationException("ResolveErrorType is null for reference " +
                                                    reference.GetType().FullName);
            }

            if (error == ResolveErrorType.OK)
            {
                return;
            }

            // ReSharper disable once AssignNullToNotNullAttribute
            if (myResolveHighlighterRegistrar.ContainsHandler(ShaderLabLanguage.Instance, error))
            {
                var highlighting = myResolveHighlighterRegistrar.GetResolveHighlighting(reference, error);
                if (highlighting != null)
                {
                    consumer.AddHighlighting(highlighting);
                }
            }
            else
            {
                // The default is unresolved. But we can't use something like NotResolvedError because:
                // a) Using an undeclared property in ShaderLab isn't a compile time error. An undeclared
                //    property just uses the default value
                // b) Properties can be set from code, without having to be declared first
                // c) There is at least one hidden property `unity_GUIZTestMode`
                //
                // So, this could be:
                // a) a typo
                // b) an external reference
                //
                // How do we tell the difference, and how do we show the difference?
                // For now, just don't give an error
                consumer.AddHighlighting(new NotResolvedPropertyWarning(reference));
            }
        }
예제 #19
0
        public virtual void VisitNode(IReference node)
        {
            IAssembly             assembly = node as IAssembly;
            INamedTypeDefinition  type     = node as INamedTypeDefinition;
            ITypeDefinitionMember member   = node as ITypeDefinitionMember;
            IAliasForType         alias    = node as IAliasForType;

            if (assembly != null)
            {
                if (m_implModel.CanIncludeAssembly(assembly.AssemblyIdentity))
                {
                    Visit(assembly);
                }
            }
            else if (type != null)
            {
                INamedTypeReference typeRef = Util.CanonicalizeTypeReference(type);
                if (m_implModel.CanInclude(typeRef))
                {
                    Visit(type);
                }
            }
            else if (member != null)
            {
                INamedTypeReference typeRef = Util.CanonicalizeTypeReference(member.ContainingType);
                if (m_implModel.CanInclude(typeRef))
                {
                    Visit(member);
                }
            }
            else if (alias != null)
            {
                Visit(alias);
            }
            else
            {
                throw new Exception("Illegal node: " + node.GetType().Name);
            }
        }
예제 #20
0
        public virtual void VisitNode(IReference node)
        {
            IAssembly assembly = node as IAssembly;
            INamedTypeDefinition type = node as INamedTypeDefinition;
            ITypeDefinitionMember member = node as ITypeDefinitionMember;
            IAliasForType alias = node as IAliasForType;

            if (assembly != null)
            {
                if (m_implModel.CanIncludeAssembly(assembly.AssemblyIdentity))
                {
                    Visit(assembly);
                }
            }
            else if (type != null)
            {
                INamedTypeReference typeRef = Util.CanonicalizeTypeReference(type);
                if (m_implModel.CanInclude(typeRef))
                {
                    Visit(type);
                }
            }
            else if (member != null)
            {
                INamedTypeReference typeRef = Util.CanonicalizeTypeReference(member.ContainingType);
                if (m_implModel.CanInclude(typeRef))
                {
                    Visit(member);
                }
            }
            else if (alias != null)
            {
                Visit(alias);
            }
            else
            {
                throw new Exception("Illegal node: " + node.GetType().Name);
            }
        }
        private void CheckForResolveProblems(IHighlightingConsumer consumer, IReference reference)
        {
            var resolveErrorType = reference.CheckResolveResult();

            if (resolveErrorType == null)
            {
                throw new InvalidOperationException("ResolveErrorType is null for reference " + reference.GetType().FullName);
            }

            if (resolveErrorType.IsAcceptable)
            {
                return;
            }

            // ReSharper disable once AssignNullToNotNullAttribute
            if (myResolveHighlighterRegistrar.ContainsHandler(YamlLanguage.Instance, resolveErrorType))
            {
                var highlighting = myResolveHighlighterRegistrar.GetResolveHighlighting(reference, resolveErrorType);
                if (highlighting != null)
                {
                    consumer.AddHighlighting(highlighting);
                }
            }
            else
            {
                consumer.AddHighlighting(new NotResolvedError(reference));
            }
        }
        public static IAssemblyReference GetAssemblyReference(this IReference reference)
        {
            Contract.Requires(reference != null);
            Contract.Requires(!(reference is Dummy));

            IAssemblyReference assembly = reference as IAssemblyReference;

            if (assembly != null)
            {
                return(assembly);
            }

            ITypeReference type = reference as ITypeReference;

            if (type != null)
            {
                return(type.GetAssemblyReference());
            }

            ITypeMemberReference member = reference as ITypeMemberReference;

            if (member != null)
            {
                return(member.ContainingType.GetAssemblyReference());
            }

            throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, LocalizedStrings.UnknownIReference, reference.GetType().FullName));
        }
        public static string FullName(this IReference reference)
        {
            Contract.Requires(reference != null);

            ITypeReference type = reference as ITypeReference;

            if (type != null)
            {
                return(TypeHelper.GetTypeName(type, NameFormattingOptions.TypeParameters));
            }

            ITypeMemberReference member = reference as ITypeMemberReference;

            if (member != null)
            {
                return(MemberHelper.GetMemberSignature(member, NameFormattingOptions.TypeParameters | NameFormattingOptions.Signature));
            }

            IUnitNamespaceReference ns = reference as IUnitNamespaceReference;

            if (ns != null)
            {
                return(TypeHelper.GetNamespaceName(ns, NameFormattingOptions.None));
            }

            INamedEntity named = reference as INamedEntity;

            if (named != null)
            {
                return(named.Name.Value);
            }

            Contract.Assert(false, String.Format(CultureInfo.CurrentCulture, LocalizedStrings.FellThroughCasesIn, "TypeExtensions.FullName()", reference.GetType()));
            return(LocalizedStrings.UnknownReferenceType);
        }
예제 #24
0
        public static string RefDocId(this IReference reference)
        {
            Contract.Requires(reference != null);

            ITypeReference type = reference as ITypeReference;

            if (type != null)
            {
                return(type.DocId());
            }

            ITypeMemberReference member = reference as ITypeMemberReference;

            if (member != null)
            {
                return(member.DocId());
            }

            IUnitNamespaceReference ns = reference as IUnitNamespaceReference;

            if (ns != null)
            {
                return(ns.DocId());
            }

            IAssemblyReference assembly = reference as IAssemblyReference;

            if (assembly != null)
            {
                return(assembly.DocId());
            }

            Contract.Assert(false, string.Format("Fell through cases in TypeExtensions.RefDocId() Type of reference: {0}", reference.GetType()));
            return("<Unknown Reference Type>");
        }
예제 #25
0
        public static string RefDocId(this IReference reference)
        {
            Contract.Requires(reference != null);

            if (reference is ITypeReference type)
            {
                return(type.DocId());
            }
            else if (reference is ITypeMemberReference member)
            {
                return(member.DocId());
            }
            else if (reference is IUnitNamespaceReference ns)
            {
                return(ns.DocId());
            }
            else if (reference is IAssemblyReference assembly)
            {
                return(assembly.DocId());
            }

            Contract.Assert(false, string.Format(CultureInfo.CurrentUICulture, LocalizedStrings.FellThroughCasesIn, "DocIdExtensions.RefDocId()", reference.GetType()));
            return(LocalizedStrings.UnknownReferenceType);
        }
예제 #26
0
        public static string FullName(this IReference reference)
        {
            Contract.Requires(reference != null);

            ITypeReference type = reference as ITypeReference;

            if (type != null)
            {
                return(TypeHelper.GetTypeName(type, NameFormattingOptions.TypeParameters));
            }

            ITypeMemberReference member = reference as ITypeMemberReference;

            if (member != null)
            {
                return(MemberHelper.GetMemberSignature(member, NameFormattingOptions.TypeParameters | NameFormattingOptions.Signature));
            }

            IUnitNamespaceReference ns = reference as IUnitNamespaceReference;

            if (ns != null)
            {
                return(TypeHelper.GetNamespaceName(ns, NameFormattingOptions.None));
            }

            INamedEntity named = reference as INamedEntity;

            if (named != null)
            {
                return(named.Name.Value);
            }

            Contract.Assert(false, String.Format("Fell through cases in TypeExtensions.FullName() Type of reference: {0}", reference.GetType()));
            return("<Unknown Reference Type>");
        }
예제 #27
0
        public static IAssemblyReference GetAssemblyReference(this IReference reference)
        {
            Contract.Requires(reference != null);
            Contract.Requires(!(reference is Dummy));

            IAssemblyReference assembly = reference as IAssemblyReference;

            if (assembly != null)
            {
                return(assembly);
            }

            ITypeReference type = reference as ITypeReference;

            if (type != null)
            {
                return(type.GetAssemblyReference());
            }

            ITypeMemberReference member = reference as ITypeMemberReference;

            if (member != null)
            {
                return(member.ContainingType.GetAssemblyReference());
            }

            throw new NotSupportedException(string.Format("Unknown IReference '{0}' so we cannot get assembly reference!", reference.GetType().FullName));
        }