public void OnTypeCloned(IDesignTypeGeneratorContext context, BuildingTypeInfo typeInfo)
 {
     if (this.IsSpecialCollection(typeInfo))
     {
         (new CollectionGenerator(this.platformMetadata, typeInfo)).EmitCollectionImplementation(context);
     }
 }
        public bool ShouldReflectProperty(IDesignTypeGeneratorContext context, BuildingTypeInfo typeInfo, PropertyInfo sourceProperty)
        {
            if (!this.IsSpecialCollection(typeInfo))
            {
                return(true);
            }
            PropertyInfo property = typeof(IList <>).GetProperty(sourceProperty.Name);

            if (property == null)
            {
                property = typeof(IList).GetProperty(sourceProperty.Name);
                if (property == null)
                {
                    return(true);
                }
            }
            if (sourceProperty.Name == "Items")
            {
                ParameterInfo[] indexParameters = property.GetIndexParameters();
                if ((int)indexParameters.Length != 1 || indexParameters[0].ParameterType != typeof(int))
                {
                    return(true);
                }
            }
            return(false);
        }
 public bool ShouldReflectMethod(IDesignTypeGeneratorContext context, BuildingTypeInfo typeInfo, MethodInfo sourceMethod)
 {
     if (sourceMethod.Name == "Clear" && sourceMethod.ReturnType == typeof(void) && this.IsSpecialCollection(typeInfo) && (int)sourceMethod.GetParameters().Length == 0)
     {
         return(false);
     }
     return(true);
 }
示例#4
0
 public CollectionGenerator(IPlatformMetadata platformMetadata, BuildingTypeInfo typeInfo)
 {
     this.platformMetadata         = platformMetadata;
     this.typeInfo                 = typeInfo;
     this.designType               = (TypeBuilder)typeInfo.DesignType;
     this.sourceType               = typeInfo.SourceType;
     this.ctorGenerator            = ((ConstructorBuilder)typeInfo.Constructor).GetILGenerator();
     this.observableCollectionType = this.platformMetadata.ResolveType(PlatformTypes.ObservableCollection).RuntimeType;
 }
        private bool IsSpecialCollection(BuildingTypeInfo typeInfo)
        {
            object obj;
            bool   flag = false;

            if (typeInfo.DesignType is TypeBuilder)
            {
                if (!typeInfo.Extensions.TryGetValue(this, out obj))
                {
                    flag = this.IsComplexTypeWithCollectionInterfaces(typeInfo.SourceType);
                    typeInfo.Extensions[this] = flag;
                }
                else
                {
                    flag = (bool)obj;
                }
            }
            return(flag);
        }
示例#6
0
        private static string GetTypeDisplayName(Type type)
        {
            string str = string.Concat(BuildingTypeInfo.GetDesignPrefix(type), type.Name);

            if (type.IsArray)
            {
                Type arrayItemType = DesignTypeGenerator.GetArrayItemType(type);
                if (arrayItemType != null)
                {
                    str = string.Concat(BuildingTypeInfo.GetTypeDisplayName(arrayItemType), "[]");
                    string designPrefix = BuildingTypeInfo.GetDesignPrefix(arrayItemType);
                    if (string.IsNullOrEmpty(designPrefix))
                    {
                        str = string.Concat(designPrefix, str);
                    }
                }
            }
            if (!type.IsGenericType)
            {
                return(str);
            }
            int num = str.IndexOf('\u0060');

            if (num > 0)
            {
                str = str.Substring(0, num);
            }
            str = string.Concat(str, "<");
            Type[] genericArguments = type.GetGenericArguments();
            for (int i = 0; i < (int)genericArguments.Length; i++)
            {
                if (i > 0)
                {
                    str = string.Concat(str, ", ");
                }
                string typeDisplayName = BuildingTypeInfo.GetTypeDisplayName(genericArguments[i]);
                str = string.Concat(str, typeDisplayName);
            }
            str = string.Concat(str, ">");
            return(str);
        }
        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);
        }