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

C# CustomAttribute类代码示例

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

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



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

示例1: CompareConstructorArguments

		private static int CompareConstructorArguments(CustomAttribute first, CustomAttribute second)
		{
			if (first.HasConstructorArguments && !second.HasConstructorArguments)
			{
				return 1;
			}
			if (!first.HasConstructorArguments && second.HasConstructorArguments)
			{
				return -1;
			}

			int maxArguments = Math.Max(first.ConstructorArguments.Count, second.ConstructorArguments.Count);

			for (int i = 0; i < maxArguments; i++)
			{
				if (first.ConstructorArguments.Count <= i)
				{
					return 1;
				}
				if (second.ConstructorArguments.Count <= i)
				{
					return -1;
				}
				CustomAttributeArgument firstArgument = first.ConstructorArguments[i];
				CustomAttributeArgument secondArgument = second.ConstructorArguments[i];

				int compareResult = CompareCustomAttributeArguments(firstArgument, secondArgument);
				if (compareResult != 0)
				{
					return compareResult;
				}
			}
			return 0;
		}
开发者ID:Feng2012,项目名称:JustDecompileEngine,代码行数:34,代码来源:CustomAttributeExtensions.cs


示例2: IsIndexer

		public static bool IsIndexer(this PropertyDefinition property, out CustomAttribute defaultMemberAttribute)
		{
			defaultMemberAttribute = null;

			if (!property.HasParameters)
				return false;

			var accessor = property.GetMethod ?? property.SetMethod;
			var basePropDef = property;
			if (accessor.HasOverrides)
			{
				// if the property is explicitly implementing an interface, look up the property in the interface:
				var baseAccessor = accessor.Overrides.First().Resolve();
				if (baseAccessor != null)
				{
					foreach (var baseProp in baseAccessor.DeclaringType.Properties.Where(baseProp => baseProp.GetMethod == baseAccessor || baseProp.SetMethod == baseAccessor))
					{
						basePropDef = baseProp;
						break;
					}
				}
				else
					return false;
			}
			CustomAttribute attr;
			var defaultMemberName = basePropDef.DeclaringType.GetDefaultMemberName(out attr);
			if (defaultMemberName != basePropDef.Name)
				return false;

			defaultMemberAttribute = attr;
			return true;
		}
开发者ID:mwoelk83,项目名称:Mono.Cecil.Fluent,代码行数:32,代码来源:IsIndexer.cs


示例3: Construct

        /// <summary>
        /// Generates a proxy that forwards all virtual method calls
        /// to a single <see cref="IInterceptor"/> instance.
        /// </summary>
        /// <param name="originalBaseType">The base class of the type being constructed.</param>
        /// <param name="baseInterfaces">The list of interfaces that the new type must implement.</param>
        /// <param name="module">The module that will hold the brand new type.</param>
        /// <param name="targetType">The <see cref="TypeDefinition"/> that represents the type to be created.</param>
        public override void Construct(Type originalBaseType, IEnumerable<Type> baseInterfaces, ModuleDefinition module,
            TypeDefinition targetType)
        {
            var interfaces = new HashSet<Type>(baseInterfaces);

            if (!interfaces.Contains(typeof (ISerializable)))
                interfaces.Add(typeof (ISerializable));

            var serializableInterfaceType = module.ImportType<ISerializable>();
            if (!targetType.Interfaces.Contains(serializableInterfaceType))
                targetType.Interfaces.Add(serializableInterfaceType);

            // Create the proxy type
            base.Construct(originalBaseType, interfaces, module, targetType);

            // Add the Serializable attribute
            targetType.IsSerializable = true;

            var serializableCtor = module.ImportConstructor<SerializableAttribute>();
            var serializableAttribute = new CustomAttribute(serializableCtor);
            targetType.CustomAttributes.Add(serializableAttribute);

            ImplementGetObjectData(originalBaseType, baseInterfaces, module, targetType);
            DefineSerializationConstructor(module, targetType);

            var interceptorType = module.ImportType<IInterceptor>();
            var interceptorGetterProperty = (from PropertyDefinition m in targetType.Properties
                where
                    m.Name == "Interceptor" &&
                    m.PropertyType == interceptorType
                select m).First();
        }
开发者ID:philiplaureano,项目名称:LinFu,代码行数:40,代码来源:SerializableProxyBuilder.cs


