static RuntimeGeneratedTypesHelper()
 {
     RuntimeGeneratedTypesHelper.blendAssemblies               = new List <IAssembly>();
     RuntimeGeneratedTypesHelper.controlEditingAssemblies      = new List <IAssembly>();
     RuntimeGeneratedTypesHelper.assembliesInitialized         = new Dictionary <IPlatformTypes, HashSet <IAssembly> >();
     RuntimeGeneratedTypesHelper.RuntimeGeneratedTypesAssembly = RuntimeGeneratedTypesHelper.CreateNewAssembly();
     RuntimeGeneratedTypesHelper.BlendDefaultAssembly          = new Microsoft.Expression.DesignModel.Metadata.RuntimeAssembly(RuntimeGeneratedTypesHelper.RuntimeGeneratedTypesAssembly.Assembly, AssemblySource.Unknown, false);
     RuntimeGeneratedTypesHelper.blendAssemblies.Add(RuntimeGeneratedTypesHelper.BlendDefaultAssembly);
 }
 public static void EnsureControlEditingDesignTypeAssembly(IPlatformTypes platformMetadata)
 {
     if (RuntimeGeneratedTypesHelper.controlEditingDesignTypeAssembly == null)
     {
         RuntimeGeneratedTypesHelper.controlEditingDesignTypeAssembly = RuntimeGeneratedTypesHelper.CreateNewAssembly();
         RuntimeGeneratedTypesHelper.BlendControlEditingAssembly      = new Microsoft.Expression.DesignModel.Metadata.RuntimeAssembly(RuntimeGeneratedTypesHelper.controlEditingDesignTypeAssembly.Assembly, AssemblySource.Unknown, false);
         RuntimeGeneratedTypesHelper.blendAssemblies.Add(RuntimeGeneratedTypesHelper.BlendControlEditingAssembly);
         RuntimeGeneratedTypesHelper.controlEditingAssemblies.Add(RuntimeGeneratedTypesHelper.BlendControlEditingAssembly);
         RuntimeGeneratedTypesHelper.RegisterRuntimeAssemblies(platformMetadata);
     }
 }
Exemple #3
0
        protected virtual void OnAssemblyCollectionChanged(NotifyCollectionChangedEventArgs e)
        {
            TypeResolver typeResolver = this;

            typeResolver.versionStamp = typeResolver.versionStamp + 1;
            bool flag = false;
            ICollection <IAssembly> platformAssemblies = this.PlatformAssemblies;
            ICollection <IAssembly> libraryAssemblies  = this.LibraryAssemblies;
            List <IAssembly>        assemblies         = new List <IAssembly>();
            List <IAssembly>        assemblies1        = new List <IAssembly>();

            if (this.invalidatingAssemblies != null)
            {
                assemblies.AddRange(
                    from assembly in this.invalidatingAssemblies
                    where !this.AssemblyReferences.Contains(assembly)
                    select assembly);
                assemblies1.AddRange(
                    from assembly in this.AssemblyReferences
                    where !this.invalidatingAssemblies.Contains(assembly)
                    select assembly);
                this.invalidatingAssemblies = null;
            }
            HashSet <IAssembly> assemblies2 = new HashSet <IAssembly>((
                                                                          from libraryAssembly in libraryAssemblies
                                                                          where !TypeResolver.ShouldRefreshLibraryAssembly(assemblies, assemblies1, libraryAssembly)
                                                                          select libraryAssembly).Concat <IAssembly>(platformAssemblies));
            HashSet <ProjectContextType> projectContextTypes = new HashSet <ProjectContextType>(
                from type in this.typeIds.Values
                where TypeResolver.ShouldRefreshType(type, assemblies2)
                select type);

            if (e.Action == NotifyCollectionChangedAction.Reset)
            {
                RuntimeGeneratedTypesHelper.ClearControlEditingDesignTypeAssembly();
            }
            foreach (ProjectContextType projectContextType in projectContextTypes)
            {
                if (projectContextType.Refresh())
                {
                    continue;
                }
                flag = true;
            }
            if (flag)
            {
                IList <string> list = (
                    from keyValuePair in this.typeIds
                    where projectContextTypes.Contains(keyValuePair.Value)
                    select keyValuePair.Key).ToList <string>();
                for (int i = 0; i < list.Count; i++)
                {
                    this.typeIds.Remove(list[i]);
                }
                this.typeMetadataFactory.Reset();
            }
            List <IAssembly> assemblies3 = new List <IAssembly>();

            if (flag)
            {
                assemblies3.AddRange(this.AssemblyReferences.Where <IAssembly>((IAssembly assembly) => {
                    if (assemblies1.Contains(assembly) || assemblies.Contains(assembly) || platformAssemblies.Contains(assembly))
                    {
                        return(false);
                    }
                    return(!libraryAssemblies.Contains(assembly));
                }));
            }
            List <TypeChangedInfo> typeChangedInfos = new List <TypeChangedInfo>();

            typeChangedInfos.AddRange(
                from assembly in assemblies
                select new TypeChangedInfo(assembly, ModificationType.Removed));
            typeChangedInfos.AddRange(
                from assembly in assemblies1
                select new TypeChangedInfo(assembly, ModificationType.Added));
            typeChangedInfos.AddRange(
                from assembly in assemblies3
                select new TypeChangedInfo(assembly, ModificationType.Modified));
            this.OnTypesChanged(new TypesChangedEventArgs(new ReadOnlyCollection <TypeChangedInfo>(typeChangedInfos)));
        }
