當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。