示例4: Write

 /// <summary>
 /// Writes a custom attribute
 /// </summary>
 /// <param name="helper">Helper class</param>
 /// <param name="ca">The custom attribute</param>
 /// <returns>Custom attribute blob</returns>
 public static byte[] Write(ICustomAttributeWriterHelper helper, CustomAttribute ca)
 {
     using (var writer = new CustomAttributeWriter(helper)) {
         writer.Write(ca);
         return writer.GetResult();
     }
 }
开发者ID:visi,项目名称:dnlib,代码行数:13,代码来源:CustomAttributeWriter.cs


示例5: createSSAEktronMember

    public void createSSAEktronMember(string PIN)
    {
        //try
        //{

        Dictionary<string, string> UserDetails = loginSSA.GetUsersDetails(PIN);

        UserManager Usermanager = new UserManager();
        CustomAttributeList attrList = new CustomAttributeList();
        CustomAttribute timeZone = new CustomAttribute();
        timeZone.Name = "Time Zone";
        timeZone.Value = "Eastern Standard Time";
        attrList.Add(timeZone);

        UserData newUserdata = new UserData()
        {
            Username = PIN,
            Password = EktronMemberDefaultPassword,
            FirstName = UserDetails["FirstName"],
            LastName = UserDetails["LastName"],
            DisplayName = UserDetails["DisplayName"],
            Email = UserDetails["Email"],
            CustomProperties = attrList,
            // IsMemberShip = true
        };

        if (Ektron.Cms.Framework.Context.UserContextService.Current.IsLoggedIn)
        {
            Usermanager.Add(newUserdata);
            // add user to group MSBA Members
            UserGroupManager UserGroupmanager = new UserGroupManager();
            //Add a User  to a UserGroup
            UserGroupmanager.AddUser(1, newUserdata.Id);
        }
    }
开发者ID:femiosinowo,项目名称:sssadl,代码行数:35,代码来源:add.aspx.cs


示例6: CompareToCustomAttribute

		public static int CompareToCustomAttribute(this CustomAttribute first, CustomAttribute second, bool fullNameCheck = false)
		{
            if (first.AttributeType.Name != second.AttributeType.Name)
            {
                if (fullNameCheck)
                {
                    return first.AttributeType.FullName.CompareTo(second.AttributeType.FullName);
                }
                return first.AttributeType.Name.CompareTo(second.AttributeType.Name);
            }
            if (first == second)
            {
                return 0;
            }
			int returnValue = CompareConstructorArguments(first, second);
			if(returnValue != 0)
			{
				return returnValue;
			}
			returnValue = CompareConstructorFields(first, second);
			if (returnValue != 0)
			{
				return returnValue;
			}
			returnValue = CompareConstructorProperties(first, second);
			if (returnValue != 0)
			{
				return returnValue;
			}
			return 0;
		}
开发者ID:Feng2012,项目名称:JustDecompileEngine,代码行数:31,代码来源:CustomAttributeExtensions.cs


示例7: FromReader

        public static CustomAttributeSignature FromReader(CustomAttribute parent, IBinaryStreamReader reader)
        {
            long position = reader.Position;

            if (!reader.CanRead(sizeof (ushort)) || reader.ReadUInt16() != 0x0001)
                throw new ArgumentException("Signature doesn't refer to a valid custom attribute signature.");

            var signature = new CustomAttributeSignature()
            {
                StartOffset = position,
            };

            if (parent.Constructor != null)
            {
                var methodSignature = parent.Constructor.Signature as MethodSignature;
                if (methodSignature != null)
                {
                    foreach (var parameter in methodSignature.Parameters)
                    {
                        signature.FixedArguments.Add(CustomAttributeArgument.FromReader(parent.Header,
                            parameter.ParameterType, reader));
                    }
                }
            }

            var namedElementCount = reader.CanRead(sizeof (ushort)) ? reader.ReadUInt16() : 0;
            for (uint i = 0; i < namedElementCount; i++)
            {
                signature.NamedArguments.Add(CustomAttributeNamedArgument.FromReader(parent.Header, reader));
            }

            return signature;
        }
开发者ID:JerreS,项目名称:AsmResolver,代码行数:33,代码来源:CustomAttributeSignature.cs


示例8: CilCustomAttribute

 internal CilCustomAttribute(CustomAttribute attribute, ref CilReaders readers)
 {
     _attribute = attribute;
     _readers = readers;
     _parent = null;
     _constructor = null;
     _value = null;
 }
开发者ID:TerabyteX,项目名称:corefxlab,代码行数:8,代码来源:CilCustomAttribute.cs


