TypeRequiresRegistration() private method

private TypeRequiresRegistration ( Type type ) : bool
type System.Type
return bool
 public void CheckAssemblySCValidity(Assembly asm)
 {
     Type[] types = null;
     bool flag = true;
     ArrayList list = null;
     RegistrationServices services = new RegistrationServices();
     try
     {
         types = asm.GetTypes();
     }
     catch (ReflectionTypeLoadException exception)
     {
         types = exception.Types;
     }
     foreach (Type type in types)
     {
         if (((null != type) && type.IsClass) && type.IsSubclassOf(typeof(ServicedComponent)))
         {
             if (!services.TypeRequiresRegistration(type) && !type.IsAbstract)
             {
                 flag = false;
                 if (list == null)
                 {
                     list = new ArrayList();
                 }
                 RegistrationErrorInfo info = new RegistrationErrorInfo(null, null, type.ToString(), -2147467259);
                 list.Add(info);
             }
             ClassInterfaceType classInterfaceType = ServicedComponentInfo.GetClassInterfaceType(type);
             foreach (MethodInfo info2 in type.GetMethods())
             {
                 if (ReflectionCache.ConvertToInterfaceMI(info2) == null)
                 {
                     if (ServicedComponentInfo.HasSpecialMethodAttributes(info2))
                     {
                         this.ReportWarning(Resource.FormatString("Reg_NoClassInterfaceSecure", type.FullName, info2.Name));
                     }
                     if ((classInterfaceType == ClassInterfaceType.AutoDispatch) && ServicedComponentInfo.IsMethodAutoDone(info2))
                     {
                         this.ReportWarning(Resource.FormatString("Reg_NoClassInterface", type.FullName, info2.Name));
                     }
                 }
             }
         }
     }
     if (!flag)
     {
         RegistrationErrorInfo[] errorInfo = (RegistrationErrorInfo[]) list.ToArray(typeof(RegistrationErrorInfo));
         throw new RegistrationException(Resource.FormatString("Reg_InvalidServicedComponents"), errorInfo);
     }
 }
コード例 #2
0
        static void WriteTypes(Stream s, Type[] aTypes, int offset)
        {
            RegistrationServices regServices = new RegistrationServices();
            String name = null;

            Assembly asm = Assembly.GetExecutingAssembly();
            string asmver = asm.ImageRuntimeVersion;


            foreach (Type t in aTypes)
            {
                // only registrable managed types will show up in the manifest file
                if (!regServices.TypeRequiresRegistration(t))
                {
                    throw Fx.AssertAndThrow("User defined types must be registrable");
                }
                
                String strClsId = "{" + Marshal.GenerateGuidForType(t).ToString().ToUpperInvariant() + "}";
                name = t.FullName;

                // this type is a com imported type or Record
                if (regServices.TypeRepresentsComType(t) || t.IsValueType)
                {
                    WriteUTFChars(s, "<clrSurrogate" + Environment.NewLine, offset);
                    // attribute clsid
                    WriteUTFChars(s, "    clsid=\"" + strClsId + "\"" + Environment.NewLine, offset);    
                    
                    // attribute class
                    WriteUTFChars(s, "    name=\"" + name + "\"" + Environment.NewLine, offset);
                    // clr version
                    WriteUTFChars(s, "    runtimeVersion=\"" + asmver + "\">" + Environment.NewLine, offset);

                    WriteUTFChars(s, "</clrSurrogate>" + Environment.NewLine, offset);
                }                
            }
        }
 private static void WriteTypes(Stream s, Type[] aTypes, int offset)
 {
     RegistrationServices services = new RegistrationServices();
     string fullName = null;
     string imageRuntimeVersion = Assembly.GetExecutingAssembly().ImageRuntimeVersion;
     foreach (Type type in aTypes)
     {
         if (!services.TypeRequiresRegistration(type))
         {
             throw Fx.AssertAndThrow("User defined types must be registrable");
         }
         string str3 = "{" + Marshal.GenerateGuidForType(type).ToString().ToUpperInvariant() + "}";
         fullName = type.FullName;
         if (services.TypeRepresentsComType(type) || type.IsValueType)
         {
             WriteUTFChars(s, "<clrSurrogate" + Environment.NewLine, offset);
             WriteUTFChars(s, "    clsid=\"" + str3 + "\"" + Environment.NewLine, offset);
             WriteUTFChars(s, "    name=\"" + fullName + "\"" + Environment.NewLine, offset);
             WriteUTFChars(s, "    runtimeVersion=\"" + imageRuntimeVersion + "\">" + Environment.NewLine, offset);
             WriteUTFChars(s, "</clrSurrogate>" + Environment.NewLine, offset);
         }
     }
 }