本文整理汇总了C#中Mono.Cecil.TypeDefinition.GetField方法的典型用法代码示例。如果您正苦于以下问题:C# TypeDefinition.GetField方法的具体用法?C# TypeDefinition.GetField怎么用?C# TypeDefinition.GetField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Cecil.TypeDefinition
的用法示例。
在下文中一共展示了TypeDefinition.GetField方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateNewField
/// <summary>
/// Creates a new field in the target assembly, for the specified type.
/// </summary>
/// <param name="targetDeclaringType">The target declaring type.</param>
/// <param name="yourField">Your field.</param>
/// <param name="attr">The action attribute.</param>
/// <exception cref="PatchDeclerationException">Thrown if this member collides with another member, and the error cannot be resolved.</exception>
/// <returns></returns>
private NewMemberStatus CreateNewField(TypeDefinition targetDeclaringType, FieldDefinition yourField,
NewMemberAttribute attr)
{
if (attr.IsImplicit) {
Log_implicitly_creating_member("field", yourField);
} else {
Log_creating_member("field", yourField);
}
var maybeDuplicate = targetDeclaringType.GetField(yourField.Name);
if (maybeDuplicate != null) {
Log_duplicate_member("field", yourField, maybeDuplicate);
if ((DebugOptions & DebugFlags.CreationOverwrites) != 0) {
Log_overwriting();
return NewMemberStatus.Continue;
}
if (attr.IsImplicit) {
return NewMemberStatus.InvalidItem;
}
throw Errors.Duplicate_member("type", yourField.FullName, maybeDuplicate.FullName);
}
var targetField =
new FieldDefinition(yourField.Name, yourField.Resolve().Attributes, FixTypeReference(yourField.FieldType)) {
InitialValue = yourField.InitialValue, //probably for string consts
Constant = yourField.Constant
};
targetDeclaringType.Fields.Add(targetField);
return NewMemberStatus.Continue;
}
示例2: AutoModifyField
private void AutoModifyField(TypeDefinition targetType, MemberActionAttribute fieldActionAttr,
FieldDefinition yourField)
{
Log_modifying_member("field", yourField);
(fieldActionAttr != null).AssertTrue();
var asModifies = fieldActionAttr as ModifiesMemberAttribute;
string targetFieldName = null;
ModificationScope scope;
if (asModifies != null) {
targetFieldName = asModifies.MemberName ?? yourField.Name;
scope = asModifies.Scope;
} else if (fieldActionAttr is NewMemberAttribute) {
targetFieldName = yourField.Name;
scope = ModificationScope.All;
} else {
throw Errors.Unknown_action_attribute(fieldActionAttr);
}
var targetField = targetType.GetField(targetFieldName);
if (targetField == null) {
throw Errors.Missing_member("field", yourField, targetFieldName);
}
if ((scope & ModificationScope.Accessibility) != 0) {
targetField.SetAccessibility(yourField.GetAccessbility());
}
if ((scope & ModificationScope.CustomAttributes) != 0) {
CopyCustomAttributes(targetField, yourField);
}
if ((scope & ModificationScope.Body) != 0) {
targetField.InitialValue = yourField.InitialValue; //dunno what this is used for
targetField.Constant = yourField.Constant;
}
}
示例3: InjectInto
public static void InjectInto(AssemblyDefinition asm)
{
_asm = asm;
_main = asm.MainModule.GetType("Terraria.Main");
_spriteBatch = _main.GetField("spriteBatch");
_hooksClass = _asm.MainModule.GetType("Terraria.PrismInjections.Hooks");
_typeSystem = _asm.MainModule.TypeSystem;
InjectItemHook();
InjectProjectileHook();
InjectNPCHook();
InjectDrawInterfaceCalls();
InjectInputUpdate();
}
示例4: CreateNewField
/// <summary>
/// Creates a new field in the target assembly, for the specified type.
/// </summary>
/// <param name="targetDeclaringType">The target declaring type.</param>
/// <param name="yourField">Your field.</param>
/// <param name="attr">The action attribute.</param>
/// <exception cref="PatchDeclerationException">Thrown if this member collides with another member, and the error cannot be resolved.</exception>
/// <returns></returns>
private FieldDefinition CreateNewField(TypeDefinition targetDeclaringType, FieldDefinition yourField,
NewMemberAttribute attr)
{
if (attr.IsImplicit) {
Log_implicitly_creating_member("field", yourField);
} else {
Log_creating_member("field", yourField);
}
var newName = attr.NewMemberName ?? yourField.Name;
var maybeDuplicate = targetDeclaringType.GetField(newName);
if (maybeDuplicate != null) {
var prevName = newName;
Log_duplicate_member("field", yourField, maybeDuplicate);
newName = GetNameAfterCollision(newName);
Log_name_changed("field", yourField, prevName, newName);
}
var targetField = CopyField(yourField, newName);
targetDeclaringType.Fields.Add(targetField);
return targetField;
}
示例5: AssertField
static void AssertField (TypeDefinition type, string name, Type expected)
{
var field = type.GetField (name);
Assert.IsNotNull (field, name);
Assert.AreEqual (expected.FullName, field.FieldType.FullName);
}