示例#1
0
        private string CheckStatic()
        {
            if (HasIntrinsicTypeOverride)
            {
                return(null);
            }

            if (CILType.IsArray)
            {
                TypeDescriptor tdref      = GetElement0Type();
                string         innerCheck = tdref.CheckStatic();
                if (innerCheck != null)
                {
                    return(innerCheck);
                }
                if (_sample == null)
                {
                    return("No sample - not able to determine whether type descriptor is static");
                }
                Array array   = (Array)_sample;
                int[] indices = new int[array.Rank];
                do
                {
                    object elem = array.GetValue(indices);
                    if (elem == null)
                    {
                        return("Null array element");
                    }

                    TypeDescriptor td = new TypeDescriptor(elem);
                    if (!tdref.Equals(td))
                    {
                        return("Different element types in array");
                    }

                    int dim;
                    for (dim = 0; dim < indices.Length; dim++)
                    {
                        ++indices[dim];
                        if (indices[dim] < array.GetLength(dim))
                        {
                            break;
                        }
                        indices[dim] = 0;
                    }
                    if (dim == indices.Length)
                    {
                        break;
                    }
                }while (true);

                return(null);
            }
            else
            {
                if (!CILType.IsValueType && !CILType.IsPrimitive)
                {
                    return("Type is neither primitive nor a value type");
                }

                TypeDescriptor[] deps = GetDependentTypes();
                foreach (TypeDescriptor dep in deps)
                {
                    string innerCheck = dep.CheckStatic();
                    if (innerCheck != null)
                    {
                        return(innerCheck);
                    }
                }

                return(null);
            }
        }