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


C# TypeDefinition.GetField方法代码示例

本文整理汇总了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;
        }
开发者ID:gitter-badger,项目名称:Patchwork,代码行数:36,代码来源:CreateNew.cs

示例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;
            }
        }
开发者ID:gitter-badger,项目名称:Patchwork,代码行数:32,代码来源:ModifyExisting.cs

示例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();
        }
开发者ID:chatrat12,项目名称:Prism,代码行数:14,代码来源:HookInjector.cs

示例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;
        }
开发者ID:GregRos,项目名称:Patchwork,代码行数:28,代码来源:CreateNew.cs

示例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);
		}
开发者ID:95ulisse,项目名称:ILEdit,代码行数:7,代码来源:FieldTests.cs


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