private async void MTAuthorsTxt_SelectedValueChanged(object sender, EventArgs e) { AuthorAttribute author = SelectedAuthor; UI.MTResourceBtn.Text = (author?.ResourceName); UI.MTResourceBtn.Enabled = (IsValidUrl(author?.ResourceUrl)); if (string.IsNullOrWhiteSpace(author?.HabboName)) { UI.MTHabboNameLbl.Text = "Habbo Name"; UI.MTHabboNameTxt.Text = string.Empty; UI.MTAuthorPctbx.Image = Resources.Avatar; return; } UI.MTHabboNameTxt.Text = author.HabboName; UI.MTHabboNameLbl.Text = $"Habbo Name({author.Hotel})"; if (author.Hotel != HHotel.Unknown) { Bitmap avatar = await UI.GetAvatarAsync(author.HabboName, author.Hotel); if (author == SelectedAuthor) { UI.MTAuthorPctbx.Image = avatar; } } }
private async void MTAuthorsTxt_SelectedValueChanged(object sender, EventArgs e) { AuthorAttribute author = SelectedAuthor; UI.MTResourceBtn.Text = (author?.ResourceName); UI.MTResourceBtn.Enabled = (IsValidUrl(author?.ResourceUrl)); if (string.IsNullOrWhiteSpace(author?.HabboName)) { UI.MTHotelTxt.Text = string.Empty; UI.MTHabboNameTxt.Text = string.Empty; UI.MTAuthorPctbx.Image = Resources.Avatar; return; } UI.MTHabboNameTxt.Text = author.HabboName; UI.MTHotelTxt.Text = ("Habbo." + author.Hotel.ToDomain()); Bitmap avatar = await GetAvatarAsync(author); if (author == SelectedAuthor) { UI.MTAuthorPctbx.Image = avatar; } }
private BrowsableItem(T item) { this.Item = item; DisplayNameAttribute dn = Util.GetAttribute <DisplayNameAttribute>(item, false); if (dn != null) { this.DisplayName = dn.DisplayName; } else { this.DisplayName = item.Name; } CategoryAttribute cat = Util.GetAttribute <CategoryAttribute>(item, false); if (cat != null) { this.Category = cat.Category; } else { this.Category = "(None)"; } DescriptionAttribute desc = Util.GetAttribute <DescriptionAttribute>(item, false); if (desc != null) { this.Description = desc.Description; } else { this.Description = string.Empty; } FollowsAttribute follows = Util.GetAttribute <FollowsAttribute>(item, false); if (follows != null) { this.Follows = follows.Follows; } else { this.Follows = null; } AuthorAttribute author = Util.GetAttribute <AuthorAttribute>(item, false); if (author != null) { this.Author = author.Author; } else { this.Author = null; } }
public void Try() { AuthorAttribute attribute = (AuthorAttribute)Attribute.GetCustomAttributes(typeof(HackersBlackBook)) .Where(t => t.GetType() == typeof(AuthorAttribute)) .First(); Console.WriteLine(attribute.GetName() + " " + attribute.version); }
static void DisplayMemberByAuthor(MemberInfo[] memberInfos, string authorName) { foreach (var member in memberInfos) { foreach (var attribute in member.GetCustomAttributes(true)) { AuthorAttribute author = attribute as AuthorAttribute; if (author != null && author.Name == authorName) { Console.WriteLine(member.Name); } } } }
public override void Populate( GuidTestTreeNodeDictionary nodes, TestTreeNode rootNode, MbUnit.Core.Collections.RunPipeStarterCollection pipes ) { if (rootNode == null) { throw new ArgumentNullException("rootNode"); } if (pipes == null) { throw new ArgumentNullException("pipes"); } if (this.parentNode == null) { this.parentNode = new TestTreeNode("Authors", TestNodeType.Populator); nodes.Add(this.parentNode); rootNode.Nodes.Add(this.parentNode); // add unknown author this.anonymous = this.addAuthor(nodes, "Anonymous"); } foreach (RunPipeStarter pipeStarter in pipes) { // get author attribute TestTreeNode node = null; AuthorAttribute author = (AuthorAttribute)TypeHelper.TryGetFirstCustomAttribute( pipeStarter.Pipe.FixtureType, typeof(AuthorAttribute)); if (author != null) { node = addAuthor(nodes, author.Name); } else { node = anonymous; } TestTreeNode fixtureNode = addFixtureNode(nodes, node, pipeStarter); CreatePipeNode(nodes, fixtureNode, pipeStarter); } }
public async Task <HProfile> GetProfileAsync(AuthorAttribute authorAtt) { if (!_profileCache.ContainsKey(authorAtt.Hotel)) { _profileCache[authorAtt.Hotel] = new Dictionary <string, HProfile>(); } if (_profileCache[authorAtt.Hotel] .ContainsKey(authorAtt.HabboName)) { return(_profileCache[authorAtt.Hotel][authorAtt.HabboName]); } HProfile profile = await SKore.GetProfileAsync( authorAtt.HabboName, authorAtt.Hotel).ConfigureAwait(false); _profileCache[authorAtt.Hotel][authorAtt.HabboName] = profile; return(profile); }
private void button1_Click(object sender, System.EventArgs e) { AuthorAttribute temp = new AuthorAttribute(""); Assembly asm = Assembly.LoadFrom(textBox1.Text); Type[] types = asm.GetTypes(); foreach (Type type in types) { object[] atts = type.GetCustomAttributes(temp.GetType(), false); if (atts.Length > 0) { AuthorAttribute au = (AuthorAttribute)atts[0]; if (au.Nombre == textBox2.Text) { ListViewItem item = listView1.Items.Add("Clase"); item.SubItems.Add(type.FullName); } } } }
private void PrintAttributeMsg() { //获取类型 Type type = typeof(UsersAttributes); //得到该类型的不可继承的特性对象 object[] atts = type.GetCustomAttributes(false); for (int i = 0; i < atts.Length; i++) { //判断当前特性是不是某个特性类型 if (atts[i] is AuthorAttribute) { //将特性转换为该类型 AuthorAttribute authorObj = atts[i] as AuthorAttribute; Debug.Log(authorObj.author); Debug.Log(authorObj.LastDate); } } }
public async Task <Bitmap> GetAvatarAsync(AuthorAttribute authorAtt) { HProfile profile = await GetProfileAsync( authorAtt).ConfigureAwait(false); if (profile == null) { return(Resources.Avatar); } if (_avatarCache.ContainsKey(profile.User.FigureId)) { return(_avatarCache[profile.User.FigureId]); } Bitmap avatar = await SKore.GetAvatarAsync( profile.User.FigureId, HSize.Medium).ConfigureAwait(false); _avatarCache[profile.User.FigureId] = avatar; return(avatar); }
public static void Main() { Assembly asm = Assembly.GetExecutingAssembly(); string author; int version; foreach (Type t in asm.GetTypes()) { AuthorAttribute aa = t.GetCustomAttribute(typeof(AuthorAttribute)) as AuthorAttribute; author = "Unknown"; version = 1; if (aa != null) { author = aa.Author; version = aa.Version; } Console.WriteLine("{0} {1} {2}", t.Name.PadRight(30), author.PadRight(30), version); } }
/* * // 콜백으로 등록될 메서드 1 * static void PrintPrime(object sender, EventArgs arg) * { * Console.Write((arg as PrimeCallbackArg).Prime + ", "); * } * * static int Sum; * * // 콜백으로 등록될 메서드 2 * static void SumPrime(object sender, EventArgs arg) * { * Sum += (arg as PrimeCallbackArg).Prime; * }*/ #endregion 258 static void Main(string[] args) { #region 258 /* * PrimeGenerator gen = new PrimeGenerator(); * * // PrintPrime 콜백 메서드 추가 * gen.PrimeGenerated += PrintPrime; * * // SumPrime 콜백 메서드 추가 * gen.PrimeGenerated += SumPrime; * * // 1 ~ 10까지 소수를 구하고, * gen.Run(10); * Console.WriteLine(); * Console.WriteLine(Sum); * * // SumPrime 콜백 메서드를 제거한 후 다시 1 ~ 15까지 소수를 구하는 메서드 호출 * gen.PrimeGenerated -= SumPrime; * gen.Run(15);*/ #endregion 258 #region 260 /* * IntegerText aInt = new IntegerText(123456); * * int step = 1; * for (int i = 0; i < aInt.ToString().Length; i++) * { * Console.WriteLine(step + "의 자릿수: " + aInt[i]); * step *= 10; * } * * aInt[3] = '5'; * * Console.WriteLine(aInt.ToInt32());*/ #endregion 260 #region 262 /* * Notebook norma1 = new Notebook(13, 4); * Console.WriteLine("모니터 인치: " + norma1["인치"] + "\""); * Console.WriteLine("메모리 크기: " + norma1["메모리크기"] + "GB");*/ #endregion 262 #region 267 /* * string txt = Console.ReadLine(); * * if (string.IsNullOrEmpty(txt) == false) * { * Console.WriteLine("사용자 입력: " + txt); * } #if OUTPUT_LOG * else * { * Console.WriteLine("입력되지 않음"); * } #endif*/ #endregion 267 #region 269 /* #if OUTPUT_LOG * Console.WriteLine("OUTPUT_LOG가 정의됨"); #else * Console.WriteLine("OUTPUT_LOG가 정의되지 않음"); #endif * #if __X86__ * Console.WriteLine("__X86__ 정의됨"); #elif __X64__ * Console.WriteLine("__X64__ 정의됨"); #else * Console.WriteLine("아무것도 정의되지 않음"); #endif */ #endregion 269 #region 270 /* * if (true) * { * int i = 5; * } * * //Console.WriteLine(i); // error CS0103: 'i'이름이 현재 컨텍스트에 없습니다. * * int j = 5; * { * //int j = 10; // error CS0136: 'i'(이)라는 지역 변수는 'i'에 다른 의미를 주기 때문에 * // 이 범위에 선언할 수 없습니다. 이 변수는 이미 '부모 또는 * // 현재' 범위에서 다른 의미를 나타내도록 사용되었습니다. * } * * { * int i = 5; * } * * { * int i = 10; * }*/ #endregion 270 #region 271 /* * Console.WriteLine(5.ToString() + 6.ToString()); // 출력 결과: 56 * Console.WriteLine("test".ToUpper()); // 출력 결과: TEST*/ #endregion 271 AuthorAttribute attr = new AuthorAttribute(); // 코드로 생성하는 것도 가능 }
static void Main(string[] args) { // バージョン情報表示 CurrentVersion.ShowInConsole(); CurrentVersion.ShowInConsole(typeof(Program).Assembly); Console.ReadLine(); #region パスワード入力プログラムの実験 #if !NO_PASSWORD_TEST // 起動パスワード確認 Console.WriteLine(); pwprompt: Console.Write("このライブラリの名前を入力:"); SecureString pass = ConsoleUtils.ReadPassword(); string pw = Marshal.PtrToStringUni(Marshal.SecureStringToGlobalAllocUnicode(pass)); if (pw == "DotnetExlib") { ConsoleUtils.Pause(); } else { goto pwprompt; } Console.WriteLine(); #endif #endregion #region 開発者情報に不正が存在しないかチェック #if !NO_DEV_CHECK Console.WriteLine("開発者情報のチェック"); try { List <(string name, string copyright)> devs = new List <(string name, string copyright)>(); List <(string name, string copyright)> devs2 = new List <(string name, string copyright)>(); Assembly asm = typeof(CurrentVersion).Assembly; List <LicenseKind> dev_lic = new List <LicenseKind>(); foreach (var dev_class in asm.GetTypes()) { // <PrivateImplementationDetails>を除外 if (dev_class.Name == "<PrivateImplementationDetails>") { continue; } // このループで全てのクラスから、開発者情報を取得する。 foreach (var dev_class_author in AuthorAttribute.GetAuthors(dev_class)) { // もし、おかしなライセンスだったら if (dev_class_author.License == LicenseKind.Developer) { throw new Exception( "開発者情報チェックでエラーが発生しました。ライセンスがdeveloperになっています。クラス:" + dev_class.ToString()); } dev_lic.Add(dev_class_author.License); // 同じ人を追加しない様にする。 if (!devs.Contains((dev_class_author.Name, dev_class_author.Copyright))) { devs.Add((dev_class_author.Name, dev_class_author.Copyright)); } } // ライセンスが重複していないか? bool a = true; LicenseKind lk = dev_lic?[0] == null ? LicenseKind.NoLicense : dev_lic[0]; foreach (var dev_lic_item in dev_lic) { a &= lk == dev_lic_item; } // もし、重複していたらエラー。 if (!a) { throw new Exception( "開発者情報チェックでエラーが発生しました。ライセンスが重複しています。クラス:" + dev_class.ToString()); } dev_lic.Clear(); } foreach (var dev_item in AuthorAttribute.GetAuthors(asm)) { if (!devs.Contains((dev_item.Name, dev_item.Copyright))) { throw new Exception( "開発者情報チェックでエラーが発生しました。開発者情報がクラスに存在しません。開発者:" + dev_item.Name); } else { devs2.Add((dev_item.Name, dev_item.Copyright)); } if (dev_item.License != LicenseKind.Developer) { throw new Exception( "開発者情報チェックでエラーが発生しました。ライセンス設定が不正です。開発者:" + dev_item.Name); } }
private void ProcessDirectory(string pluginPath, string pluginName) { bool isInDeveloperSolution = publicSolution.ContainsKey(pluginName); bool isInNightlyBuild = coreSolution.ContainsKey(pluginName); streamWriter.Write(string.Format("<tr><td>{0}</td>", pluginName)); streamWriter.Write("<td style=\"text-align:center\">"); streamWriter.Write(isInDeveloperSolution ? "true" : "<span style=\"color:red\">false</span>"); streamWriter.Write("</td><td style=\"text-align:center\">"); streamWriter.Write(isInNightlyBuild ? "true" : "<span style=\"color:red\">false</span>"); streamWriter.Write("</td>"); var pluginTypes = from type in pluginAssemblies.Values where type.Assembly.GetName().Name == pluginName select type; if (pluginTypes.Count() == 0) { streamWriter.Write("<td colspan=\"4\"><span style=\"color:red\">IPlugin not found</span> (not in CrypBuild, assembly name != directory name or not an IPlugin)</td>"); } else { streamWriter.Write("<td>"); foreach (var type in pluginTypes) { streamWriter.Write(type.Namespace + "<br>"); } streamWriter.Write("</td><td>"); foreach (var type in pluginTypes) { streamWriter.Write(type.Name + "<br>"); } streamWriter.Write("</td><td>"); foreach (var type in pluginTypes) { string descFile = type.GetPluginInfoAttribute().DescriptionUrl; if (string.IsNullOrWhiteSpace(descFile)) { streamWriter.Write("<span style=\"color:red\">None</span>"); } else if (descFile.EndsWith(".xaml")) { streamWriter.Write("<span style=\"color:red\">XAML: </span>" + descFile); } else if (!File.Exists(Path.Combine(pluginPath, descFile))) { streamWriter.Write("<span style=\"color:red\">File not found: </span>" + descFile); } else { streamWriter.Write("yes, XML"); } streamWriter.Write("<br>"); } streamWriter.Write("</td><td>"); foreach (var type in pluginTypes) { AuthorAttribute attr = type.GetPluginAuthorAttribute(); if (attr == null) { streamWriter.Write("<span style=\"color:red\">null</span>"); } else { streamWriter.Write(attr.Author); } streamWriter.Write("<br>"); } streamWriter.Write("</td>"); } streamWriter.WriteLine("</tr>"); }