Exemplo n.º 1
0
        private static void StructDependsClosure(TypeSymbol type, HashSet <Symbol> partialClosure, NamedTypeSymbol on)
        {
            if ((object)type == null)
            {
                return;
            }

            var nt = type as NamedTypeSymbol;

            if ((object)nt != null && ReferenceEquals(nt.OriginalDefinition, on))
            {
                // found a possibly expanding cycle, for example
                //     struct X<T> { public T t; }
                //     struct W<T> { X<W<W<T>>> x; }
                // while not explicitly forbidden by the spec, it should be.
                partialClosure.Add(on);
                return;
            }
            if ((object)nt != null && partialClosure.Add(nt))
            {
                foreach (var member in type.GetMembersUnordered())
                {
                    var field = member as FieldSymbol;
                    if ((object)field == null || field.Type.TypeKind != TypeKind.Struct || field.IsStatic)
                    {
                        continue;
                    }

                    StructDependsClosure(field.Type, partialClosure, on);
                }
            }
        }
        private static void StructDependsClosure(TypeSymbol type, HashSet<Symbol> partialClosure, NamedTypeSymbol on)
        {
            if ((object)type == null)
            {
                return;
            }

            var nt = type as NamedTypeSymbol;
            if ((object)nt != null && ReferenceEquals(nt.OriginalDefinition, on))
            {
                // found a possibly expanding cycle, for example
                //     struct X<T> { public T t; }
                //     struct W<T> { X<W<W<T>>> x; }
                // while not explicitly forbidden by the spec, it should be.
                partialClosure.Add(on);
                return;
            }
            if ((object)nt != null && partialClosure.Add(nt))
            {
                foreach (var member in type.GetMembersUnordered())
                {
                    var field = member as FieldSymbol;
                    if ((object)field == null || field.Type.TypeKind != TypeKind.Struct || field.IsStatic)
                    {
                        continue;
                    }

                    StructDependsClosure(field.Type, partialClosure, on);
                }
            }
        }