System.Xml.Serialization.TypeScope.IsKnownType C# (CSharp) Method

IsKnownType() static private method

static private IsKnownType ( Type type ) : bool
type System.Type
return bool
        internal static bool IsKnownType(Type type)
        {
            if (type == typeof(object))
                return true;
            if (type.GetTypeInfo().IsEnum)
                return false;

            switch (type.GetTypeCode())
            {
                case TypeCode.String: return true;
                case TypeCode.Int32: return true;
                case TypeCode.Boolean: return true;
                case TypeCode.Int16: return true;
                case TypeCode.Int64: return true;
                case TypeCode.Single: return true;
                case TypeCode.Double: return true;
                case TypeCode.Decimal: return true;
                case TypeCode.DateTime: return true;
                case TypeCode.Byte: return true;
                case TypeCode.SByte: return true;
                case TypeCode.UInt16: return true;
                case TypeCode.UInt32: return true;
                case TypeCode.UInt64: return true;
                case TypeCode.Char: return true;
                default:
                    if (type == typeof(XmlQualifiedName))
                        return true;
                    else if (type == typeof(byte[]))
                        return true;
                    else if (type == typeof(Guid))
                        return true;
                    else if (type == typeof (TimeSpan))
                        return true;
                    else if (type == typeof(XmlNode[]))
                        return true;
                    break;
             }
            return false;
        }

Usage Example

Example #1
0
 internal void AddImport(Type type, Hashtable types)
 {
     if (((type != null) && !TypeScope.IsKnownType(type)) && (types[type] == null))
     {
         types[type] = type;
         Type baseType = type.BaseType;
         if (baseType != null)
         {
             this.AddImport(baseType, types);
         }
         Type declaringType = type.DeclaringType;
         if (declaringType != null)
         {
             this.AddImport(declaringType, types);
         }
         foreach (Type type4 in type.GetInterfaces())
         {
             this.AddImport(type4, types);
         }
         ConstructorInfo[] constructors = type.GetConstructors();
         for (int i = 0; i < constructors.Length; i++)
         {
             ParameterInfo[] parameters = constructors[i].GetParameters();
             for (int j = 0; j < parameters.Length; j++)
             {
                 this.AddImport(parameters[j].ParameterType, types);
             }
         }
         if (type.IsGenericType)
         {
             Type[] genericArguments = type.GetGenericArguments();
             for (int k = 0; k < genericArguments.Length; k++)
             {
                 this.AddImport(genericArguments[k], types);
             }
         }
         TempAssembly.FileIOPermission.Assert();
         Assembly a = type.Module.Assembly;
         if (DynamicAssemblies.IsTypeDynamic(type))
         {
             DynamicAssemblies.Add(a);
         }
         else
         {
             object[] customAttributes = type.GetCustomAttributes(typeof(TypeForwardedFromAttribute), false);
             if (customAttributes.Length > 0)
             {
                 TypeForwardedFromAttribute attribute = customAttributes[0] as TypeForwardedFromAttribute;
                 Assembly assembly2 = Assembly.Load(attribute.AssemblyFullName);
                 this.imports[assembly2] = assembly2.Location;
             }
             this.imports[a] = a.Location;
         }
     }
 }
All Usage Examples Of System.Xml.Serialization.TypeScope::IsKnownType