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


C# TypeDefinition.GetPropertiesWithoutIgnores方法代码示例

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


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

示例1: InjectEqualsInternal

        public static MethodReference InjectEqualsInternal( TypeDefinition type, TypeReference typeRef, MethodDefinition collectionEquals )
        {
            var methodAttributes = MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.Static;
            var method = new MethodDefinition("EqualsInternal", methodAttributes, ReferenceFinder.Boolean.TypeReference);
            method.CustomAttributes.MarkAsGeneratedCode();

            var left = method.Parameters.Add("left", typeRef);
            var right = method.Parameters.Add("right", typeRef);

            var body = method.Body;
            var ins = body.Instructions;

            var properties = type.GetPropertiesWithoutIgnores(ignoreAttributeName);

            foreach (var property in properties)
            {
                AddPropertyCode( type, collectionEquals, property, ins);
            }

            AddReturnTrue(ins);

            body.OptimizeMacros();

            type.Methods.Add(method);

            var methodToCall = new MethodReference(method.Name, method.ReturnType, typeRef);
            foreach (var parameter in method.Parameters)
            {
                methodToCall.Parameters.Add(parameter);
            }

            return methodToCall;
        }
开发者ID:kzaikin,项目名称:Equals,代码行数:33,代码来源:EqualsInjector.cs

示例2: Inject

        public static MethodDefinition Inject( TypeDefinition type )
        {
            var methodAttributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Virtual;
            var method = new MethodDefinition("GetHashCode", methodAttributes, ReferenceFinder.Int32.TypeReference);
            method.CustomAttributes.MarkAsGeneratedCode();

            var resultVariable = method.Body.Variables.Add("result", ReferenceFinder.Int32.TypeReference);

            var body = method.Body;
            var ins = body.Instructions;

            ins.Add(Instruction.Create(OpCodes.Ldc_I4_0));
            ins.Add(Instruction.Create(OpCodes.Stloc, resultVariable));

            var properties = type.GetPropertiesWithoutIgnores(ignoreAttributeName);
            if (properties.Length == 0)
            {
                AddResutInit(ins, resultVariable);
            }

            var isFirst = true;
            foreach (var property in properties)
            {
                AddPropertyCode(property, isFirst, ins, resultVariable, method, type);
                isFirst = false;
            }

            AddReturnCode(ins, resultVariable);

            body.OptimizeMacros();

            type.Methods.Add(method);

            return method;
        }
开发者ID:kzaikin,项目名称:Equals,代码行数:35,代码来源:GetHashCodeInjector.cs

示例3: InjectEqualsInternal

        public static MethodReference InjectEqualsInternal(TypeDefinition type, TypeReference typeRef, MethodDefinition collectionEquals)
        {
            var methodAttributes = MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.Static;
            var method = new MethodDefinition("EqualsInternal", methodAttributes, ReferenceFinder.Boolean.TypeReference);
            method.CustomAttributes.MarkAsGeneratedCode();

            var left = method.Parameters.Add("left", typeRef);
            var right = method.Parameters.Add("right", typeRef);

            var body = method.Body;
            body.InitLocals = true;
            var ins = body.Instructions;

            var properties = type.GetPropertiesWithoutIgnores(ignoreAttributeName);

            foreach (var property in properties)
            {
                AddPropertyCode(type, collectionEquals, property, ins, left, right);
            }

            var methods = type.GetMethods();
            var customLogic = methods
                .Where(x => x.CustomAttributes.Any(y => y.AttributeType.Name == customAttribute)).ToArray();

            if (customLogic.Length > 2)
            {
                throw new WeavingException("Only one custom method can be specified.");
            }

            if (customLogic.Length == 1)
            {
                AddCustomLogicCall(type, body, ins, customLogic);
            }

            AddReturnTrue(ins);

            body.OptimizeMacros();

            type.Methods.AddOrReplace(method);

            var methodToCall = new MethodReference(method.Name, method.ReturnType, typeRef);
            foreach (var parameter in method.Parameters)
            {
                methodToCall.Parameters.Add(parameter);
            }

            return methodToCall;
        }
开发者ID:rjasica,项目名称:Equals,代码行数:48,代码来源:EqualsInjector.cs


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