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


C# Cecil.CustomAttribute类代码示例

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


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

示例1: ShowDialog

 public virtual DialogResult ShowDialog(CustomAttribute attribute, CustomAttributeNamedArgument? argument, bool usefields)
 {
     m_selectedargument = argument;
     m_selectedattribute = attribute;
     m_usefields = usefields;
     return base.ShowDialog();
 }
开发者ID:SAD1992,项目名称:justdecompile-plugins,代码行数:7,代码来源:CustomAttributeNamedArgumentForm.cs

示例2: Transform

        /// <summary>
        /// Public translation interface.
        /// Translates the given method to GLSL
        /// </summary>
        /// <param name="s">Shader type definition.</param>
        /// <param name="m">A method representing a shader to translate.</param>
        /// <param name="attr">The shader type as attribute (either FragmentShaderAttribute or VertexShaderAttribute</param>
        /// <param name="type">The shader type as ShaderType</param>
        /// <returns>The translated GLSL shader source</returns>
        public FunctionDescription Transform(TypeDefinition s, MethodDefinition m, CustomAttribute attr,
            ShaderType type)
        {
            if (s == null)
                throw new ArgumentNullException("s");

            if (m == null)
                throw new ArgumentNullException("m");

            if (attr == null)
                throw new ArgumentNullException("attr");

            var ctx = new DecompilerContext(s.Module)
            {
                CurrentType = s,
                CurrentMethod = m,
                CancellationToken = CancellationToken.None
            };

            var d = AstMethodBodyBuilder.CreateMethodBody(m, ctx);

            var glsl = new GlslVisitor(d, attr, ctx);

            _functions.UnionWith(glsl.Functions);

            var entry = (bool)attr.ConstructorArguments.FirstOrDefault().Value;
            var sig = entry ? "void main()" : GlslVisitor.GetSignature(m);

            var code = glsl.Result;
            var desc = new FunctionDescription(entry ? "main" : Shader.GetMethodName(m), sig + code, entry, type);

            _dependencies.UnionWith(glsl.Dependencies);

            return desc;
        }
开发者ID:mono-soc-2011,项目名称:SLSharp,代码行数:44,代码来源:GlslTransform.cs

示例3: AppliedPatchInfo

        public AppliedPatchInfo(CustomAttribute cecilCustomAttribute)
        {
            _cecilCustomAttribute = cecilCustomAttribute;
            Name =  cecilCustomAttribute.Fields.Single(f => f.Name == "Name").Argument.Value.ToString();

            Version = int.Parse(
                cecilCustomAttribute.Fields.Single(f => f.Name == "Version").Argument.Value.ToString()
                );

            var catStr = PatchCategory.Unknown.ToString();
            var catField = cecilCustomAttribute.Fields.SingleOrDefault(f => f.Name == "Category");
            if (catField.Name == "Category")
            {
                catStr = catField.Argument.Value.ToString();
            }

            PatchCategory catTemp = PatchCategory.Unknown;
            Enum.TryParse(catStr, true, out catTemp);
            Category = catTemp;

            var codeBlocksObj = cecilCustomAttribute.Fields.SingleOrDefault(f => f.Name == "CodeBlocks");

            if (codeBlocksObj.Name == "CodeBlocks")
            {
                AppliedCodeBlocks = AppliedCodeBlock.Deserialise(codeBlocksObj.Argument.Value.ToString());
            }
            else
            {
                AppliedCodeBlocks = new List<AppliedCodeBlock>();
            }
        }
开发者ID:nugarin,项目名称:sotsos,代码行数:31,代码来源:AppliedPatchInfo.cs

