Exemplo n.º 1
0
        internal static bool BuildFileType(string fileTypeCode, bool debug)
        {
            builtFileType = null;

            const string projectName = "MyFileType";

            UIElement[] userControls = UIElement.ProcessUIControls(fileTypeCode, ProjectType.FileType);

            string sourceCode =
                ScriptWriter.UsingPartCode(ProjectType.FileType) +
                ScriptWriter.NamespacePart(projectName, ProjectType.FileType) +
                ScriptWriter.FileTypePart(projectName, "\".foo\"", "\".foo\"", false, projectName) +
                ScriptWriter.ConstructorPart(debug) +
                ScriptWriter.PropertyPart(userControls, projectName, string.Empty, HelpType.None, string.Empty, ProjectType.FileType) +
                ScriptWriter.FileTypePart2(userControls) +
                ScriptWriter.UserEnteredPart(fileTypeCode) +
                ScriptWriter.EndPart();

            Assembly assembly = CreateAssembly(sourceCode, debug);

            if (assembly == null)
            {
                return(false);
            }

            Intelli.UserDefinedTypes.Clear();

            foreach (Type type in assembly.GetTypes())
            {
                if (type.IsSubclassOf(typeof(PropertyBasedFileType)) && !type.IsAbstract)
                {
                    builtFileType = (FileType)type.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance)[0].Invoke(null);
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        internal static bool Build(string scriptText, bool debug)
        {
            builtEffect = null;

            string SourceCode =
                ScriptWriter.UsingPartCode(ProjectType.Effect) +
                ScriptWriter.prepend_code +
                ScriptWriter.ConstructorPart(debug) +
                ScriptWriter.SetRenderPart(Array.Empty <UIElement>(), false, preRenderRegex.IsMatch(scriptText)) +
                ScriptWriter.UserEnteredPart(scriptText) +
                ScriptWriter.append_code;

            Assembly assembly = CreateAssembly(SourceCode, debug);

            if (assembly == null)
            {
                return(false);
            }

            Intelli.UserDefinedTypes.Clear();

            foreach (Type type in assembly.GetTypes())
            {
                if (type.IsSubclassOf(typeof(Effect)) && !type.IsAbstract)
                {
                    builtEffect        = (Effect)type.GetConstructor(Type.EmptyTypes).Invoke(null);
                    Intelli.UserScript = type;
                }
                else if (type.DeclaringType != null && type.DeclaringType.FullName.StartsWith(Intelli.UserScriptFullName, StringComparison.Ordinal) && !Intelli.UserDefinedTypes.ContainsKey(type.Name))
                {
                    Intelli.UserDefinedTypes.Add(type.Name, type);
                }
            }

            return(builtEffect != null);
        }