示例9: Decorate

        public void Decorate(MethodDefinition method, CustomAttribute attribute)
        {
            method.Body.InitLocals = true;

            var getMethodFromHandleRef = referenceFinder.GetMethodReference(typeof(MethodBase), md => md.Name == "GetMethodFromHandle" && md.Parameters.Count == 2);
            var getCustomAttributesRef = referenceFinder.GetMethodReference(typeof(MemberInfo), md => md.Name == "GetCustomAttributes" && md.Parameters.Count == 2);
            var getTypeFromHandleRef = referenceFinder.GetMethodReference(typeof(Type), md => md.Name == "GetTypeFromHandle");

            var methodBaseTypeRef = referenceFinder.GetTypeReference(typeof(MethodBase));
            var exceptionTypeRef = referenceFinder.GetTypeReference(typeof(Exception));

            var methodVariableDefinition = AddVariableDefinition(method, "__fody$method", methodBaseTypeRef);
            var attributeVariableDefinition = AddVariableDefinition(method, "__fody$attribute", attribute.AttributeType);
            var exceptionVariableDefinition = AddVariableDefinition(method, "__fody$exception", exceptionTypeRef);
            VariableDefinition retvalVariableDefinition = null;
            if (method.ReturnType.FullName != "System.Void")
                retvalVariableDefinition = AddVariableDefinition(method, "__fody$retval", method.ReturnType);

            var onEntryMethodRef = referenceFinder.GetMethodReference(attribute.AttributeType, md => md.Name == "OnEntry");
            var onExitMethodRef = referenceFinder.GetMethodReference(attribute.AttributeType, md => md.Name == "OnExit");
            var onExceptionMethodRef = referenceFinder.GetMethodReference(attribute.AttributeType, md => md.Name == "OnException");

            var processor = method.Body.GetILProcessor();
            var methodBodyFirstInstruction = method.Body.Instructions.First();
            if (method.IsConstructor)
                methodBodyFirstInstruction = method.Body.Instructions.First(i => i.OpCode == OpCodes.Call).Next;

            var getAttributeInstanceInstructions = GetAttributeInstanceInstructions(processor, method, attribute, attributeVariableDefinition, methodVariableDefinition, getCustomAttributesRef, getTypeFromHandleRef, getMethodFromHandleRef);
            var callOnEntryInstructions = GetCallOnEntryInstructions(processor, attributeVariableDefinition, methodVariableDefinition, onEntryMethodRef);
            var saveRetvalInstructions = GetSaveRetvalInstructions(processor, retvalVariableDefinition);
            var callOnExitInstructions = GetCallOnExitInstructions(processor, attributeVariableDefinition, methodVariableDefinition, onExitMethodRef);
            var methodBodyReturnInstructions = GetMethodBodyReturnInstructions(processor, retvalVariableDefinition);
            var methodBodyReturnInstruction = methodBodyReturnInstructions.First();
            var tryCatchLeaveInstructions = GetTryCatchLeaveInstructions(processor, methodBodyReturnInstruction);
            var catchHandlerInstructions = GetCatchHandlerInstructions(processor, attributeVariableDefinition, exceptionVariableDefinition, methodVariableDefinition, onExceptionMethodRef);

            ReplaceRetInstructions(processor, saveRetvalInstructions.Concat(callOnExitInstructions).First());

            processor.InsertBefore(methodBodyFirstInstruction, getAttributeInstanceInstructions);
            processor.InsertBefore(methodBodyFirstInstruction, callOnEntryInstructions);

            processor.InsertAfter(method.Body.Instructions.Last(), methodBodyReturnInstructions);

            processor.InsertBefore(methodBodyReturnInstruction, saveRetvalInstructions);
            processor.InsertBefore(methodBodyReturnInstruction, callOnExitInstructions);
            processor.InsertBefore(methodBodyReturnInstruction, tryCatchLeaveInstructions);

            processor.InsertBefore(methodBodyReturnInstruction, catchHandlerInstructions);

            method.Body.ExceptionHandlers.Add(new ExceptionHandler(ExceptionHandlerType.Catch)
                                              {
                                                  CatchType = exceptionTypeRef,
                                                  TryStart = methodBodyFirstInstruction,
                                                  TryEnd = tryCatchLeaveInstructions.Last().Next,
                                                  HandlerStart = catchHandlerInstructions.First(),
                                                  HandlerEnd = catchHandlerInstructions.Last().Next
                                              });
        }
开发者ID:ramyhhh,项目名称:MethodDecorator,代码行数:58,代码来源:MethodDecorator.cs