示例4: Visit

        public void Visit(IBehaviorDefinition method, CustomAttribute attribute)
        {
            ILProcessor processor = method.Body.GetILProcessor();
            string description = attribute.Properties.Where(argument => (argument.Name == "Description")).First().Argument.Value as string;
            Instruction exitInstruction = processor.Create(OpCodes.Callvirt, method.Module.Import(broadcastType.GetMethod("Run", new[] {typeof(object), typeof(string)})));
            var returnValue = new VariableDefinition("retVal", method.Module.Import(typeof(object)));
            var enclosingObject = new VariableDefinition("enclosing", method.Module.Import(typeof(object)));
            method.Body.Variables.Add(enclosingObject);
            method.Body.Variables.Add(returnValue);
            Instruction store = processor.Create(OpCodes.Stloc, returnValue);
            Instruction reload = processor.Create(OpCodes.Ldloc, returnValue);
            var instructions = new List<Instruction>();
            if (!ReturnsVoid(method))
            {
                instructions.Add(store);
            }
            instructions.Add(processor.Create(OpCodes.Newobj, method.Module.Import(broadcastType.GetConstructor(new Type[] { }))));
            instructions.Add(processor.Create(OpCodes.Ldarg_0));
            instructions.Add(processor.Create(OpCodes.Ldstr, description));
            instructions.Add(exitInstruction);
            if (!ReturnsVoid(method))
            {
                instructions.Add(reload);
            }

            new InsertionAtEnd(processor, method).Run(instructions);
        }
开发者ID:asengupta,项目名称:Exo,代码行数:27,代码来源:PublishSelfWeave.cs

示例5: WillRemoveAttribute

        protected override void WillRemoveAttribute(ICustomAttributeProvider provider, CustomAttribute attribute)
        {
            var attr_type = attribute.Constructor.DeclaringType;
            if (attr_type.Namespace == Namespaces.ObjCRuntime) {
                switch (attr_type.Name) {
                case "AvailabilityAttribute":
                case "AvailabilityBaseAttribute":
                case "DeprecatedAttribute":
                case "IntroducedAttribute":
                    var dict = context.Annotations.GetCustomAnnotations ("Availability");
                    List<CustomAttribute> attribs;
                    object attribObjects;
                    if (!dict.TryGetValue (provider, out attribObjects)) {
                        attribs = new List<CustomAttribute> ();
                        dict [provider] = attribs;
                    } else {
                        attribs = (List<CustomAttribute>) attribObjects;
                    }
                    // Make sure the attribute is resolved, since after removing the attribute
                    // it won't be able to do it. The 'CustomAttribute.Resolve' method is private, but fetching
                    // any property will cause it to be called.
                    var dummy = attribute.HasConstructorArguments;
                    attribs.Add (attribute);
                    break;
                }
            }

            base.WillRemoveAttribute (provider, attribute);
        }
开发者ID:yudhitech,项目名称:xamarin-macios,代码行数:29,代码来源:CoreRemoveAttributes.cs

