当前位置: 首页>>代码示例>>C#>>正文


C# Assembly.GetCustomAttributes方法代码示例

本文整理汇总了C#中System.Reflection.Assembly.GetCustomAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# Assembly.GetCustomAttributes方法的具体用法?C# Assembly.GetCustomAttributes怎么用?C# Assembly.GetCustomAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.Assembly的用法示例。


在下文中一共展示了Assembly.GetCustomAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AboutBSM

        public AboutBSM(Icon icon, Assembly a)
        {
            InitializeComponent();

            if (icon != null) this.Icon = icon;

            if (a != null) {
                software_title.Text = ((AssemblyTitleAttribute)a.GetCustomAttributes(typeof(AssemblyTitleAttribute), false)[0]).Title;
                version.Text = a.GetName().Version.ToString();
                copyright.Text = ((AssemblyCopyrightAttribute)a.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false)[0]).Copyright;

                Assembly b = Assembly.GetAssembly(this.GetType());
                library_title.Text = ((AssemblyTitleAttribute)b.GetCustomAttributes(typeof(AssemblyTitleAttribute), false)[0]).Title;
                library_version.Text = b.GetName().Version.ToString();
                library_copyright.Text = ((AssemblyCopyrightAttribute)b.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false)[0]).Copyright;

                Assembly dll = Assembly.GetAssembly(typeof(BrawlLib.StringTable));
                brawllib.Text = "Using " +
                    ((AssemblyTitleAttribute)dll.GetCustomAttributes(typeof(AssemblyTitleAttribute), false)[0]).Title + "\r\n" +
                    ((AssemblyCopyrightAttribute)dll.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false)[0]).Copyright;

                textBox1.Text = "Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\r\n" +
                "\r\n" +
                "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\r\n" +
                "\r\n" +
                "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.";
            }
        }
开发者ID:liddictm,项目名称:BrawlManagers,代码行数:28,代码来源:AboutBSM.cs

示例2: GetAssemblyInfo

		static string GetAssemblyInfo (Assembly a)
		{
			object[] attrs;
			StringBuilder sb;

			string app_name;
			string evidence_str;
			string version;

			attrs = a.GetCustomAttributes (typeof (AssemblyProductAttribute), false);
			if (attrs != null && attrs.Length > 0)
				app_name = ((AssemblyProductAttribute)attrs[0]).Product;
			else
				app_name = AppDomain.CurrentDomain.FriendlyName;

			sb = new StringBuilder();

			sb.Append ("evidencehere");

			evidence_str = sb.ToString();

			attrs = a.GetCustomAttributes (typeof (AssemblyVersionAttribute), false);
			if (attrs != null && attrs.Length > 0)
				version = ((AssemblyVersionAttribute)attrs[0]).Version;
			else
				version = "1.0.0.0" /* XXX */;


			return Path.Combine (String.Format ("{0}_{1}", app_name, evidence_str), version);
		}
开发者ID:rabink,项目名称:mono,代码行数:30,代码来源:ConfigurationManager.cs

示例3: ModuleInfo

        public ModuleInfo(Assembly _asm)
        {
            _name = _asm.GetName().Name;
            _version = DepVersion.VersionParse (_asm.GetName().Version.ToString ());

            ModuleDependencyAttribute _depAttr = ((ModuleDependencyAttribute)(_asm.GetCustomAttributes (typeof (ModuleDependencyAttribute), false)[0]));

            if (_depAttr != null) {
                DepLexer _lexer = new DepLexer (new StringReader (_depAttr.DepString));
                DepParser _parser = new DepParser (_lexer);

                // woot...lets do this!
                _dependencies = new DepNode ();

                _parser.expr (_dependencies);
            } else
                _dependencies = null;

            ModuleRoleAttribute _roleAttr = ((ModuleRoleAttribute)(_asm.GetCustomAttributes (typeof (ModuleRoleAttribute), false)[0]));

            if (_roleAttr != null) {
                _roles = _roleAttr.Roles;
            } else
                throw new ModuleInfoException (string.Format ("The module {0} has no defined roles, and is not a valid NModule module.", _asm.GetName ().Name));

            _owner = _asm;
        }
开发者ID:BackupTheBerlios,项目名称:nmodule-svn,代码行数:27,代码来源:ModuleInfo.cs