示例10: Write

		void Write(CustomAttribute ca) {
			if (ca == null) {
				helper.Error("The custom attribute is null");
				return;
			}

			// Check whether it's raw first. If it is, we don't care whether the ctor is
			// invalid. Just use the raw data.
			if (ca.IsRawBlob) {
				if ((ca.ConstructorArguments != null && ca.ConstructorArguments.Count > 0) || (ca.NamedArguments != null && ca.NamedArguments.Count > 0))
					helper.Error("Raw custom attribute contains arguments and/or named arguments");
				writer.Write(ca.RawData);
				return;
			}

			if (ca.Constructor == null) {
				helper.Error("Custom attribute ctor is null");
				return;
			}

			var methodSig = GetMethodSig(ca.Constructor);
			if (methodSig == null) {
				helper.Error("Custom attribute ctor's method signature is invalid");
				return;
			}

			if (ca.ConstructorArguments.Count != methodSig.Params.Count)
				helper.Error("Custom attribute arguments count != method sig arguments count");
			if (methodSig.ParamsAfterSentinel != null && methodSig.ParamsAfterSentinel.Count > 0)
				helper.Error("Custom attribute ctor has parameters after the sentinel");
			if (ca.NamedArguments.Count > ushort.MaxValue)
				helper.Error("Custom attribute has too many named arguments");

			// A generic custom attribute isn't allowed by most .NET languages (eg. C#) but
			// the CLR probably supports it.
			var mrCtor = ca.Constructor as MemberRef;
			if (mrCtor != null) {
				var owner = mrCtor.Class as TypeSpec;
				if (owner != null) {
					var gis = owner.TypeSig as GenericInstSig;
					if (gis != null) {
						genericArguments = new GenericArguments();
						genericArguments.PushTypeArgs(gis.GenericArguments);
					}
				}
			}

			writer.Write((ushort)1);

			int numArgs = Math.Min(methodSig.Params.Count, ca.ConstructorArguments.Count);
			for (int i = 0; i < numArgs; i++)
				WriteValue(FixTypeSig(methodSig.Params[i]), ca.ConstructorArguments[i]);

			int numNamedArgs = Math.Min((int)ushort.MaxValue, ca.NamedArguments.Count);
			writer.Write((ushort)numNamedArgs);
			for (int i = 0; i < numNamedArgs; i++)
				Write(ca.NamedArguments[i]);
		}
开发者ID:GodLesZ,项目名称:ConfuserDeobfuscator,代码行数:58,代码来源:CustomAttributeWriter.cs


示例11: ToHostAttributeMapping

 private HostAttributeMapping ToHostAttributeMapping(CustomAttribute arg) {
     var prms = arg.ConstructorArguments.First().Value as CustomAttributeArgument[];
     if (null == prms)
         return null;
     return new HostAttributeMapping {
         HostAttribute = arg,
         AttribyteTypes = prms.Select(c => ((TypeReference)c.Value).Resolve()).ToArray()
     };
 }
开发者ID:ProESM,项目名称:MethodDecorator,代码行数:9,代码来源:ModuleWeaver.cs


示例12: GetSetIsChanged

 bool? GetSetIsChanged(CustomAttribute notifyAttribute)
 {
     var setIsChanged = notifyAttribute.Properties.FirstOrDefault(x => x.Name == "SetIsChanged");
     var setIsChangedValue = setIsChanged.Argument.Value;
     if (setIsChangedValue != null)
     {
         return (bool) setIsChangedValue;
     }
     return null;
 }
开发者ID:marcuswhit,项目名称:NotifyPropertyWeaver,代码行数:10,代码来源:NotifyPropertyDataAttributeReader.cs


示例13: AddEditorBrowsableAttribute

 void AddEditorBrowsableAttribute(Collection<CustomAttribute> customAttributes)
 {
     if (customAttributes.Any(x=>x.AttributeType.Name == "EditorBrowsableAttribute"))
     {
         return;
     }
     var customAttribute = new CustomAttribute(EditorBrowsableConstructor);
     customAttribute.ConstructorArguments.Add(new CustomAttributeArgument(EditorBrowsableStateType, AdvancedStateConstant));
     customAttributes.Add(customAttribute);
 }
开发者ID:mdabbagh88,项目名称:Publicize,代码行数:10,代码来源:TypeProcessor.cs


示例14: GetCheckForEquality

 bool? GetCheckForEquality(CustomAttribute notifyAttribute)
 {
     var performEqualityCheck = notifyAttribute.Properties.FirstOrDefault(x => x.Name == "PerformEqualityCheck");
     var equalityCheckValue = performEqualityCheck.Argument.Value;
     if (equalityCheckValue != null)
     {
         return (bool) equalityCheckValue;
     }
     return null;
 }
