АвтоАвтоматизацияАрхитектураАстрономияАудитБиологияБухгалтерияВоенное делоГенетикаГеографияГеологияГосударствоДомДругоеЖурналистика и СМИИзобретательствоИностранные языкиИнформатикаИскусствоИсторияКомпьютерыКулинарияКультураЛексикологияЛитератураЛогикаМаркетингМатематикаМашиностроениеМедицинаМенеджментМеталлы и СваркаМеханикаМузыкаНаселениеОбразованиеОхрана безопасности жизниОхрана ТрудаПедагогикаПолитикаПравоПриборостроениеПрограммированиеПроизводствоПромышленностьПсихологияРадиоРегилияСвязьСоциологияСпортСтандартизацияСтроительствоТехнологииТорговляТуризмФизикаФизиологияФилософияФинансыХимияХозяйствоЦеннообразованиеЧерчениеЭкологияЭконометрикаЭкономикаЭлектроникаЮриспунденкция

Анализ атрибутов во время выполнения программы

Читайте также:
  1. A8 (базовый уровень, время – 2 мин)
  2. A8 (базовый уровень, время – 3 мин)
  3. B. Во время беременности и лактации
  4. B1 (базовый уровень, время – 1 мин)
  5. B7 (повышенный уровень, время – 2 мин)
  6. I. Понятие и анализ оборотного капитала
  7. II. Основные цели и задачи Программы, срок и этапы ее реализации, целевые индикаторы и показатели
  8. II. Требования к структуре образовательной программы дошкольного образования и ее объему
  9. III. Анализ изобразительно-выразительных средств, определение их роли в раскрытии идейного содержания произведения, выявлении авторской позиции.
  10. III. Анализ представленных работ
  11. IV период школы управления — информационный период (1960 г. по настоящее время).
  12. IV этап (середина XX в. по настоящее время)

 

An attribute instance is an instance that represents an attribute at run-time. An attribute is defined with an attribute class, positional arguments, and named arguments. An attribute instance is an instance of the attribute class that is initialized with the positional and named arguments.

 

Retrieval of an attribute instance involves both compile-time and run-time processing.

 

The compilation of an attribute with attribute class T, positional-argument-list P and named-argument-list N, consists of the following steps:

 

13. Follow the compile-time processing steps for compiling an object-creation-expression of the form new T(P). These steps either result in a compile-time error, or determine an instance constructor C on T that can be invoked at run-time.

14. If C does not have public accessibility, then a compile-time error occurs.

15. For each named-argument Arg in N:

· Let Name be the identifier of the named-argument Arg.

· Name must identify a non-static read-write public field or property on T. If T has no such field or property, then a compile-time error occurs.

16. Keep the following information for run-time instantiation of the attribute: the attribute class T, the instance constructor C on T, the positional-argument-list P and the named-argument-list N.

17. Compilation of an attribute yields an attribute class T, an instance constructor C on T, a positional-argument-list P, and a named-argument-list N. Given this information, an attribute instance can be retrieved at run-time using the following steps:

18. Follow the run-time processing steps for executing an object-creation-expression of the form new T(P), using the instance constructor C as determined at compile-time. These steps either result in an exception, or produce an instance O of T.

 

19. For each named-argument Arg in N, in order:

· Let Name be the identifier of the named-argument Arg. If Name does not identify a non-static public read-write field or property on O, then an exception is thrown.

· Let Value be the result of evaluating the attribute-argument-expression of Arg.

· If Name identifies a field on O, then set this field to Value.

· Otherwise, Name identifies a property on O. Set this property to Value.

· The result is O, an instance of the attribute class T that has been initialized with the positional-argument-list P and the named-argument-list N.

 

Indexers are implemented in.NET using indexed properties, and have a name in the.NET metadata. If no IndexerName attribute is present for an indexer, then the name Item is used by default. The IndexerName attribute enables a developer to override this default and specify a different name.

 

namespace System.Runtime.CompilerServices.CSharp
{
[AttributeUsage(AttributeTargets.Property)]
public class IndexerNameAttribute: Attribute
{
public IndexerNameAttribute(string indexerName) {...}

public string Value { get {...} }
}
}

Понятие рефлексии (reflection) в языке C#

 

The following example shows how attribute information for a given program entity can be retrieved at run-time using reflection.

 

using System;
using System.Reflection;

class Test
{
static void ShowHelp(MemberInfo member)

{
HelpAttribute a = Attribute.GetCustomAttribute(member,
typeof(HelpAttribute)) as HelpAttribute;
if (a == null) {
Console.WriteLine("No help for {0}", member);
}
else {
Console.WriteLine("Help for {0}:", member);
Console.WriteLine(" Url={0}, Topic={1}", a.Url, a.Topic);
}
}

 

static void Main() {
ShowHelp(typeof(Widget));
ShowHelp(typeof(Widget).GetMethod("Display"));
}
}

When a particular attribute is requested through reflection, the constructor for the attribute class is invoked with the information provided in the program source, and the resulting attribute instance is returned. If additional information was provided through properties, those properties are set to the given values before the attribute instance is returned.


1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |

Поиск по сайту:



Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав. Студалл.Орг (0.003 сек.)