示例6: DomCecilAttribute

		/*CustomAttribute customAttribute;
		
		public CustomAttribute CustomAttribute {
			get {
				return customAttribute;
			}
		}*/
		
		public DomCecilAttribute (CustomAttribute customAttribute)
		{
			//this.customAttribute = customAttribute;
			base.AttributeType = DomCecilMethod.GetReturnType (customAttribute.Constructor);
			base.Name          = customAttribute.Constructor.DeclaringType.FullName;
			
			try {
				foreach (var argument in customAttribute.ConstructorArguments)
					AddPositionalArgument (CreateExpressionFor (argument));
			} catch (Exception e) {
				LoggingService.LogError ("Error reading attributes", e);
			}
			
			try {
				foreach (var namedArgument in customAttribute.Properties)
					AddNamedArgument (namedArgument.Name, CreateExpressionFor (namedArgument.Argument));
			} catch (Exception e) {
				LoggingService.LogError ("Error reading attributes", e);
			}
			
			try {
				foreach (var namedArgument in customAttribute.Fields)
					AddNamedArgument (namedArgument.Name, CreateExpressionFor (namedArgument.Argument));
			} catch (Exception e) {
				LoggingService.LogError ("Error reading attributes", e);
			}
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:35,代码来源:DomCecilAttribute.cs

示例7: Visit

        public void Visit(IBehaviorDefinition behaviorDefinition, CustomAttribute attribute)
        {
            ILProcessor processor = behaviorDefinition.Body.GetILProcessor();
            var pingerDefinition = new VariableDefinition("pinger",
                                                          behaviorDefinition.Module.Import(breakpointType));
            behaviorDefinition.Body.Variables.Add(pingerDefinition);
            var sequencedInstructions =
                behaviorDefinition.Body.Instructions.Where(instruction => instruction.SequencePoint != null).ToList();

            Console.Out.WriteLine(sequencedInstructions.Count);
            //            var extractedInstructions = Specific(sequencedInstructions, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 20, 21);
            var extractedInstructions = Filtered(sequencedInstructions);
            foreach (var instruction in extractedInstructions)
            {
                Type intType = typeof(int);
                var breakPointInstructions = new List<Instruction>
                                       {
                                           processor.Create(OpCodes.Newobj, behaviorDefinition.Module.Import(
                                                                                breakpointType.GetConstructor(new Type[]{}))),
                                           processor.Create(OpCodes.Ldc_I4, instruction.SequencePoint.StartLine),
                                           processor.Create(OpCodes.Ldc_I4, instruction.SequencePoint.StartColumn),
                                           processor.Create(OpCodes.Ldc_I4, instruction.SequencePoint.EndLine),
                                           processor.Create(OpCodes.Ldc_I4, instruction.SequencePoint.EndColumn),
                                           processor.Create(OpCodes.Ldstr, instruction.SequencePoint.Document.Url),
                                           processor.Create(OpCodes.Call,
                                                            behaviorDefinition.Module.Import(breakpointType.GetMethod("Activate",
                                                                                                                      new[] {intType, intType, intType, intType, typeof(string)})))
                                       };
                breakPointInstructions.ForEach(bpr => processor.InsertBefore(instruction, bpr));
                foreach (var i in behaviorDefinition.Body.Instructions)
                {
                    Console.Out.WriteLine("{0}/[{1}]: {2} {3}", i.Offset, Sequence(i.SequencePoint), i.OpCode, i.Operand);
                }
            }
        }
开发者ID:asengupta,项目名称:Exo,代码行数:35,代码来源:DebugWeave.cs

示例8: Visit

        public void Visit(IBehaviorDefinition method, CustomAttribute attribute)
        {
            ILProcessor processor = method.Body.GetILProcessor();
            string description = attribute.Properties.Where(argument => (argument.Name == "Description")).First().Argument.Value as string;
            var listType = typeof(List<object>);
            var listVariable = new VariableDefinition("argumentz", method.Module.Import(listType));
            method.Body.Variables.Add(listVariable);
            var instructions = new List<Instruction>();
            instructions.Add(processor.Create(OpCodes.Newobj, method.Module.Import(listType.GetConstructor(new Type[] { }))));
            instructions.Add(processor.Create(OpCodes.Stloc, listVariable));

            int parameterIndex = 1;
            foreach (var parameter in method.Parameters)
            {
                instructions.Add(processor.Create(OpCodes.Ldloc, listVariable));
                instructions.Add(processor.Create(OpCodes.Ldarg, parameterIndex));
                if (parameter.ParameterType.IsPrimitive || parameter.ParameterType.IsValueType)
                    instructions.Add(processor.Create(OpCodes.Box, parameter.ParameterType));
                instructions.Add(processor.Create(OpCodes.Callvirt, method.Module.Import(listType.GetMethod("Add", new[] { typeof(object) }))));
                ++parameterIndex;
            }
            instructions.Add(processor.Create(OpCodes.Newobj, method.Module.Import(broadcastType.GetConstructor(new Type[] {}))));
            instructions.Add(processor.Create(OpCodes.Ldloc, listVariable));
            instructions.Add(processor.Create(OpCodes.Ldstr, description));
            instructions.Add(processor.Create(OpCodes.Callvirt, method.Module.Import(broadcastType.GetMethod("Run", new[] {listType, typeof(string)}))));

            new InsertionAtStart(processor, method).Run(instructions);
        }
开发者ID:asengupta,项目名称:Exo,代码行数:28,代码来源:PublishArgumentsWeave.cs

示例9: InjectCustomAttribute

        public CustomAttribute InjectCustomAttribute(Mono.Cecil.ICustomAttributeProvider target, CustomAttribute attribute)
        {
            if(module == null)
                throw new ArgumentNullException("module");
            if(target == null)
                throw new ArgumentNullException("target");
            if(attribute == null)
                throw new ArgumentNullException("attribute");

            TypeReference attributeType = ReferenceOrInjectType(attribute.AttributeType);

            // no context required as attributes cannot be generic
            MethodReference constructor = ReferenceOrInjectMethod(attribute.Constructor);

            CustomAttribute newAttribute;

            if((newAttribute = Helper.GetCustomAttribute(target.CustomAttributes, attribute)) != null)
                return newAttribute;

            newAttribute = new CustomAttribute(constructor);//, attr.GetBlob());

            target.CustomAttributes.Add(newAttribute);

            CopyCustomAttributeArguments(attribute.ConstructorArguments, newAttribute.ConstructorArguments);

            CopyCustomAttributeNamedArguments(attribute.Fields, newAttribute.Fields);

            CopyCustomAttributeNamedArguments(attribute.Properties, newAttribute.Properties);

            return newAttribute;
        }
开发者ID:Cadla,项目名称:OBFSCTR,代码行数:31,代码来源:AssemblyBuilder.cs

示例10: IsRemovedAttribute

 protected override bool IsRemovedAttribute(CustomAttribute attribute)
 {
     // note: this also avoid calling FullName (which allocates a string)
     var attr_type = attribute.Constructor.DeclaringType;
     switch (attr_type.Name) {
     case "AdviceAttribute":
     case "FieldAttribute":
     case "PreserveAttribute":	// the ApplyPreserveAttribute substep is executed before this
     case "LinkerSafeAttribute":
         return attr_type.Namespace == Namespaces.Foundation;
     // used for documentation, not at runtime
     case "AvailabilityAttribute":
     case "AvailabilityBaseAttribute":
     case "DeprecatedAttribute":
     case "IntroducedAttribute":
     case "iOSAttribute":
     case "MacAttribute":
     case "LionAttribute":
     case "MountainLionAttribute":
     case "MavericksAttribute":
     case "ObsoletedAttribute":
     case "SinceAttribute":
     case "ThreadSafeAttribute":
     case "UnavailableAttribute":
     case "LinkWithAttribute":
     case "DesignatedInitializerAttribute":
         return attr_type.Namespace == Namespaces.ObjCRuntime;
     default:
         return base.IsRemovedAttribute (attribute);
     }
 }
开发者ID:yudhitech,项目名称:xamarin-macios,代码行数:31,代码来源:CoreRemoveAttributes.cs

示例11: DexImport

 /// <summary>
 /// Default ctor
 /// </summary>
 internal DexImport(string className, TypeDefinition firstType, CustomAttribute attr, string scope)
 {
     this.className = className;
     this.attr = attr;
     this.scope = scope;
     types = new List<TypeDefinition> { firstType };
 }
开发者ID:Xtremrules,项目名称:dot42,代码行数:10,代码来源:AssemblyClassLoader.DexImport.cs

示例12: RunTask

        /// <summary>
        /// Runs the specified cloaking task.
        /// </summary>
        /// <param name="context">The running context of this cloak job.</param>
        public void RunTask(ICloakContext context)
        {
            Dictionary<string, AssemblyDefinition> assemblyCache = context.GetAssemblyDefinitions();
            foreach (string assembly in assemblyCache.Keys)
            {
                AssemblyDefinition def = assemblyCache[assembly];
                Type si = typeof (SuppressIldasmAttribute);
                CustomAttribute found = null;
                foreach (CustomAttribute attr in def.CustomAttributes)
                {
                    if (attr.Constructor.DeclaringType.FullName == si.FullName)
                    {
                        found = attr;
                        break;
                    }
                }

                //Only add if it's not there already
                if (found == null)
                {
                    //Add one
                    MethodReference constructor = def.MainModule.Import(typeof (SuppressIldasmAttribute).GetConstructor(Type.EmptyTypes));
                    CustomAttribute attr = new CustomAttribute(constructor);
                    def.CustomAttributes.Add(attr);
                }
            }

        }
开发者ID:modulexcite,项目名称:ncloak,代码行数:32,代码来源:SupressIldasmTask.cs

示例13: Visit

        public void Visit(IBehaviorDefinition behaviorDefinition, CustomAttribute attribute)
        {
            ILProcessor processor = behaviorDefinition.Body.GetILProcessor();
            var pingerDefinition = new VariableDefinition("pinger",
                                                         behaviorDefinition.Module.Import(pingType));
            behaviorDefinition.Body.Variables.Add(pingerDefinition);

            var start = new List<Instruction>
                            {
                                processor.Create(OpCodes.Ldstr, behaviorDefinition.Name),
                                processor.Create(OpCodes.Newobj,
                                                 behaviorDefinition.Module.Import(
                                                     pingType.GetConstructor(new[]{typeof(string)}))),
                                processor.Create(OpCodes.Stloc, pingerDefinition),
                                processor.Create(OpCodes.Ldloc, pingerDefinition),
                                processor.Create(OpCodes.Callvirt,
                                               behaviorDefinition.Module.Import(pingType.GetMethod("Start",
                                                                                                      new Type[] {}))),

                            };
            var end = new List<Instruction>
                          {
                              processor.Create(OpCodes.Ldloc, pingerDefinition),
                              processor.Create(OpCodes.Callvirt,
                                               behaviorDefinition.Module.Import(pingType.GetMethod("End",
                                                                                                      new Type[] {})))
                          };

            new InsertionAtStart(processor, behaviorDefinition).Run(start);
            new InsertionAtEnd(processor, behaviorDefinition).Run(end);
            foreach (var instruction in behaviorDefinition.Body.Instructions)
            {
                Console.Out.WriteLine("{0}/[{1}]: {2} {3}", instruction.Offset, Sequence(instruction.SequencePoint), instruction.OpCode, instruction.Operand);
            }
        }
开发者ID:asengupta,项目名称:Exo,代码行数:35,代码来源:PingWeave.cs

示例14: InjectCustomAttribute

        public static CustomAttribute InjectCustomAttribute(this ICustomAttributeProvider provider, CustomAttribute attribute, ReferenceResolver resolver)
        {
            if (attribute == null)
                throw new ArgumentNullException("attribute");
            if (resolver == null)
                throw new ArgumentNullException("resolver");

            TypeReference attributeType = resolver.ReferenceType(attribute.AttributeType);

            // no context required as attributes cannot be generic
            MethodReference constructor = resolver.ReferenceMethod(attribute.Constructor);

            CustomAttribute newAttribute;
            if ((newAttribute = Helper.GetCustomAttribute(provider.CustomAttributes, attribute)) != null)
                return newAttribute;

            newAttribute = new CustomAttribute(constructor);//, attr.GetBlob());
            provider.CustomAttributes.Add(newAttribute);

            MetadataBuilderHelper.CopyCustomAttributeArguments(attribute.ConstructorArguments, newAttribute.ConstructorArguments, resolver);

            MetadataBuilderHelper.CopyCustomAttributeNamedArguments(attribute.Fields, newAttribute.Fields, resolver);

            MetadataBuilderHelper.CopyCustomAttributeNamedArguments(attribute.Properties, newAttribute.Properties, resolver);

            return newAttribute;
        }
开发者ID:Cadla,项目名称:OBFSCTR,代码行数:27,代码来源:ICustomAttributeProviderExtensions.cs

示例15: Run

		public void Run()
		{
			// Retrieve the target method onto which we want to add the attribute
			var targetType = _module.Types.Single(t => t.Name == "Target");
			var targetMethod = targetType.Methods.Single(m => m.Name == "TargetMethod");

			// Retrieve the type of the attribute
			var decorationAttributeType = _module.Types.Single(t => t.Name == "DecorationAttribute");

			// Create the equivalent of [Decoration("WOW")]
			// All custom attributes are created from a constructor
			var decorationAttributeConstructor = decorationAttributeType
				.Methods
				.Single(m => m.IsConstructor
					&& m.Parameters.Count == 1
					&& m.Parameters[0].ParameterType.MetadataType == MetadataType.String);

			var decorationAttribute = new CustomAttribute(decorationAttributeConstructor);

			decorationAttribute.ConstructorArguments.Add(
				new CustomAttributeArgument(
					type: _module.TypeSystem.String,
					value: "WOW"));

			// Add the custom attribute to the method
			targetMethod.CustomAttributes.Add(decorationAttribute);

			// Write the module with default parameters
			_module.Write(_targetFileName);
		}
开发者ID:transformersprimeabcxyz,项目名称:cecil.samples,代码行数:30,代码来源:Sample.cs


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