开发者ID:marcuswhit,项目名称:NotifyPropertyWeaver,代码行数:10,代码来源:NotifyPropertyDataAttributeReader.cs


示例15: ImportExternal

    void ImportExternal(CustomAttribute validationTemplateAttribute)
    {
        var typeReference = (TypeReference) validationTemplateAttribute.ConstructorArguments.First().Value;
        TypeDefinition = typeReference.Resolve();
        TypeReference = ModuleDefinition.ImportReference(TypeDefinition);

        TemplateConstructor = ModuleDefinition.ImportReference(FindConstructor(TypeDefinition));
        ModuleDefinition
            .Assembly
            .CustomAttributes.Remove(validationTemplateAttribute);
    }
开发者ID:Fody,项目名称:Validar,代码行数:11,代码来源:ValidationTemplateFinder.cs


示例16: Create

 public async Task<ActionResult> Create(CustomAttribute customAttribute)
 {
     try
     {
         await new AttributeHelper().SaveCustomAttribute(customAttribute);
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
开发者ID:Avinash-Setty,项目名称:GoldInventory,代码行数:12,代码来源:CustomAttributeController.cs


示例17: GetDefaultMemberName

 public static string GetDefaultMemberName(this TypeDefinition type, out CustomAttribute defaultMemberAttribute)
 {
     if (type.HasCustomAttributes)
         foreach (var ca in type.CustomAttributes)
             if (ca.Constructor.DeclaringType.Name == "DefaultMemberAttribute" && ca.Constructor.DeclaringType.Namespace == "System.Reflection"
                 && ca.Constructor.FullName == @"System.Void System.Reflection.DefaultMemberAttribute::.ctor(System.String)")
             {
                 defaultMemberAttribute = ca;
                 return ca.ConstructorArguments[0].Value as string;
             }
     defaultMemberAttribute = null;
     return null;
 }
开发者ID:mwoelk83,项目名称:Mono.Cecil.Fluent,代码行数:13,代码来源:GetDefaultMemberName.cs


示例18: GetPropertyNamesToNotify

 IEnumerable<PropertyDefinition> GetPropertyNamesToNotify(CustomAttribute notifyAttribute, PropertyDefinition property, List<PropertyDefinition> allProperties)
 {
     var customAttributeArguments = notifyAttribute.ConstructorArguments.ToList();
     var value = (string)customAttributeArguments[0].Value;
     yield return GetPropertyDefinition(property, allProperties, value);
     if (customAttributeArguments.Count > 1)
     {
         var paramsArguments = (CustomAttributeArgument[]) customAttributeArguments[1].Value;
         foreach (string argument in paramsArguments.Select(x=>x.Value))
         {
             yield return GetPropertyDefinition(property, allProperties, argument);
         }
     }
 }
开发者ID:jbruening,项目名称:PropertyChanged,代码行数:14,代码来源:NotifyPropertyDataAttributeReader.cs


示例19: AddObsoleteAttribute

    void AddObsoleteAttribute(AttributeData attributeData, Collection<CustomAttribute> customAttributes)
    {
        var customAttribute = new CustomAttribute(ObsoleteConstructorReference);

        var message = ConvertToMessage(attributeData);
        var messageArgument = new CustomAttributeArgument(ModuleDefinition.TypeSystem.String, message);
        customAttribute.ConstructorArguments.Add(messageArgument);

        var isError = GetIsError(attributeData);
        var isErrorArgument = new CustomAttributeArgument(ModuleDefinition.TypeSystem.Boolean, isError);
        customAttribute.ConstructorArguments.Add(isErrorArgument);

        customAttributes.Add(customAttribute);
    }
开发者ID:Fody,项目名称:Obsolete,代码行数:14,代码来源:AttributeFixer.cs


示例20: GetEnumType

 TypeReference GetEnumType(CustomAttribute attribute, GenericParameter parameter)
 {
     if (attribute.HasConstructorArguments)
     {
         var typeReference = (TypeReference) attribute.ConstructorArguments[0].Value;
         if (!typeReference.IsEnumType())
         {
             var message = $"The type '{typeReference.FullName}' is not an enum type. Only enum types are permitted in an EnumConstraintAttribute.";
             throw new WeavingException(message);
         }
         return typeReference;
     }
     return CreateConstraint("System", "Enum", parameter);
 }
开发者ID:Fody,项目名称:ExtraConstraints,代码行数:14,代码来源:GenericParameterProcessor.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# CustomAttributeBuilder类代码示例发布时间:2022-05-24
下一篇:
C# Custom类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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