• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Cecil.PropertyDefinition类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



PropertyDefinition类属于Mono.Cecil命名空间,在下文中一共展示了PropertyDefinition类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: AnalyzedPropertyOverridesTreeNode

		public AnalyzedPropertyOverridesTreeNode(PropertyDefinition analyzedProperty)
		{
			if (analyzedProperty == null)
				throw new ArgumentNullException("analyzedProperty");

			this.analyzedProperty = analyzedProperty;
		}
开发者ID:FaceHunter,项目名称:ILSpy,代码行数:7,代码来源:AnalyzedPropertyOverridesTreeNode.cs


示例2: CheckIfGetterCallsVirtualBaseSetter

    public bool CheckIfGetterCallsVirtualBaseSetter(PropertyDefinition propertyDefinition)
    {
        if (propertyDefinition.SetMethod.IsVirtual)
        {
            var baseType = Resolve(propertyDefinition.DeclaringType.BaseType);
            var baseProperty = baseType.Properties.FirstOrDefault(x => x.Name == propertyDefinition.Name);

            if (baseProperty != null)
            {
                if (propertyDefinition.GetMethod != null)
                {
                    var instructions = propertyDefinition.GetMethod.Body.Instructions;
                    foreach (var instruction in instructions)
                    {
                        if (instruction.OpCode == OpCodes.Call
                            && instruction.Operand is MethodReference
                            && ((MethodReference) instruction.Operand).Resolve() == baseProperty.SetMethod)
                        {
                            return true;
                        }
                    }
                }
            }
        }

        return false;
    }
开发者ID:jbruening,项目名称:PropertyChanged,代码行数:27,代码来源:StackOverflowChecker.cs


