當前位置: 首頁>>代碼示例>>C#>>正文


C# Reflection.GetSimpleName方法代碼示例

本文整理匯總了C#中System.Reflection.GetSimpleName方法的典型用法代碼示例。如果您正苦於以下問題:C# Reflection.GetSimpleName方法的具體用法?C# Reflection.GetSimpleName怎麽用?C# Reflection.GetSimpleName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Reflection的用法示例。


在下文中一共展示了Reflection.GetSimpleName方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CreateViewModelDescriptors

        private static void CreateViewModelDescriptors(IZetboxContext ctx, SR.Assembly srAssembly)
        {
            using (Logging.Log.InfoTraceMethodCallFormat("CreateViewModelDescriptors", "Creating ViewModelDescriptors"))
            {
                var liveDescriptors = new HashSet<ViewModelDescriptor>();

                foreach (var type in GetTypes(srAssembly))
                {
                    object attr;
                    // http://blogs.msdn.com/b/kaevans/archive/2005/10/24/484186.aspx
                    if (type.Assembly.ReflectionOnly)
                    {
                        attr = SR.CustomAttributeData.GetCustomAttributes(type).FirstOrDefault(i => i.Constructor.DeclaringType.FullName == typeof(ViewModelDescriptorAttribute).FullName);
                    }
                    else
                    {
                        attr = type.GetCustomAttributes(typeof(ViewModelDescriptorAttribute), false).FirstOrDefault() as ViewModelDescriptorAttribute;
                    }
                    if (attr != null)
                    {
                        var typeName = type.GetSimpleName();
                        var descr = ctx.GetQuery<ViewModelDescriptor>().FirstOrDefault(i => i.ViewModelTypeRef == typeName);
                        if (descr == null)
                        {
                            descr = ctx.Create<ViewModelDescriptor>();
                            descr.ViewModelTypeRef = typeName;
                            descr.Description = "TODO: Add description";
                        }
                        else
                        {
                            descr.Deleted = false;
                        }

                        liveDescriptors.Add(descr);
                    }
                }

                var simpleAssemblyName = srAssembly.GetSimpleName();
                var deadDescriptors = ctx
                    .GetQuery<ViewModelDescriptor>()
                    .ToList()
                    .Where(vmd => TypeSpec.Parse(vmd.ViewModelTypeRef).AssemblyName.IfNullOrWhiteSpace(string.Empty).Split(',').FirstOrDefault().IfNullOrWhiteSpace(string.Empty).Trim() == simpleAssemblyName)
                    .Except(liveDescriptors);

                foreach (var d in deadDescriptors)
                {
                    d.Deleted = true;
                }
            }
        }
開發者ID:daszat,項目名稱:zetbox,代碼行數:50,代碼來源:AssemblyActions.cs

示例2: CreateViewDescriptors

        private static void CreateViewDescriptors(IZetboxContext ctx, SR.Assembly srAssembly)
        {
            using (Logging.Log.InfoTraceMethodCallFormat("CreateViewDescriptors", "Creating ViewDescriptors"))
            {
                var liveDescriptors = new HashSet<ViewDescriptor>();

                foreach (var type in GetTypes(srAssembly))
                {
                    object attr;
                    Toolkit? tk = null;
                    // http://blogs.msdn.com/b/kaevans/archive/2005/10/24/484186.aspx
                    if (type.Assembly.ReflectionOnly)
                    {
                        attr = SR.CustomAttributeData.GetCustomAttributes(type).FirstOrDefault(i => i.Constructor.DeclaringType.FullName == typeof(ViewDescriptorAttribute).FullName);
                        if (attr != null) tk = (Toolkit)((SR.CustomAttributeData)attr).ConstructorArguments.Single().Value;
                    }
                    else
                    {
                        attr = type.GetCustomAttributes(typeof(ViewDescriptorAttribute), false).FirstOrDefault() as ViewDescriptorAttribute;
                        if (attr != null) tk = ((ViewDescriptorAttribute)attr).Toolkit;
                    }
                    if (attr != null)
                    {
                        var typeName = type.GetSimpleName();

                        // if a view can be used under multiple ControlKinds, it needs to have multiple ViewDescriptors
                        var descrList = ctx.GetQuery<ViewDescriptor>().Where(i => i.ControlTypeRef == typeName).ToList();
                        if (descrList.Count == 0)
                        {
                            var descr = ctx.Create<ViewDescriptor>();
                            descr.ControlTypeRef = typeName;
                            if (tk != null) descr.Toolkit = tk.Value;
                            liveDescriptors.Add(descr);
                        }
                        else
                        {
                            foreach (var descr in descrList)
                            {
                                descr.Deleted = false;
                                liveDescriptors.Add(descr);
                            }
                        }
                    }
                }

                var simpleAssemblyName = srAssembly.GetSimpleName();
                var deadDescriptors = ctx
                    .GetQuery<ViewDescriptor>()
                    .ToList()
                    .Where(vmd => TypeSpec.Parse(vmd.ControlTypeRef).AssemblyName.IfNullOrWhiteSpace(string.Empty).Split(',').FirstOrDefault().IfNullOrWhiteSpace(string.Empty).Trim() == simpleAssemblyName)
                    .Except(liveDescriptors);
                foreach (var d in deadDescriptors)
                {
                    d.Deleted = true;
                }
            }
        }
開發者ID:daszat,項目名稱:zetbox,代碼行數:57,代碼來源:AssemblyActions.cs


注:本文中的System.Reflection.GetSimpleName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。