示例4: GetCopyrightString

        public static string GetCopyrightString(Assembly assembly, string prefix = "Copyright", bool appendCompanyName = true)
        {
            var str = "";

            var copyrightAttributes = assembly.GetCustomAttributes(typeof (AssemblyCopyrightAttribute), true);
            if (copyrightAttributes.Length > 0)
            {
                var copyrightString = ((AssemblyCopyrightAttribute) copyrightAttributes[0]).Copyright;

                if (!string.IsNullOrEmpty(copyrightString))
                    str = copyrightString;
            }

            if (appendCompanyName)
            {
                string companyString = null;

                var companyAttributes = assembly.GetCustomAttributes(typeof (AssemblyCompanyAttribute), true);
                if (companyAttributes.Length > 0)
                    companyString = ((AssemblyCompanyAttribute) companyAttributes[0]).Company;

                if (!string.IsNullOrEmpty(companyString) && !str.EndsWith(companyString))
                {
                    str += string.Format(" {0}", companyString);
                }
            }

            if (!str.StartsWith(prefix))
                str = str.Insert(0, string.Format("{0} ", prefix));

            return str;
        }
开发者ID:GetTabster,项目名称:Tabster,代码行数:32,代码来源:BrandingUtilities.cs

示例5: Plugin

 public Plugin(Assembly Assembly)
 {
     Name = Assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false).OfType<AssemblyTitleAttribute>().FirstOrDefault().Title;
     Description = Assembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false).OfType<AssemblyDescriptionAttribute>().FirstOrDefault().Description;
     try
     {
         Version = Assembly.GetCustomAttributes(typeof(AssemblyVersionAttribute), false).OfType<AssemblyVersionAttribute>().FirstOrDefault().Version;
     }
     catch
     {
         Version = null;
     }
     Type[] tt = Assembly.GetExportedTypes();
     List<Type> fe = new List<Type>();
     List<Type> ce = new List<Type>();
     List<Type> pe = new List<Type>();
     foreach (var t in tt)
     {
         if (!t.IsClass) continue;
         if (t.IsSubclassOf(typeof(EFEPlugin)))
         {
             Initializer = (EFEPlugin)t.InvokeMember(null, BindingFlags.CreateInstance, null, null, null);
             continue;
         }
         var v = t.GetInterfaces();
         if (v.Length != 0 && t.GetInterfaces()[0].Name == "FileFormatBase") fe.Add(t);
         else if (v.Length != 0 && t.GetInterfaces()[0].Name == "CompressionFormatBase") ce.Add(t);
         else if (v.Length != 0 && t.GetInterfaces()[0].Name == "ProjectBase") pe.Add(t);
     }
     FileFormatTypes = fe.ToArray();
     CompressionTypes = ce.ToArray();
     ProjectTypes = pe.ToArray();
 }
开发者ID:Ermelber,项目名称:EveryFileExplorer,代码行数:33,代码来源:Plugin.cs

示例6: AssemblyPropertyHelper

 public AssemblyPropertyHelper(Assembly asm)
 {
     var attributes = asm.GetCustomAttributes(typeof (AssemblyProductAttribute), false);
     if (attributes.Length > 0)
         _product = (AssemblyProductAttribute) attributes[0];
     attributes = asm.GetCustomAttributes(typeof (AssemblyCompanyAttribute), false);
     if (attributes.Length > 0)
         _company = (AssemblyCompanyAttribute) attributes[0];
     attributes = asm.GetCustomAttributes(typeof (AssemblyCopyrightAttribute), false);
     if (attributes.Length > 0)
         _copyright = (AssemblyCopyrightAttribute) attributes[0];
     attributes = asm.GetCustomAttributes(typeof (AssemblyDescriptionAttribute), false);
     if (attributes.Length > 0)
         _description = (AssemblyDescriptionAttribute) attributes[0];
 }
开发者ID:haoas,项目名称:DotSpatial.Plugins,代码行数:15,代码来源:ucInfo.cs

示例7: GetVersionOptions

 private static IEnumerable<string> GetVersionOptions(Assembly assembly)
 {
     yield return assembly
         .GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false)
         .OfType<AssemblyInformationalVersionAttribute>()
         .Select(a => a.InformationalVersion).FirstOrDefault();
     yield return assembly
         .GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false)
         .OfType<AssemblyFileVersionAttribute>()
         .Select(a => a.Version).FirstOrDefault();
     yield return assembly
         .GetName()
         .Version
         .ToString();
 }