示例3: CecilPropertyDescriptor

		public CecilPropertyDescriptor (CecilWidgetLibrary lib, XmlElement elem, Stetic.ItemGroup group, Stetic.ClassDescriptor klass, PropertyDefinition pinfo): base (elem, group, klass)
		{
			string tname;
			
			if (pinfo != null) {
				name = pinfo.Name;
				tname = pinfo.PropertyType.FullName;
				canWrite = pinfo.SetMethod != null;
			}
			else {
				name = elem.GetAttribute ("name");
				tname = elem.GetAttribute ("type");
				canWrite = elem.Attributes ["canWrite"] == null;
			}
			
			Load (elem);
			
			type = Stetic.Registry.GetType (tname, false);
			
			if (type == null) {
				Console.WriteLine ("Could not find type: " + tname);
				type = typeof(string);
			}
			if (type.IsValueType)
				initialValue = Activator.CreateInstance (type);
				
			// Consider all properties runtime-properties, since they have been created
			// from class properties.
			isRuntimeProperty = true;
			
			if (pinfo != null)
				SaveCecilXml (elem);
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:33,代码来源:CecilPropertyDescriptor.cs


示例4: AddBeforeAfterInvokerCall

    int AddBeforeAfterInvokerCall(int index, PropertyDefinition property)
    {
        var beforeVariable = new VariableDefinition(typeSystem.Object);
        setMethodBody.Variables.Add(beforeVariable);
        var afterVariable = new VariableDefinition(typeSystem.Object);
        setMethodBody.Variables.Add(afterVariable);
        var getMethod = property.GetMethod.GetGeneric();

        index = instructions.Insert(index,
                                    Instruction.Create(OpCodes.Ldarg_0),
                                    CreateCall(getMethod),
                                    Instruction.Create(OpCodes.Box, property.GetMethod.ReturnType),
                                    Instruction.Create(OpCodes.Stloc, afterVariable),
                                    Instruction.Create(OpCodes.Ldarg_0),
                                    Instruction.Create(OpCodes.Ldstr, property.Name),
                                    Instruction.Create(OpCodes.Ldloc, beforeVariable),
                                    Instruction.Create(OpCodes.Ldloc, afterVariable),
                                    CallEventInvoker()
            );

        instructions.Prepend(
            Instruction.Create(OpCodes.Ldarg_0),
            CreateCall(getMethod),
            Instruction.Create(OpCodes.Box, property.GetMethod.ReturnType),
            Instruction.Create(OpCodes.Stloc, beforeVariable));
        return index + 4;
    }
开发者ID:halad,项目名称:PropertyChanged,代码行数:27,代码来源:PropertyWeaver.cs


示例5: Add

        public void Add(PropertyDefinition value)
        {
            if (!Contains (value))
                Attach (value);

            List.Add (value);
        }
开发者ID:KenMacD,项目名称:deconfuser,代码行数:7,代码来源:PropertyDefinitionCollection.cs


示例6: SignatureForProperty

        private static string SignatureForProperty(PropertyDefinition property, bool hyperLinked)
        {
            var hb = new HtmlBuilder();
            if (property.IsStatic())
            {
                hb.AddKeyword("static");
                hb.Add(" ");
            }
            hb.AddKeyword("public");
            hb.Add(" ");
            hb.AddTypeReference(property.PropertyType, hyperLinked);
            hb.Add(" ");
            hb.AddMemberReferenceName(property, false);
            hb.Add(" {");
            if (property.GetMethod != null)
            {
                hb.Add(" ");
                hb.AddKeyword("get");
                hb.Add(";");
            }
            if (property.SetMethod != null)
            {
                hb.Add(" ");
                hb.AddKeyword("set");
                hb.Add(";");
            }
            hb.Add(" }");

            return hb.ToString();
        }
开发者ID:paveltimofeev,项目名称:documentation,代码行数:30,代码来源:CSharpSignatureProvider.cs


示例7: AddCollectionCode

        private static void AddCollectionCode(PropertyDefinition property, bool isFirst, Collection<Instruction> ins, VariableDefinition resultVariable, MethodDefinition method, TypeDefinition type)
        {
            if (isFirst)
            {
                ins.Add(Instruction.Create(OpCodes.Ldc_I4_0));
                ins.Add(Instruction.Create(OpCodes.Stloc, resultVariable));
            }

            ins.If(
                c =>
                {
                    LoadVariable(property, c, type);

                },
                t =>
                {
                    LoadVariable(property, t, type);
                    var enumeratorVariable = method.Body.Variables.Add(property.Name + "Enumarator", ReferenceFinder.IEnumerator.TypeReference);
                    var currentVariable = method.Body.Variables.Add(property.Name + "Current", ReferenceFinder.Object.TypeReference);

                    GetEnumerator(t, enumeratorVariable);

                    AddCollectionLoop(resultVariable, t, enumeratorVariable, currentVariable);
                },
                f => { });
        }
开发者ID:kzaikin,项目名称:Equals,代码行数:26,代码来源:GetHashCodeInjector.cs


示例8: Execute

        public static void Execute(PropertyDefinition property_definition, MethodDefinition notify_method, DependencyMap map)
        {
            // Check if notifications are already call, if so bail out
            foreach (var instruction in property_definition.SetMethod.Body.Instructions)
            {
                if (instruction.OpCode == OpCodes.Call)
                {
                    var method = instruction.Operand as MethodDefinition;
                    if (method != null && method == notify_method)
                    {
                        log.Trace("\t\t\t\t\tBailing out, notification found in property");
                        return;
                    }
                }
            }

            // Add notifications
            var ret = property_definition.SetMethod.Body.Instructions.Last(i => i.OpCode == OpCodes.Ret);
            ILProcessor processor = property_definition.SetMethod.Body.GetILProcessor();

            // NotifyPropertyChanged(property)
            processor.InsertBefore(ret, processor.Create(OpCodes.Ldarg_0));
            processor.InsertBefore(ret, processor.Create(OpCodes.Ldstr, property_definition.Name));
            processor.InsertBefore(ret, processor.Create(OpCodes.Call, notify_method));

            // Add notifications for dependent properties
            foreach (var target in map.GetDependenciesFor(property_definition.Name))
            {
                log.Trace("\t\t\t\t\tAdding dependency " + target);
                processor.InsertBefore(ret, processor.Create(OpCodes.Ldarg_0));
                processor.InsertBefore(ret, processor.Create(OpCodes.Ldstr, target));
                processor.InsertBefore(ret, processor.Create(OpCodes.Call, notify_method));
            }
        }
开发者ID:lycilph,项目名称:Projects,代码行数:34,代码来源:AddNotificationsToNormalPropertyTask.cs


示例9: GetSingleField

 static FieldDefinition GetSingleField(PropertyDefinition property, Code code, MethodDefinition methodDefinition)
 {
     if (methodDefinition?.Body == null)
     {
         return null;
     }
     FieldReference fieldReference = null;
     foreach (var instruction in methodDefinition.Body.Instructions)
     {
         if (instruction.OpCode.Code == code)
         {
             //if fieldReference is not null then we are at the second one
             if (fieldReference != null)
             {
                 return null;
             }
             var field = instruction.Operand as FieldReference;
             if (field != null)
             {
                 if (field.DeclaringType != property.DeclaringType)
                 {
                     continue;
                 }
                 if (field.FieldType != property.PropertyType)
                 {
                     continue;
                 }
                 fieldReference = field;
             }
         }
     }
     return fieldReference?.Resolve();
 }
开发者ID:Fody,项目名称:PropertyChanging,代码行数:33,代码来源:MappingFinder.cs


示例10: TryGetField

    static FieldDefinition TryGetField(TypeDefinition typeDefinition, PropertyDefinition property)
    {
        var propertyName = property.Name;
        var fieldsWithSameType = typeDefinition.Fields.Where(x => x.DeclaringType == typeDefinition).ToList();
        foreach (var field in fieldsWithSameType)
        {
            //AutoProp
            if (field.Name == $"<{propertyName}>k__BackingField")
            {
                return field;
            }
        }

        foreach (var field in fieldsWithSameType)
        {
            //diffCase
            var upperPropertyName = propertyName.ToUpper();
            var fieldUpper = field.Name.ToUpper();
            if (fieldUpper == upperPropertyName)
            {
                return field;
            }
            //underScore
            if (fieldUpper == "_" + upperPropertyName)
            {
                return field;
            }
        }
        return GetSingleField(property);
    }
开发者ID:Fody,项目名称:PropertyChanging,代码行数:30,代码来源:MappingFinder.cs


示例11: PropertyReferenceReflectionEmitter

        public PropertyReferenceReflectionEmitter(MemberReferenceExpression memberReferenceExpression,
                                                  Type target,
                                                  MemberInfo member,
                                                  ILGenerator ilGenerator,
                                                  IOpCodeIndexer instructionsIndexer,
                                                  IAstVisitor<ILGenerator, AstNode> visitor,
                                                  List<LocalBuilder> locals,
                                                  bool isSetter = false)
            : base(memberReferenceExpression, target, member, ilGenerator, instructionsIndexer, visitor, locals) {

            var propertyInfo = Member as PropertyInfo;

            _isSetter = isSetter;
            _propertyDefinition = MemberReference.Annotation<Cecil.PropertyDefinition>();
            NonPublic = !_propertyDefinition.GetMethod.IsPublic;
            Type = _propertyDefinition.PropertyType.GetActualType();

            if (isSetter) {
                _propertyMethod = propertyInfo.GetSetMethod(NonPublic);
                _emitPrivateAction = EmitPrivateStorePropertyReference;
            }
            else {
                _propertyMethod = propertyInfo.GetGetMethod(NonPublic);
                _emitPrivateAction = EmitPrivateLoadPropertyReference;
            }
        }
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:26,代码来源:PropertyReferenceReflectionEmitter.cs


示例12: AddPropertySetter

        public static MethodDefinition AddPropertySetter(
            PropertyDefinition property
            , MethodAttributes methodAttributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.NewSlot | MethodAttributes.Virtual
            , FieldDefinition backingField = null)
        {
            if (backingField == null)
            {
                // TODO: Try and find existing friendly named backingFields first.
                backingField = AddPropertyBackingField(property);
            }

            var methodName = "set_" + property.Name;
            var setter = new MethodDefinition(methodName, methodAttributes, property.Module.TypeSystem.Void)
            {
                IsSetter = true,
                Body = { InitLocals = true },
            };
            setter.Parameters.Add(new ParameterDefinition("value", ParameterAttributes.None, property.PropertyType));
            setter.Body.Instructions.Append(
                Instruction.Create(OpCodes.Ldarg_0),
                Instruction.Create(OpCodes.Ldarg_1),
                Instruction.Create(OpCodes.Stfld, backingField),
                Instruction.Create(OpCodes.Ret)
                );

            property.SetMethod = setter;
            property.DeclaringType.Methods.Add(setter);
            return setter;
        }
开发者ID:brainoffline,项目名称:Commander.Fody,代码行数:29,代码来源:CommandPropertyInjector.cs


示例13: AddPropertyGetter

        public static MethodDefinition AddPropertyGetter(
            PropertyDefinition property
            , MethodAttributes methodAttributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.NewSlot | MethodAttributes.Virtual
            , FieldDefinition backingField = null)
        {
            if (backingField == null)
            {
                // TODO: Try and find existing friendly named backingFields first.
                backingField = AddPropertyBackingField(property);
            }

            var methodName = "get_" + property.Name;
            var getter = new MethodDefinition(methodName, methodAttributes, property.PropertyType)
            {
                IsGetter = true,
                Body = {InitLocals = true},
            };

            getter.Body.Variables.Add(new VariableDefinition(property.PropertyType));

            var returnStart = Instruction.Create(OpCodes.Ldloc_0);
            getter.Body.Instructions.Append(
                Instruction.Create(OpCodes.Ldarg_0),
                Instruction.Create(OpCodes.Ldfld, backingField),
                Instruction.Create(OpCodes.Stloc_0),
                Instruction.Create(OpCodes.Br_S, returnStart),
                returnStart,
                Instruction.Create(OpCodes.Ret)
                );        
                
            property.GetMethod = getter;
            property.DeclaringType.Methods.Add(getter);
            return getter;
        }
开发者ID:brainoffline,项目名称:Commander.Fody,代码行数:34,代码来源:CommandPropertyInjector.cs


示例14: ChangeFieldReferencesToPropertyVisitor

 public ChangeFieldReferencesToPropertyVisitor(FieldDefinition field, PropertyDefinition property)
 {
     if (field == null) throw new ArgumentNullException("field");
       if (property == null) throw new ArgumentNullException("property");
       _field = field;
       _property = property;
 }
开发者ID:cessationoftime,项目名称:nroles,代码行数:7,代码来源:ChangeFieldReferencesToPropertyVisitor.cs


示例15: InstantiateCollection

        private void InstantiateCollection(TypeDefinition typeDef, MethodDefinition[] constructors, PropertyDefinition propDef) {
            var constructor = constructors.First();
            if (constructors.Length > 1) {
                constructor = constructors.SingleOrDefault(s => !s.HasParameters && !s.IsStatic);
                if (constructor == null) {
                    this.Log.Error("Type " + typeDef.FullName + " does not have a parameterless constructor for instantiating collections in");
                }
            }

            var insertIdx = constructor.Body.Instructions.Count - 1;
            constructor.Body.Instructions.Insert(insertIdx++, Instruction.Create(OpCodes.Nop));
            constructor.Body.Instructions.Insert(insertIdx++, Instruction.Create(OpCodes.Ldarg_0));
            constructor.Body.Instructions.Insert(
                insertIdx++,
                Instruction.Create(
                    OpCodes.Newobj,
                    MakeGeneric(
                        typeDef.Module.Import(
                            typeDef.Module.Import(typeof(List<>))
                                   .MakeGenericInstanceType(propDef.PropertyType)
                                   .Resolve()
                                   .GetConstructors()
                                   .First(c => !c.HasParameters)),
                        ((GenericInstanceType)propDef.PropertyType).GenericArguments.First())));
            constructor.Body.Instructions.Insert(insertIdx, Instruction.Create(OpCodes.Call, propDef.SetMethod));
        }
开发者ID:Polylytics,项目名称:dashing,代码行数:26,代码来源:CollectionInstantiationWeaver.cs


示例16: AddBeforeAfterInvokerCall

    int AddBeforeAfterInvokerCall(int index, PropertyDefinition property)
    {
        var beforeVariable = new VariableDefinition(msCoreReferenceFinder.ObjectTypeReference);
        setMethodBody.Variables.Add(beforeVariable);
        var afterVariable = new VariableDefinition(msCoreReferenceFinder.ObjectTypeReference);
        setMethodBody.Variables.Add(afterVariable);
        var isVirtual = property.GetMethod.IsVirtual;
        var getMethod = property.GetMethod.GetGeneric();

        index = instructions.Insert(index,
                                    Instruction.Create(OpCodes.Ldarg_0),
                                    CreateCall(getMethod),
                                    //TODO: look into why this box is required
                                    Instruction.Create(OpCodes.Box, property.GetMethod.ReturnType),
                                    Instruction.Create(OpCodes.Stloc, afterVariable),
                                    Instruction.Create(OpCodes.Ldarg_0),
                                    Instruction.Create(OpCodes.Ldstr, property.Name),
                                    Instruction.Create(OpCodes.Ldloc, beforeVariable),
                                    Instruction.Create(OpCodes.Ldloc, afterVariable),
                                    CallEventInvoker()
            );

        instructions.Prepend(
            Instruction.Create(OpCodes.Ldarg_0),
            CreateCall(getMethod),
            //TODO: look into why this box is required
            Instruction.Create(OpCodes.Box, property.GetMethod.ReturnType),
            Instruction.Create(OpCodes.Stloc, beforeVariable));
        return index + 4;
    }
开发者ID:marcuswhit,项目名称:NotifyPropertyWeaver,代码行数:30,代码来源:PropertyWeaver.cs


示例17: ProcessProperty

		public override void ProcessProperty (PropertyDefinition property)
		{
			foreach (var attribute in GetPreserveAttributes (property)) {
				MarkMethod (property.GetMethod, attribute);
				MarkMethod (property.SetMethod, attribute);
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:7,代码来源:ApplyPreserveAttributeBase.cs


示例18: AlreadyHasEquality

    public static bool AlreadyHasEquality(PropertyDefinition propertyDefinition, FieldReference backingFieldReference)
    {
        var instructions = propertyDefinition.SetMethod.Body.Instructions;
        var list = instructions.Where(IsNotNop).ToList();
        if (list.Count < 4)
        {
            return false;
        }
        var firstFive = list.Take(5).ToList();
        if (firstFive.All(x => x.OpCode != OpCodes.Ldarg_1))
        {
            return false;
        }
        if (firstFive.All(x => x.OpCode != OpCodes.Ldarg_0))
        {
            return false;
        }
        if (firstFive.All(x => !x.IsEquality()))
        {
            return false;
        }

        if (firstFive.Any(x => x.Operand == backingFieldReference))
        {
            return true;
        }
        if (firstFive.Any(x => x.Operand == propertyDefinition))
        {
            return true;
        }
        return false;
    }
开发者ID:dj-pgs,项目名称:PropertyChanged,代码行数:32,代码来源:HasEqualityChecker.cs


示例19: AddGetItem

    void AddGetItem()
    {
        var method = new MethodDefinition(DataErrorInfoFinder.InterfaceRef.FullName + ".get_Item", MethodAttributes, TypeSystem.String)
                             {
                                 IsGetter = true,
                                 IsPrivate = true,
                                 SemanticsAttributes = MethodSemanticsAttributes.Getter,
                             };
        method.Overrides.Add(DataErrorInfoFinder.GetItemMethod);
        method.Parameters.Add(new ParameterDefinition(TypeSystem.String));

        method.Body.Instructions.Append(
            Instruction.Create(OpCodes.Ldarg_0),
            Instruction.Create(OpCodes.Ldfld, ValidationTemplateField),
            Instruction.Create(OpCodes.Ldarg_1),
            Instruction.Create(OpCodes.Callvirt, DataErrorInfoFinder.GetItemMethod),
            Instruction.Create(OpCodes.Ret));
        var property = new PropertyDefinition(DataErrorInfoFinder.InterfaceRef.FullName + ".Item", PropertyAttributes.None, TypeSystem.String)
                           {
                               GetMethod = method,
                           };
        TypeDefinition.Methods.Add(method);

        TypeDefinition.Properties.Add(property);
    }
开发者ID:kedarvaidya,项目名称:Validar,代码行数:25,代码来源:DataErrorInfoInjector.cs


示例20: GetAlreadyNotifies

    public IEnumerable<string> GetAlreadyNotifies(PropertyDefinition propertyDefinition)
    {
        if (propertyDefinition.SetMethod.IsAbstract)
        {
            yield break;
        }
        var instructions = propertyDefinition.SetMethod.Body.Instructions;
        for (var index = 0; index < instructions.Count; index++)
        {
            var instruction = instructions[index];
            foreach (var methodName in EventInvokerNames)
            {

                int propertyNameIndex;
                if (instruction.IsCallToMethod(methodName, out propertyNameIndex))
                {
                    var before = instructions[index - propertyNameIndex];
                    if (before.OpCode == OpCodes.Ldstr)
                    {
                        yield return (string) before.Operand;
                    }
                }
            }
        }
    }
开发者ID:dj-pgs,项目名称:PropertyChanged,代码行数:25,代码来源:AlreadyNotifyFinder.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Cecil.Range类代码示例发布时间:2022-05-26
下一篇:
C# Cecil.ParameterDefinition类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap