public bool PropertyExists(PropertyInfo sourceProperty)
 {
     if (sourceProperty.Name.IndexOf('.') >= 0)
     {
         return(true);
     }
     for (int i = 0; i < this.designProperties.Count; i++)
     {
         KeyValuePair <PropertyBuilder, PropertyInfo> item = this.designProperties[i];
         if (item.Value == sourceProperty)
         {
             return(true);
         }
         if (!(item.Key.Name != sourceProperty.Name) && object.Equals(item.Key.PropertyType, sourceProperty.PropertyType))
         {
             if (item.Value == null)
             {
                 return(true);
             }
             if (DesignTypeGenerator.CompareParameters(item.Value.GetIndexParameters(), sourceProperty.GetIndexParameters()))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
 public bool MethodExists(MethodInfo sourceMethod)
 {
     if (sourceMethod.Name.IndexOf('.') >= 0)
     {
         return(true);
     }
     for (int i = 0; i < this.designMethods.Count; i++)
     {
         KeyValuePair <MethodBuilder, MethodInfo> item = this.designMethods[i];
         if (item.Value == sourceMethod)
         {
             return(true);
         }
         if (!(item.Key.Name != sourceMethod.Name) && object.Equals(item.Key.ReturnType, sourceMethod.ReturnType))
         {
             if (item.Value == null)
             {
                 return(true);
             }
             if (DesignTypeGenerator.CompareParameters(item.Value.GetParameters(), sourceMethod.GetParameters()))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        public Type GetDesignType(IDesignTypeGeneratorContext context, Type runtimeType)
        {
            if (runtimeType == null)
            {
                return(runtimeType);
            }
            if (PlatformTypes.IsExpressionInteractiveType(runtimeType))
            {
                return(runtimeType);
            }
            if (runtimeType.IsPrimitive || runtimeType.IsGenericParameter)
            {
                return(runtimeType);
            }
            if (!this.IsCorePlatformType(runtimeType))
            {
                return(null);
            }
            Type replacementForPlatformType = this.GetReplacementForPlatformType(runtimeType);

            if (replacementForPlatformType != null)
            {
                return(replacementForPlatformType);
            }
            if (runtimeType.IsInterface)
            {
                return(null);
            }
            if (!runtimeType.IsGenericType)
            {
                if (runtimeType.IsArray && this.GetDesignType(context, DesignTypeGenerator.GetArrayItemType(runtimeType)) == null)
                {
                    return(null);
                }
                return(runtimeType);
            }
            Type[] genericArguments = runtimeType.GetGenericArguments();
            for (int i = 0; i < (int)genericArguments.Length; i++)
            {
                if (this.GetDesignType(context, genericArguments[i]) == null)
                {
                    return(null);
                }
            }
            return(runtimeType);
        }
        public static IType GetSourceType(IType type, ITypeResolver typeResolver)
        {
            if (typeResolver.PlatformMetadata.IsNullType((ITypeId)type))
            {
                return(type);
            }
            DesignTypeResult designTypeResult = DesignTypeGenerator.LookupGetDesignTypeResult(type.RuntimeType);

            if (designTypeResult != null && !designTypeResult.IsFailed && designTypeResult.SourceType != type.RuntimeType)
            {
                ITypeResolver typeResolver1 = (ITypeResolver)ProjectXamlContext.FromProjectContext(typeResolver as IProjectContext) ?? typeResolver;
                IType         type1         = typeResolver1.GetType(designTypeResult.SourceType);
                if (!typeResolver1.PlatformMetadata.IsNullType((ITypeId)type1))
                {
                    return(type1);
                }
            }
            return(type);
        }
        private bool IsComplexTypeWithCollectionInterfaces(Type originalType)
        {
            Type baseType = originalType.BaseType;

            if (baseType == null || baseType == this.objectType)
            {
                return(false);
            }
            Type genericTypeDefinition = baseType;

            if (baseType.IsGenericType && !baseType.IsGenericTypeDefinition)
            {
                genericTypeDefinition = baseType.GetGenericTypeDefinition();
            }
            for (int i = 0; i < this.collectionTypes.Count; i++)
            {
                Type item = this.collectionTypes[i];
                if (item.IsAssignableFrom(genericTypeDefinition) || item.IsAssignableFrom(baseType))
                {
                    return(false);
                }
            }
            Type[] implementedInterfaces = DesignTypeGenerator.GetImplementedInterfaces(originalType);
            for (int j = 0; j < (int)implementedInterfaces.Length; j++)
            {
                Type type = implementedInterfaces[j];
                Type genericTypeDefinition1 = type;
                if (type.IsGenericType && !type.IsGenericTypeDefinition)
                {
                    genericTypeDefinition1 = type.GetGenericTypeDefinition();
                }
                for (int k = 0; k < this.collectionTypes.Count; k++)
                {
                    Type item1 = this.collectionTypes[k];
                    if (item1.IsAssignableFrom(genericTypeDefinition1) || item1.IsAssignableFrom(type))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        private Type GetReplacementCollectionType(Type type)
        {
            if (type.IsArray)
            {
                if (type.GetArrayRank() == 1)
                {
                    Type arrayItemType = DesignTypeGenerator.GetArrayItemType(type);
                    if (arrayItemType != null)
                    {
                        return(this.replacementCollectionType.MakeGenericType(new Type[] { arrayItemType }));
                    }
                }
                return(null);
            }
            Type genericTypeDefinition = type;

            if (type.IsGenericType && !type.IsGenericTypeDefinition)
            {
                genericTypeDefinition = type.GetGenericTypeDefinition();
            }
            if (!this.collectionTypes.Contains(genericTypeDefinition))
            {
                if (!this.baseCollectionType.IsAssignableFrom(genericTypeDefinition))
                {
                    return(null);
                }
                ConstructorInfo constructor = genericTypeDefinition.GetConstructor(Type.EmptyTypes);
                if (constructor != null && constructor.IsPublic)
                {
                    return(null);
                }
            }
            Type type1 = this.replacementCollectionType;

            if (!type.IsGenericType)
            {
                Type   type2     = this.replacementCollectionType;
                Type[] typeArray = new Type[] { this.objectType };
                type1 = type2.MakeGenericType(typeArray);
            }
            return(type1);
        }
        public static DesignTypeResult GetTypeToInstantiate(IPlatformMetadata platformMetadata, Type sourceType, bool createList, bool isDesignTimeCreatable)
        {
            Type designType = sourceType;
            DesignTypeGenerator designTypeGenerator = new DesignTypeGenerator(platformMetadata);

            if (!isDesignTimeCreatable)
            {
                DesignTypeResult designTypeResult = designTypeGenerator.GetDesignType(sourceType);
                if (designTypeResult.IsFailed)
                {
                    return(designTypeResult);
                }
                designType = designTypeResult.DesignType;
            }
            if (!(designType != null) || !createList)
            {
                return(new DesignTypeResult(sourceType, designType));
            }
            return(designTypeGenerator.GetXamlFriendlyListType(designType));
        }
        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 static List <MethodInfo> GetSupportedMethods(ITypeResolver typeResolver, Type type)
        {
            List <MethodInfo> list = new List <MethodInfo>();

            if (!DataBindingDragDropAddTriggerHandler.IsEnabled(typeResolver))
            {
                return(list);
            }
            StringComparison comparison = DataBindingDragDropAddTriggerHandler.GetMethodNameComparison(typeResolver);

            foreach (MethodInfo methodInfo in DesignTypeGenerator.GetCommandMethods(type, typeResolver.PlatformMetadata, true))
            {
                MethodInfo method           = methodInfo;
                object[]   customAttributes = method.GetCustomAttributes(typeof(BrowsableAttribute), true);
                if ((customAttributes.Length <= 0 || ((BrowsableAttribute)customAttributes[0]).Browsable) && list.FindIndex((Predicate <MethodInfo>)(m => string.Compare(method.Name, m.Name, comparison) == 0)) < 0)
                {
                    list.Add(method);
                }
            }
            return(list);
        }
        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);
        }