示例#1
0
        public TypeCache(Type type, bool caseSensitiveMembers = false)
        {
            var comparer = caseSensitiveMembers ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase;

            Cache = new Dictionary <string, MemberInfo>(comparer);

            try
            {
                TypeInfo = type.GetTypeInfo();
                foreach (var m in TypeInfo.GetMembers(BindingFlags.Instance | BindingFlags.Public))
                {
                    //Prevent error on multiple cctor
                    if (!(Cache.ContainsKey(m.Name)))
                    {
                        Cache.Add(m.Name, m);
                    }
                }
            }
            catch (Exception ex)
            {
                DebugExtensions.DebugHere();
            }
        }
示例#2
0
        /// <summary>
        /// Render within target file, instead of into a separate file
        /// </summary>
        /// <remarks></remarks>
        private void RenderWithinTarget()
        {
            var undoCtx = DTE.UndoContext;

            undoCtx.Open(AttrType.Name, false);
            try {
                //render shared library. It has to be created before the interface can be added to the classes. Otherwise EnvDte would throw exception
                RenderLibrary();

                var validClasses = GetValidClasses();

                var sw       = new Stopwatch();
                var hasError = false;
                //!for each class
                foreach (var cc in validClasses)
                {
                    sw.Start();

                    var classWriter = new Writer()
                    {
                        Class = cc
                    };

                    //!generate
                    GenerateInClass(classWriter);

                    //!if also doing derivedClasses
                    if (classWriter.GenAttribute.ApplyToDerivedClasses)
                    {
                        //!for each subclass
                        foreach (var derivedC in cc.GetSubclasses())
                        {
                            var childInfo = new Writer()
                            {
                                TriggeringBaseClass = cc, Class = derivedC
                            };
                            //generate
                            GenerateInClass(childInfo);
                            //combine status
                            if (childInfo.HasError)
                            {
                                classWriter.HasError = true;
                                classWriter.Status.AppendLine(childInfo.Status.ToString());
                            }
                        }
                    }

                    //if there's error
                    if (classWriter.HasError)
                    {
                        hasError = true;
                        MessageBox.Show(classWriter.Status.ToString());
                    }
                    //finish up
                    sw.Stop();
                    DebugWriteLine(string.Format("Finished {0} in {1}", cc.Name, sw.Elapsed));
                    sw.Reset();
                }


                //if there's error
                if (hasError)
                {
                    //undo everything
                    undoCtx.SetAborted();
                }
                else
                {
                    undoCtx.Close();
                    //automatically save, since we are changing the target file
                    var doc = ProjectItem.DteObject.Document;
                    //if anything is changed, save
                    if (doc != null && !doc.Saved)
                    {
                        doc.Save();
                    }
                }
            }
            catch (Exception ex)
            {
                DebugExtensions.DebugHere();
                if (undoCtx.IsOpen)
                {
                    undoCtx.SetAborted();
                }
            }
        }