public Type DefineType(Type type)
        {
            Type type1;
            Type fromCache = ControlEditingDesignTypeGenerator.GetFromCache(type);

            if (fromCache != null)
            {
                return(fromCache);
            }
            if (type == null || type.IsArray || type.IsGenericType || type.IsInterface || type.IsNested || !PlatformTypes.Control.IsAssignableFrom(this.typeResolver.GetType(type)))
            {
                return(type);
            }
            try
            {
                Type            baseType    = type;
                ConstructorInfo constructor = null;
                while (baseType != null)
                {
                    if (!baseType.IsSealed)
                    {
                        constructor = baseType.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null);
                        if (constructor != null && (constructor.IsPublic || constructor.IsFamily))
                        {
                            break;
                        }
                    }
                    baseType = baseType.BaseType;
                }
                TypeAttributes attributes = TypeAttributes.Public | type.Attributes & (TypeAttributes.VisibilityMask | TypeAttributes.Public | TypeAttributes.NestedPublic | TypeAttributes.NestedPrivate | TypeAttributes.NestedFamily | TypeAttributes.NestedAssembly | TypeAttributes.NestedFamANDAssem | TypeAttributes.NestedFamORAssem | TypeAttributes.LayoutMask | TypeAttributes.SequentialLayout | TypeAttributes.ExplicitLayout | TypeAttributes.ClassSemanticsMask | TypeAttributes.Interface | TypeAttributes.Abstract | TypeAttributes.Sealed | TypeAttributes.SpecialName | TypeAttributes.Import | TypeAttributes.Serializable | TypeAttributes.WindowsRuntime | TypeAttributes.StringFormatMask | TypeAttributes.UnicodeClass | TypeAttributes.AutoClass | TypeAttributes.CustomFormatClass | TypeAttributes.CustomFormatMask | TypeAttributes.BeforeFieldInit) & (TypeAttributes.VisibilityMask | TypeAttributes.Public | TypeAttributes.NestedPublic | TypeAttributes.NestedPrivate | TypeAttributes.NestedFamily | TypeAttributes.NestedAssembly | TypeAttributes.NestedFamANDAssem | TypeAttributes.NestedFamORAssem | TypeAttributes.LayoutMask | TypeAttributes.SequentialLayout | TypeAttributes.ExplicitLayout | TypeAttributes.ClassSemanticsMask | TypeAttributes.Interface | TypeAttributes.Abstract | TypeAttributes.Sealed | TypeAttributes.SpecialName | TypeAttributes.Import | TypeAttributes.Serializable | TypeAttributes.WindowsRuntime | TypeAttributes.StringFormatMask | TypeAttributes.UnicodeClass | TypeAttributes.AutoClass | TypeAttributes.CustomFormatClass | TypeAttributes.CustomFormatMask | TypeAttributes.BeforeFieldInit | TypeAttributes.ReservedMask | TypeAttributes.RTSpecialName | TypeAttributes.HasSecurity) & (TypeAttributes.VisibilityMask | TypeAttributes.Public | TypeAttributes.NestedPublic | TypeAttributes.NestedPrivate | TypeAttributes.NestedFamily | TypeAttributes.NestedAssembly | TypeAttributes.NestedFamANDAssem | TypeAttributes.NestedFamORAssem | TypeAttributes.LayoutMask | TypeAttributes.SequentialLayout | TypeAttributes.ExplicitLayout | TypeAttributes.ClassSemanticsMask | TypeAttributes.Interface | TypeAttributes.Sealed | TypeAttributes.SpecialName | TypeAttributes.Import | TypeAttributes.Serializable | TypeAttributes.WindowsRuntime | TypeAttributes.StringFormatMask | TypeAttributes.UnicodeClass | TypeAttributes.AutoClass | TypeAttributes.CustomFormatClass | TypeAttributes.CustomFormatMask | TypeAttributes.BeforeFieldInit | TypeAttributes.ReservedMask | TypeAttributes.RTSpecialName | TypeAttributes.HasSecurity);
                string         str        = this.CreateUniqueTypeName(type);
                RuntimeGeneratedTypesHelper.EnsureControlEditingDesignTypeAssembly(this.typeResolver.PlatformMetadata as IPlatformTypes);
                TypeBuilder      typeBuilder      = RuntimeGeneratedTypesHelper.ControlEditingDesignTypeAssembly.DefineType(str, attributes, baseType);
                BuildingTypeInfo buildingTypeInfo = new BuildingTypeInfo()
                {
                    SourceType  = type,
                    DesignType  = typeBuilder,
                    Constructor = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes)
                };
                ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Private | MethodAttributes.Static | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, CallingConventions.Standard, Type.EmptyTypes);
                buildingTypeInfo.IsReplacement = true;
                buildingTypeInfo.BaseTypeInfo  = new BuildingTypeInfo()
                {
                    SourceType    = baseType,
                    DesignType    = baseType,
                    IsReplacement = false
                };
                DesignTypeGenerator.DefineAbstractMethods(buildingTypeInfo);
                ILGenerator lGenerator = ((ConstructorBuilder)buildingTypeInfo.Constructor).GetILGenerator();
                lGenerator.Emit(OpCodes.Ldarg_0);
                lGenerator.Emit(OpCodes.Call, constructor);
                ILGenerator    lGenerator1 = constructorBuilder.GetILGenerator();
                BindingFlags   bindingFlag = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
                PropertyInfo[] properties  = type.GetProperties(bindingFlag);
                for (int i = 0; i < (int)properties.Length; i++)
                {
                    PropertyInfo propertyInfo = properties[i];
                    PropertyInfo property     = baseType.GetProperty(propertyInfo.Name, bindingFlag);
                    if (!(property != null) || !(property.PropertyType == propertyInfo.PropertyType))
                    {
                        this.DefineProperty(propertyInfo, typeBuilder, type, lGenerator1);
                    }
                }
                lGenerator1.Emit(OpCodes.Ret);
                lGenerator.Emit(OpCodes.Ret);
                Type type2 = typeBuilder.CreateType();
                ControlEditingDesignTypeGenerator.AddToCache(type, type2);
                type1 = type2;
            }
            catch (Exception exception)
            {
                type1 = type;
            }
            return(type1);
        }