コード例 #1
0
        public NamespaceAndNestedType(INamespaceAndType parent, string name, params string[] genericTypeNames)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (!ValidateCsNameAttribute.NameRegex.IsMatch(name))
            {
                throw new ArgumentException("Invalid type name", "name");
            }

            Parent = parent;
            Type   = new CodeTypeDeclaration(name);
            if (genericTypeNames != null && genericTypeNames.Length > 0)
            {
                foreach (string n in genericTypeNames)
                {
                    if (n == null)
                    {
                        throw new ArgumentNullException("genericTypeNames");
                    }
                    if (!ValidateCsNameAttribute.NameRegex.IsMatch(n))
                    {
                        throw new ArgumentException("Invalid type name", "genericTypeNames");
                    }
                    Type.TypeParameters.Add(new CodeTypeParameter(n));
                }
            }
            parent.Type.Members.Add(Type);
        }
コード例 #2
0
 public NamespaceAndNestedType(INamespaceAndType parent, CodeTypeDeclaration type)
 {
     if (parent == null)
     {
         throw new ArgumentNullException("parent");
     }
     if (type == null)
     {
         throw new ArgumentNullException("type");
     }
     Parent = parent;
     Type   = type;
     if (!parent.Type.Members.OfType <CodeTypeDeclaration>().Any(t => ReferenceEquals(t, type)))
     {
         parent.Type.Members.Add(type);
     }
 }