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


C# TypeDefinition.GetProperty方法代码示例

本文整理汇总了C#中Mono.Cecil.TypeDefinition.GetProperty方法的典型用法代码示例。如果您正苦于以下问题:C# TypeDefinition.GetProperty方法的具体用法?C# TypeDefinition.GetProperty怎么用?C# TypeDefinition.GetProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mono.Cecil.TypeDefinition的用法示例。


在下文中一共展示了TypeDefinition.GetProperty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateNewProperty

        /// <summary>
        ///     Creates a new property in the target assembly, but doesn't set its accessors.
        /// </summary>
        /// <param name="targetType">Type of the target.</param>
        /// <param name="yourProperty">Your property.</param>
        /// <param name="newPropAttr">The new property attribute.</param>
        /// <exception cref="PatchDeclerationException">Thrown if this member collides with another member, and the error cannot be resolved.</exception>
        private NewMemberStatus CreateNewProperty(TypeDefinition targetType, PropertyDefinition yourProperty,
			NewMemberAttribute newPropAttr)
        {
            if (newPropAttr.IsImplicit) {
                Log_implicitly_creating_member("property", yourProperty);

            } else {
                Log_creating_member("property", yourProperty);
            }
            var maybeDuplicate = targetType.GetProperty(yourProperty.Name,
                yourProperty.Parameters.Select(x => x.ParameterType));
            if (maybeDuplicate != null) {
                Log_duplicate_member("property", yourProperty, maybeDuplicate);
                if ((DebugOptions & DebugFlags.CreationOverwrites) != 0) {
                    Log_overwriting();
                    return NewMemberStatus.Continue;
                }
                if (newPropAttr.IsImplicit) {
                    return NewMemberStatus.InvalidItem;
                }
                throw Errors.Duplicate_member("property", yourProperty.FullName, maybeDuplicate.FullName);
            }
            var targetPropertyType = FixTypeReference(yourProperty.PropertyType);
            var targetProperty = new PropertyDefinition(yourProperty.Name,
                yourProperty.Attributes,
                targetPropertyType) {
                    HasThis = yourProperty.HasThis,
                    Constant =  yourProperty.Constant,
                    HasDefault = yourProperty.HasDefault
                };
            targetType.Properties.Add(targetProperty);
            foreach (var param in yourProperty.Parameters) {
                targetProperty.Parameters.Add(new ParameterDefinition(param.Name, param.Attributes,
                    FixTypeReference(param.ParameterType)));
            }
            return NewMemberStatus.Continue;
        }
开发者ID:gitter-badger,项目名称:Patchwork,代码行数:44,代码来源:CreateNew.cs

示例2: CreateNewProperty

        /// <summary>
        ///     Creates a new property in the target assembly, but doesn't set its accessors.
        /// </summary>
        /// <param name="targetType">Type of the target.</param>
        /// <param name="yourProperty">Your property.</param>
        /// <param name="newPropAttr">The new property attribute.</param>
        /// <exception cref="PatchDeclerationException">Thrown if this member collides with another member, and the error cannot be resolved.</exception>
        private PropertyDefinition CreateNewProperty(TypeDefinition targetType, PropertyDefinition yourProperty,
			NewMemberAttribute newPropAttr)
        {
            if (newPropAttr.IsImplicit) {
                Log_implicitly_creating_member("property", yourProperty);
            } else {
                Log_creating_member("property", yourProperty);
            }
            var newName = newPropAttr.NewMemberName ?? yourProperty.Name;
            var maybeDuplicate = targetType.GetProperty(newName, yourProperty.Parameters.Select(x => x.ParameterType));

            if (maybeDuplicate != null) {
                Log_duplicate_member("property", yourProperty, maybeDuplicate);
                newName = GetNameAfterCollision(newName);
                var prevName = newName;
                Log_name_changed("property", yourProperty, prevName, newName);
            }
            var targetProperty = CopyProperty(yourProperty, newName);
            targetType.Properties.Add(targetProperty);
            return targetProperty;
        }
开发者ID:GregRos,项目名称:Patchwork,代码行数:28,代码来源:CreateNew.cs

示例3: AutoModifyProperty

        private void AutoModifyProperty(TypeDefinition targetType, MemberActionAttribute propActionAttr,
			PropertyDefinition yourProp)
        {
            Log_modifying_member("property", yourProp);
            var modifiesMemberAttr = propActionAttr as ModifiesMemberAttribute;
            var newMemberAttr = propActionAttr as NewMemberAttribute;
            string targetPropName;
            ModificationScope scope;

            if (modifiesMemberAttr != null) {
                targetPropName = modifiesMemberAttr.MemberName ?? yourProp.Name;
                scope = modifiesMemberAttr.Scope;
            } else if (newMemberAttr != null) {
                targetPropName = yourProp.Name;
                scope = ModificationScope.All;
            } else {
                throw Errors.Unknown_action_attribute(propActionAttr);
            }
            var targetProp = targetType.GetProperty(targetPropName,
                yourProp.Parameters.Select(x => x.ParameterType));
            if (targetProp == null) {
                throw Errors.Missing_member("property", yourProp, targetPropName);
            }

            if ((scope & ModificationScope.CustomAttributes) != 0) {
                CopyCustomAttributes(targetProp, yourProp);
                for (int i = 0; i < yourProp.Parameters.Count; i++) {
                    CopyCustomAttributes(targetProp.Parameters[i], yourProp.Parameters[i]);
                }
            }
            if ((scope & ModificationScope.Body) != 0) {
                targetProp.GetMethod = yourProp.GetMethod != null ? FixMethodReference(yourProp.GetMethod).Resolve() : null;
                targetProp.SetMethod = yourProp.SetMethod != null ? FixMethodReference(yourProp.SetMethod).Resolve() : null;
                targetProp.OtherMethods.Clear();
                if (yourProp.HasOtherMethods) {
                    //I have absolutely NO idea what this is used for
                    foreach (var otherMethod in yourProp.OtherMethods) {
                        targetProp.OtherMethods.Add(FixMethodReference(otherMethod).Resolve());
                    }
                }
            }
        }
开发者ID:gitter-badger,项目名称:Patchwork,代码行数:42,代码来源:ModifyExisting.cs


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