Exemple #4
0
 protected void Initialize(IPlatformTypes platformTypes)
 {
     this.platformTypes       = platformTypes;
     this.typeMetadataFactory = this.platformTypes.CreateTypeMetadataFactory(this);
     RuntimeGeneratedTypesHelper.ClearControlEditingDesignTypeAssembly();
 }
        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);
        }
Exemple #6
0
        private Type GetRuntimeType(ITypeResolver typeResolver, ProjectContextType typeId)
        {
            Type type;

            if (RuntimeGeneratedTypesHelper.IsControlEditingAssembly(typeId.assembly))
            {
                Type sourceType = ControlEditingDesignTypeGenerator.GetSourceType(typeId.RuntimeType);
                if (sourceType != null)
                {
                    ProjectContextType projectContextType = typeResolver.GetType(sourceType) as ProjectContextType;
                    if (projectContextType != null)
                    {
                        Type runtimeType = projectContextType.GetRuntimeType();
                        if (runtimeType != sourceType && runtimeType != null)
                        {
                            Type type1 = (new ControlEditingDesignTypeGenerator(typeResolver)).DefineType(runtimeType);
                            if (type1 != typeId.RuntimeType)
                            {
                                this.assemblyName = AssemblyHelper.GetAssemblyName(type1.Assembly).Name;
                                this.assembly     = this.GetAssembly(this.typeResolver, this.assemblyName);
                                return(type1);
                            }
                        }
                    }
                }
            }
            if (typeId.arrayItemType == null)
            {
                IAssembly runtimeAssembly = typeId.RuntimeAssembly;
                if (runtimeAssembly != null)
                {
                    runtimeAssembly = this.GetAssembly(typeResolver, runtimeAssembly.Name);
                }
                if (runtimeAssembly != null)
                {
                    Type type2 = PlatformTypeHelper.GetType(runtimeAssembly, typeId.FullName);
                    if (type2 != null)
                    {
                        if (!typeId.IsGenericType)
                        {
                            return(type2);
                        }
                        IList <IType> genericTypeArguments = typeId.GetGenericTypeArguments();
                        int           count = genericTypeArguments.Count;
                        if (count > 0)
                        {
                            Type[] typeArray = new Type[count];
                            for (int i = 0; i < count; i++)
                            {
                                Type runtimeType1 = this.GetRuntimeType(genericTypeArguments[i]);
                                if (runtimeType1 == null)
                                {
                                    return(null);
                                }
                                typeArray[i] = runtimeType1;
                            }
                            try
                            {
                                type = type2.MakeGenericType(typeArray);
                            }
                            catch (ArgumentException argumentException)
                            {
                                return(null);
                            }
                            return(type);
                        }
                    }
                }
            }
            else
            {
                Type runtimeType2 = this.GetRuntimeType(typeId.arrayItemType);
                if (runtimeType2 != null)
                {
                    if (typeId.arrayRank <= 1)
                    {
                        return(runtimeType2.MakeArrayType());
                    }
                    return(runtimeType2.MakeArrayType(typeId.arrayRank));
                }
            }
            return(null);
        }