static UpdateManager() { // Fetch the build channel attribute the program was compiled with System.Reflection.Assembly _assemblyInfo = System.Reflection.Assembly.GetExecutingAssembly(); BuildVersion = _assemblyInfo.GetName().Version; BuildChannelVersion = _assemblyInfo.GetCustomAttributes(typeof(BuildChannelAttribute), false).FirstOrDefault(item => item is BuildChannelAttribute) as BuildChannelAttribute; if (BuildChannelVersion == null) { BuildChannelVersion = new BuildChannelAttribute("", UpdateChannelType.Stable); } // Check if the update channel has been overridden by the user if (SettingsManager.Settings.HasSetting("updateChannel")) { UpdateChannelType updateChannel; if (Enum.TryParse <UpdateChannelType>(SettingsManager.Settings.Read("updateChannel") as string, out updateChannel)) { UpdateChannel = updateChannel; } } else { UpdateChannel = BuildChannelVersion.UpdateChannel; } // Set app display version AppDisplayVersion = String.Format("{0}.{1}.{2} {3} ", BuildVersion.Major, BuildVersion.Minor, BuildVersion.Build, BuildChannelVersion.DisplayName); #if PORTABLE AppDisplayVersion += String.Format("(Portable, Build {0})", BuildVersion.Revision); #elif DEBUG AppDisplayVersion += String.Format("(Debug, Build {0})", BuildVersion.Revision); #else AppDisplayVersion += String.Format("(Build {0})", BuildVersion.Revision); #endif }
public static void LoadAssembly(System.Reflection.Assembly assembly, Server server) { ServiceAttribute.LoadAssembly(assembly, server); foreach (HosteableObjectAttribute attr in assembly.GetCustomAttributes(typeof(HosteableObjectAttribute), false)) { attr.RegisterTo(server); } foreach (var module in assembly.GetModules()) { foreach (HosteableObjectAttribute attr in module.GetCustomAttributes(typeof(HosteableObjectAttribute), false)) { attr.RegisterTo(server); } } foreach (Type type in assembly.GetTypes()) { var attrs = type.GetCustomAttributes(typeof(HosteableObjectAttribute), false); if (attrs.Length > 0) { var attr = attrs[0] as HosteableObjectAttribute; attr.RegisterTo(server); } } }
public FormAbout() { InitializeComponent(); System.Reflection.Assembly ehLibAssemly = typeof(EhLib.WinForms.DataGridEh).Assembly; Version ehLibVer = typeof(EhLib.WinForms.DataGridEh).Assembly.GetName().Version; //AssemblyConfiguration tbVersion.Text = "Version " + ehLibVer.Major.ToString() + "." + ehLibVer.Minor.ToString(); tbBuild.Text = "Build " + ehLibVer.Major.ToString() + "." + ehLibVer.Minor.ToString() + "." + ehLibVer.Build.ToString(); object[] atrbs = ehLibAssemly.GetCustomAttributes(typeof(System.Reflection.AssemblyConfigurationAttribute), false); if (atrbs.Length > 0) { tbConfiguration.Text = (atrbs[0] as System.Reflection.AssemblyConfigurationAttribute).Configuration; } else { tbConfiguration.Text = ""; } tbBuild.GotFocus += textBox1_GotFocus; tbBuild.MouseUp += textBox1_MouseUp; tbBuild.Leave += textBox1_Leave; tbVersion.GotFocus += textBox1_GotFocus; tbVersion.MouseUp += textBox1_MouseUp; tbVersion.Leave += textBox1_Leave; }
public static T GetCustomAttribute <T>(this System.Reflection.Assembly @this) where T : Attribute { T attr = (T)@this.GetCustomAttributes(typeof(T), true).FirstOrDefault(); return(attr); }
static void Main(string[] args) { System.Reflection.Assembly assembly = null; if (args != null && args.Length > 0) { assembly = System.Reflection.Assembly.LoadFrom(args[0]); System.Console.WriteLine("{0} - Assembly Image Runtime Version", assembly.ImageRuntimeVersion); System.Console.WriteLine("{0} - Environment Version", System.Environment.Version); } else { assembly = System.Reflection.Assembly.GetExecutingAssembly(); System.Console.WriteLine("Hint: Put assembly name as application argument"); System.Console.WriteLine("{0} - Current Assembly Image Runtime Version", assembly.ImageRuntimeVersion); } System.Console.WriteLine("----------------------------------------"); System.Console.WriteLine("Help: Identifies the version of the .NET Framework that a particular assembly was compiled against."); object[] list = assembly.GetCustomAttributes(true); var attribute = list.OfType <System.Runtime.Versioning.TargetFrameworkAttribute>().FirstOrDefault(); if (attribute != null) { System.Console.WriteLine(attribute.FrameworkName); System.Console.WriteLine(attribute.FrameworkDisplayName); } System.Console.ReadKey(); }
static WebDavConnection() { System.Reflection.Assembly app = System.Reflection.Assembly.GetExecutingAssembly(); var assemblyTitle = (System.Reflection.AssemblyTitleAttribute)app.GetCustomAttributes(typeof(System.Reflection.AssemblyTitleAttribute), false)[0]; _key = assemblyTitle.Title; }
/// <summary> /// Instantiates a plug-in type and registers the associated commands and classes. /// </summary> /// <param name="pluginType">A plug-in type. This type must derive from <see cref="PlugIn"/>.</param> /// <param name="printDebugMessages">true if debug messages should be printed.</param> /// <returns>A new plug-in instance.</returns> public static PlugIn CreatePlugIn(Type pluginType, bool printDebugMessages) { if (null == pluginType || !typeof(PlugIn).IsAssignableFrom(pluginType)) return null; InitializeRhinoCommon(); // If we turn on debug messages, we always get debug output if (printDebugMessages) SendDebugToCommandLine = true; // this function should only be called by Rhino_DotNet.dll // we could add some safety checks by performing validation on // the calling assembly //System.Reflection.Assembly.GetCallingAssembly(); System.Reflection.Assembly plugin_assembly = pluginType.Assembly; object[] name = plugin_assembly.GetCustomAttributes(typeof(System.Reflection.AssemblyTitleAttribute), false); string plugin_name = ((System.Reflection.AssemblyTitleAttribute)name[0]).Title; string plugin_version = plugin_assembly.GetName().Version.ToString(); PlugIn plugin = PlugIn.Create(pluginType, plugin_name, plugin_version); if (plugin == null) return null; PlugIn.m_plugins.Add(plugin); return plugin; }
/// <summary> /// 获取当前模块的guid /// </summary> /// <returns></returns> Guid GetCurGuid() { System.Reflection.Assembly ass = System.Reflection.Assembly.GetExecutingAssembly(); object[] attrs = ass.GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), false); Guid id = new Guid(((System.Runtime.InteropServices.GuidAttribute)attrs[0]).Value); return(id); }
/// <summary> /// Obtiene el identificador público de la aplicación /// </summary> /// <returns>Identificador público de la aplicación</returns> public static string GetApplicationID() { System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly(); var attribute = (System.Runtime.InteropServices.GuidAttribute)asm.GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), true)[0]; string id = attribute.Value; return(id); }
public static T GetAssemblyAttribute <T>(this System.Reflection.Assembly ass) where T : Attribute { object[] attributes = ass.GetCustomAttributes(typeof(T), false); if (attributes == null || attributes.Length == 0) { return(null); } return(attributes.OfType <T>().SingleOrDefault()); }
string GetAttrValue(System.Reflection.Assembly assy, Type attrType, string field) { object[] ary = assy.GetCustomAttributes(attrType, false); if (ary == null || ary.Length != 1) { return("(not set)"); } object value = attrType.InvokeMember(field, System.Reflection.BindingFlags.GetProperty, null, ary[0], new object[] { }); return(value == null ? "(not set)" : (string)value); }
private Attribute getAsmAttribute(System.Reflection.Assembly assembly, Type attrType) { Attribute retVal = null; object[] attributes = assembly.GetCustomAttributes(attrType, true); if ((attributes != null) && (attributes.Length > 0)) { retVal = (Attribute)attributes[0]; } return(retVal); }
public static bool IsAssemblyDebugBuild(System.Reflection.Assembly assembly) { foreach (var attribute in assembly.GetCustomAttributes(false)) { if (attribute is DebuggableAttribute debuggableAttribute) { return(debuggableAttribute.IsJITTrackingEnabled); } } return(false); }
private DomainConfiguratorAttribute CurrentDomainConfiguratorAttribute(System.Reflection.Assembly assembly) { object[] objs = assembly.GetCustomAttributes(typeof(DomainConfiguratorAttribute), false); if (objs != null) { return((DomainConfiguratorAttribute)objs[0]); } else { return(null); } }
protected string GetAttributeValue <TAttr>(Func <TAttr, string> resolveFunc, string defaultResult = null) where TAttr : Attribute { object[] attributes = assembly.GetCustomAttributes(typeof(TAttr), false); if (attributes.Length > 0) { return(resolveFunc((TAttr)attributes[0])); } else { return(defaultResult); } }
private bool CheckFileForFilters(System.IO.FileInfo fileInfo) { bool result; if (fileInfo.Extension == ".dll" || fileInfo.Extension == ".exe") { System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFile(fileInfo.FullName); object[] customAttributes = assembly.GetCustomAttributes(typeof(System.Reflection.AssemblyDescriptionAttribute), false); if (customAttributes == null) { result = true; } else { string[] filters = this.filters; for (int i = 0; i < filters.Length; i++) { string b = filters[i]; bool flag = false; object[] array = customAttributes; for (int j = 0; j < array.Length; j++) { object obj = array[j]; if (((System.Reflection.AssemblyDescriptionAttribute)obj).Description == b) { flag = true; } } if (!flag) { result = false; return(result); } } result = true; } } else { if (!System.Text.RegularExpressions.Regex.IsMatch(fileInfo.Name, "*_[*]*")) { result = true; } else { string str = string.Concat(this.filters); result = System.Text.RegularExpressions.Regex.IsMatch(fileInfo.Name, "*_[" + str + "]*"); } } return(result); }
// информация о сборке для заголовка приложения, включает в себя Company, Product, Version public static string GetAssemblyInfoForAppTitle() { string company = null, product = null, version = null; System.Reflection.Assembly runAssembly = System.Reflection.Assembly.GetEntryAssembly(); object[] attribs = runAssembly.GetCustomAttributes(true); foreach (object item in attribs) { if (item is System.Reflection.AssemblyCompanyAttribute) { company = ((System.Reflection.AssemblyCompanyAttribute)item).Company; continue; } if (item is System.Reflection.AssemblyProductAttribute) { product = ((System.Reflection.AssemblyProductAttribute)item).Product; continue; } // file version if (item is System.Reflection.AssemblyFileVersionAttribute) { version = ((System.Reflection.AssemblyFileVersionAttribute)item).Version; continue; } } StringHelper sBuf = new StringHelper() { TokenDelimiter = ", " }; if (!string.IsNullOrEmpty(company)) { sBuf.AddText(company); } if (!string.IsNullOrEmpty(product)) { sBuf.AddText(product); } if (!string.IsNullOrEmpty(version)) { sBuf.AddText("ver. " + version); } //retVal += getAppVersionAsString(); // assembly version instead string retVal = sBuf.ToString(); return(retVal); }
private static void Main() { int tries = 60; TryAgain :; try { if (!SQLConnection.IsServerConnected(Properties.Settings.Default.FollowersConnectionString)) { tries--; if (tries > 0) { EasyLogger.Warning("SQL Server is not responding. I'll try again " + tries + " more times until I require user input..."); Thread.Sleep(2000); goto TryAgain; } else { DialogResult result = MessageBox.Show("SQL Server is not responding. Would you like to try again?", "Social Post Scheduler", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { goto TryAgain; } else { Environment.Exit(0); } } } } catch (Exception ex) { EasyLogger.Error(ex); } try { System.Reflection.Assembly assembly = typeof(Program).Assembly; GuidAttribute attribute = (GuidAttribute)assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0]; string id = attribute.Value; StartApp(); } catch (Exception ex) { EasyLogger.Error("Program - @Main(1): " + ex); MessageBox.Show(ex.Message, "TwitterFollower", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
internal string GetVersion(System.Reflection.Assembly thisAssembly) { var attFileVer = thisAssembly. GetCustomAttributes(typeof(System.Reflection.AssemblyFileVersionAttribute), false).First() as System.Reflection.AssemblyFileVersionAttribute; if (attFileVer != null) { return(attFileVer.Version); } else { return(null); } }
private static string GetAssemblyTitle(System.Reflection.Assembly assembly) { var attributes = assembly.GetCustomAttributes(typeof(System.Reflection.AssemblyTitleAttribute), false); if (attributes != null && attributes.Length > 0) { var attribute = attributes[0] as System.Reflection.AssemblyTitleAttribute; if (attribute != null) { return(attribute.Title); } } throw new InvalidProgramException(@"Can not retrive Title, assembly attribute"); }
public static string GetTitle() { System.Reflection.Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); object[] attributes = thisAssembly.GetCustomAttributes(typeof(System.Reflection.AssemblyTitleAttribute), false); string title = ""; if (attributes.Length == 1) { title = ((System.Reflection.AssemblyTitleAttribute)attributes[0]).Title; } return(title); }
public void Configure(IApplicationBuilder app) { app.Run(async context => { context.Response.Headers.Add("content-type", "text/html"); await context.Response.WriteAsync($"Application Name: {System.Reflection.Assembly.GetEntryAssembly().GetName().Name}<br/>"); await context.Response.WriteAsync($"Application Base Path: {System.AppContext.BaseDirectory}<br/>"); System.Reflection.Assembly entryAssembly = System.Reflection.Assembly.GetEntryAssembly(); var targetFramework = entryAssembly.GetCustomAttributes(typeof(System.Runtime.Versioning.TargetFrameworkAttribute), true)[0] as System.Runtime.Versioning.TargetFrameworkAttribute; await context.Response.WriteAsync($"Target Framework: {targetFramework.FrameworkName}<br/>"); await context.Response.WriteAsync($"Version: {System.Reflection.Assembly.GetEntryAssembly().GetName().Version}<br/>"); }); }
/// <summary> /// 获取版本号 /// </summary> /// <returns></returns> internal string GetVersion(string AppName) { string NowVersion = "V1.0"; string filePath = AppName; System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFile(filePath); object[] attributes = assembly.GetCustomAttributes(typeof(System.Reflection.AssemblyFileVersionAttribute), false); if (attributes.Length > 0) { if (attributes.Length > 0) { NowVersion = ((System.Reflection.AssemblyFileVersionAttribute)attributes[0]).Version; } } return(NowVersion); }
public static IServiceProvider CreateServiceProvider(System.Reflection.Assembly assembly) { if (assembly == null) { throw new ArgumentNullException("assembly"); } var attribute = assembly.GetCustomAttributes(typeof(ServiceProviderAttribute), false).Cast <ServiceProviderAttribute>().SingleOrDefault(); if (attribute == null) { return(null); } return((IServiceProvider)Activator.CreateInstance(attribute.ServiceType)); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger, IConfiguration configuration) { //These are the four default services available at Configure app.Run(async context => { context.Response.Headers.Add("content-type", "text/html"); await context.Response.WriteAsync($"Application Name: {System.Reflection.Assembly.GetEntryAssembly().GetName().Name}<br/>"); await context.Response.WriteAsync($"Application Base Path: {System.AppContext.BaseDirectory}<br/>"); System.Reflection.Assembly entryAssembly = System.Reflection.Assembly.GetEntryAssembly(); var targetFramework = entryAssembly.GetCustomAttributes(typeof(System.Runtime.Versioning.TargetFrameworkAttribute), true)[0] as System.Runtime.Versioning.TargetFrameworkAttribute; await context.Response.WriteAsync($"Target Framework: {targetFramework.FrameworkName}<br/>"); await context.Response.WriteAsync($"Version: {System.Reflection.Assembly.GetEntryAssembly().GetName().Version}<br/>"); }); }
static MonoGamerPeer() { #if !WINDOWS_PHONE // This code looks up the Guid for the host app , this is used to identify the // application on the network . We use the Guid as that is unique to that application. System.Reflection.Assembly assembly = null; // FIXME: System.Reflection.Assembly.GetAssembly(Game.Instance.GetType()); if (assembly != null) { object[] objects = assembly.GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), false); if (objects.Length > 0) { applicationIdentifier = ((System.Runtime.InteropServices.GuidAttribute)objects[0]).Value; } } #else #endif }
/// <summary> /// 获取程序集的插件特性 /// </summary> /// <param name="model"></param> /// <returns></returns> public static AssemblyPluginAttribute GetAssemblyPluginAttribute(this System.Reflection.Assembly model) { try { var assemblyPluginAttributes = model.GetCustomAttributes(typeof(AssemblyPluginAttribute), false); if (assemblyPluginAttributes != null && assemblyPluginAttributes.Length > 0) { return(assemblyPluginAttributes.FirstOrDefault(assemblyPluginAttribute => assemblyPluginAttribute is AssemblyPluginAttribute) as AssemblyPluginAttribute); } } catch (Exception ex) { ex.ToString().WriteToLog(); } return(null); }
public static string GetAppGuid() { System.Reflection.Assembly asm = getAppAssembly(); if (asm == null) { return(null); } string appGUID = null; object[] attributes = asm.GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), true); if ((attributes != null) && (attributes.Length > 0)) { System.Runtime.InteropServices.GuidAttribute ga = (System.Runtime.InteropServices.GuidAttribute)attributes[0]; appGUID = ga.Value; } return(appGUID); }
void initialize(System.Reflection.Assembly assembly) { string groupName = null; object[] attrobjs = assembly.GetCustomAttributes(typeof(LocalizationAttribute), true /* inherit */); if (attrobjs != null && attrobjs.Length > 0 && attrobjs[0] != null) // focus on only the first. { LocalizationAttribute locAttr = (LocalizationAttribute)attrobjs[0]; groupName = locAttr.locGroupName; if (groupName == null) { groupName = assembly.GetName().Name; } } LocalizationGroupStack.Push(groupName); m_Pushed = true; m_LocGroupName = groupName; }
static TAttr GetCustomAttributes <TAttr>(System.Reflection.Assembly a) where TAttr : Attribute { object[] arr = a.GetCustomAttributes(typeof(TAttr), true); #if false // _Not_ supported on NETCF var newArr = Array.ConvertAll(arr, x => (TAttr)x); #endif if (arr.Length == 0) { return(null); } if (arr.Length > 1) { throw new InvalidOperationException("Don't support multiple attribute instances."); } TAttr attr = (TAttr)arr[0]; return(attr); }