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


C# Cecil.PropertyDefinition类代码示例

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


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


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