开发者ID:quadio,项目名称:amss-boilerplate,代码行数:15,代码来源:AssemblyExtension.cs

示例8: RegisterAssembly

		public static void RegisterAssembly (Assembly a) {
			var attributes = a.GetCustomAttributes (typeof (RequiredFrameworkAttribute), false);

			foreach (var attribute in attributes) {
				var requiredFramework = (RequiredFrameworkAttribute)attribute;
				string libPath;
				string libName = requiredFramework.Name;
				
				if (libName.Contains (".dylib")) {
					libPath = ResourcesPath;
				}
				else {
					libPath = FrameworksPath;
					libPath = Path.Combine (libPath, libName);
					libName = libName.Replace (".frameworks", "");
				}
				libPath = Path.Combine (libPath, libName);
				
				if (Dlfcn.dlopen (libPath, 0) == IntPtr.Zero)
					throw new Exception (string.Format ("Unable to load required framework: '{0}'", requiredFramework.Name),
				new Exception (Dlfcn.dlerror()));
			}
			
			if (assemblies == null) {
				assemblies = new List <Assembly> ();
				Class.Register (typeof (NSObject));
			}

			assemblies.Add (a);

			foreach (Type type in a.GetTypes ()) {
				if (type.IsSubclassOf (typeof (NSObject)) && !Attribute.IsDefined (type, typeof (ModelAttribute), false))
					Class.Register (type);
			}
		}
开发者ID:Anomalous-Software,项目名称:monomac,代码行数:35,代码来源:Runtime.cs

示例9: IsRelease

        private bool IsRelease(Assembly assembly)
        {
            object[] attributes = assembly.GetCustomAttributes(typeof(DebuggableAttribute), false);

            if (attributes.Length == 0)
            {
                //Console.WriteLine(String.Format("{0} is a RELEASE Build....", assembly.FullName));
                return true;
            }
            foreach (Attribute attr in attributes)
            {
                if (attr is DebuggableAttribute)
                {
                    DebuggableAttribute d = attr as DebuggableAttribute;
                    //Console.WriteLine(String.Format("Run time Optimizer is enabled : {0}", !d.IsJITOptimizerDisabled));
                    //Console.WriteLine(String.Format("Run time Tracking is enabled : {0}", d.IsJITTrackingEnabled));

                    if (d.IsJITOptimizerDisabled == true)
                    {
                        //Console.WriteLine(String.Format("{0} is a DEBUG Build....", assembly.FullName));
                        return false;
                    }
                    else
                    {
                        //Console.WriteLine(String.Format("{0} is a RELEASE Build....", assembly.FullName));
                        return true;
                    }
                }
            }

            return false;
        }
开发者ID:jcant0n,项目名称:CheckRelease,代码行数:32,代码来源:MainWindow.xaml.cs

示例10: AboutViewModel

        /// <summary>
        /// Initializes a new instance of the <see cref="AboutViewModel"/> class.
        /// </summary>
        /// <param name="a">
        /// An assembly.
        /// </param>
        public AboutViewModel(Assembly a)
        {
            this.SystemInfoText = "System Info...";
            this.CopyReportText = "Copy report";

            if (a == null)
            {
                throw new InvalidOperationException();
            }

            if (a.Location == null)
            {
                throw new InvalidOperationException();
            }

            this.FileVersionInfo = FileVersionInfo.GetVersionInfo(a.Location);
            this.FileInfo = new FileInfo(this.FileVersionInfo.FileName);

            var va = (AssemblyVersionAttribute[])a.GetCustomAttributes(typeof(AssemblyVersionAttribute), true);
            if (va != null && va.Length > 0)
            {
                this.AssemblyVersion = va[0].Version;
            }

            comments = this.FileVersionInfo.Comments;
        }
开发者ID:vitaliygor,项目名称:Well,代码行数:32,代码来源:AboutViewModel.cs

示例11: EnsureLoaded

        public void EnsureLoaded(Assembly a)
        {
            if (assembliesProcessed.Contains(a.FullName)) return;
            Stopwatch sw = new Stopwatch();
            sw.Start();
            try {
                object[] attrs = a.GetCustomAttributes(typeof(Util.NativeDependenciesAttribute), true);
                if (attrs.Length == 0) return;
                var attr = attrs[0] as Util.NativeDependenciesAttribute;
                string shortName = a.GetName().Name;
                string resourceName = shortName + "." + attr.Value;

                var info = a.GetManifestResourceInfo(resourceName);
                if (info == null) { this.AcceptIssue(new Issues.Issue("Plugin error - failed to find embedded resource " + resourceName, Issues.IssueSeverity.Error)); return; }

                using (Stream s = a.GetManifestResourceStream(resourceName)){
                    var x = new System.Xml.XmlDocument();
                    x.Load(s);

                    var n = new Node(x.DocumentElement, this);
                    EnsureLoaded(n, shortName,sw);
                }

            } finally {
                assembliesProcessed.Add(a.FullName);
            }
        }
开发者ID:eakova,项目名称:resizer,代码行数:27,代码来源:NativeDependencyManager.cs

示例12: GetImplemetationType

        public static System.Type GetImplemetationType(Assembly assembly, Type interfaceType, Type assemblyAttribute, bool searchFromAllExportedType)
        {
            if (null == assembly)
                return null;

            object[] attributes = assembly.GetCustomAttributes(assemblyAttribute, true);
            if (null != attributes && attributes.Length > 0 && assemblyAttribute.IsAssignableFrom(attributes[0].GetType()))
            {
                PropertyInfo prop = assemblyAttribute.GetProperty("Type");
                Type t = prop.GetValue(attributes[0], null) as Type;
                if (null != t && interfaceType.IsAssignableFrom(t))
                    return t;
            }

            if (!searchFromAllExportedType)
                return null;

            //Couldn't get interfaceType via assemblyAttribute,
            //iterate  through all exported types and checkif there is a
            //interfaceType implementation.
            //
            Type[] types = assembly.GetExportedTypes();
            foreach (var item in types)
            {
                if (!item.IsAbstract && !item.IsInterface && interfaceType.IsAssignableFrom(item))
                    return item;
            }

            return null;
        }
开发者ID:samuto,项目名称:designscript,代码行数:30,代码来源:CLRDLLModule.cs

示例13: IsInternalToDynamicProxy

		/// <summary>
		///   Determines whether this assembly has internals visible to dynamic proxy.
		/// </summary>
		/// <param name = "asm">The assembly to inspect.</param>
		public static bool IsInternalToDynamicProxy(Assembly asm)
		{
			using (var locker = internalsToDynProxyLock.ForReadingUpgradeable())
			{
				if (internalsToDynProxy.ContainsKey(asm))
				{
					return internalsToDynProxy[asm];
				}

				locker.Upgrade();

				if (internalsToDynProxy.ContainsKey(asm))
				{
					return internalsToDynProxy[asm];
				}

				var atts = (InternalsVisibleToAttribute[])
				           asm.GetCustomAttributes(typeof(InternalsVisibleToAttribute), false);

				var found = false;

				foreach (var internals in atts)
				{
					if (internals.AssemblyName.Contains(ModuleScope.DEFAULT_ASSEMBLY_NAME))
					{
						found = true;
						break;
					}
				}

				internalsToDynProxy.Add(asm, found);

				return found;
			}
		}
开发者ID:dbroudy,项目名称:Castle.Core,代码行数:39,代码来源:InternalsHelper.cs

示例14: AssemblyCopyright

 public static string AssemblyCopyright(Assembly ass)
 {
     // Get all Copyright attributes on this assembly
     object[] attributes = ass.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
     // If there aren't any Copyright attributes, return an empty string. If there is a Copyright attribute, return its value.
     return (attributes.Length == 0) ? "" : ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
 }
开发者ID:svn2github,项目名称:awb,代码行数:7,代码来源:AboutBox.cs

示例15: IsNonApplicationAssembly

        public override bool IsNonApplicationAssembly(Assembly assembly)
        {
            ArgumentUtility.CheckNotNull ("assembly", assembly);

              return assembly.GetCustomAttributes (false).Any (
              attribute => attribute.GetType ().FullName == "Remotion.Reflection.TypeDiscovery.NonApplicationAssemblyAttribute");
        }
开发者ID:re-motion,项目名称:Mixins-XRef,代码行数:7,代码来源:02-TargetClassDefinitionFactoryReflector.cs


注:本文中的System.Reflection.Assembly.GetCustomAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。