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


C# TypeDefinition.GetGenericInstanceType方法代码示例

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


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

示例1: AddStaticEqualsCall

        static void AddStaticEqualsCall(TypeDefinition type, Collection<Instruction> ins)
        {
            if (type.IsValueType)
            {
                var resolved = type.GetGenericInstanceType(type);
                ins.Add(Instruction.Create(OpCodes.Ldarg_0));
                ins.Add(Instruction.Create(OpCodes.Box, resolved));
                ins.Add(Instruction.Create(OpCodes.Ldarg_1));
                ins.Add(Instruction.Create(OpCodes.Box, resolved));
            }
            else
            {
                ins.Add(Instruction.Create(OpCodes.Ldarg_0));
                ins.Add(Instruction.Create(OpCodes.Ldarg_1));
            }

            ins.Add(Instruction.Create(OpCodes.Call, ReferenceFinder.Object.StaticEquals));
        }
开发者ID:GeertvanHorrik,项目名称:Equals,代码行数:18,代码来源:OperatorInjector.cs

示例2: AddOperator

        static MethodDefinition AddOperator(TypeDefinition type, bool isEquality)
        {
            var methodAttributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.Static;
            var method = new MethodDefinition(isEquality ? "op_Equality" : "op_Inequality", methodAttributes, ReferenceFinder.Boolean.TypeReference);
            method.CustomAttributes.MarkAsGeneratedCode();

            var parameterType = type.GetGenericInstanceType(type);

            method.Parameters.Add("left", parameterType);
            method.Parameters.Add("right", parameterType);

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

            AddStaticEqualsCall(type, ins);
            AddReturnValue(isEquality, ins);

            body.OptimizeMacros();

            type.Methods.AddOrReplace(method);

            return method;
        }
开发者ID:GeertvanHorrik,项目名称:Equals,代码行数:23,代码来源:OperatorInjector.cs

示例3: AddInternalEqualsCall

        static void AddInternalEqualsCall(TypeDefinition type, TypeReference typeRef, MethodReference newEquals, Collection<Instruction> t, VariableDefinition result)
        {
            t.Add(Instruction.Create(OpCodes.Ldarg_0));
            if (type.IsValueType)
            {
                var resolvedType = type.GetGenericInstanceType(type);
                t.Add(Instruction.Create(OpCodes.Ldobj, resolvedType));
            }
            t.Add(Instruction.Create(OpCodes.Ldarg_1));
            if (type.IsValueType)
            {
                t.Add(Instruction.Create(OpCodes.Unbox_Any, typeRef));
            }
            else
            {
                t.Add(Instruction.Create(OpCodes.Castclass, typeRef));
            }

            t.Add(Instruction.Create(OpCodes.Call, newEquals));

            t.Add(Instruction.Create(OpCodes.Stloc, result));
        }
开发者ID:rjasica,项目名称:Equals,代码行数:22,代码来源:EqualsInjector.cs

示例4: AddExactlyTheSameTypeAsThis

        static void AddExactlyTheSameTypeAsThis(TypeDefinition type, Collection<Instruction> c)
        {
            c.Add(Instruction.Create(OpCodes.Ldarg_0));
            if (type.IsValueType)
            {
                var resolved = type.GetGenericInstanceType(type);
                c.Add(Instruction.Create(OpCodes.Ldobj, resolved));
                c.Add(Instruction.Create(OpCodes.Box, resolved));
            }
            c.Add(Instruction.Create(OpCodes.Call, ReferenceFinder.Object.GetType));

            c.Add(Instruction.Create(OpCodes.Ldarg_1));
            c.Add(Instruction.Create(OpCodes.Callvirt, ReferenceFinder.Object.GetType));

            c.Add(Instruction.Create(OpCodes.Ceq));
        }
开发者ID:rjasica,项目名称:Equals,代码行数:16,代码来源:EqualsInjector.cs

示例5: AddExactlyOfType

        static void AddExactlyOfType(TypeDefinition type, TypeReference typeRef, Collection<Instruction> c)
        {
            c.Add(Instruction.Create(OpCodes.Ldarg_0));
            if (type.IsValueType)
            {
                var resolved = type.GetGenericInstanceType(type);
                c.Add(Instruction.Create(OpCodes.Ldobj, resolved));
                c.Add(Instruction.Create(OpCodes.Box, resolved));
            }
            c.Add(Instruction.Create(OpCodes.Call, ReferenceFinder.Object.GetType));

            c.Add(Instruction.Create(OpCodes.Ldtoken, typeRef));
            c.Add(Instruction.Create(OpCodes.Call, ReferenceFinder.Type.GetTypeFromHandle));
            c.Add(Instruction.Create(OpCodes.Ceq));
        }
开发者ID:rjasica,项目名称:Equals,代码行数:15,代码来源:EqualsInjector.cs

示例6: AddCustomLogicCall

        static void AddCustomLogicCall(TypeDefinition type, MethodBody body, Collection<Instruction> ins, MethodDefinition[] customLogic)
        {
            ins.IfNot(
                c =>
                {
                    var customMethod = ReferenceFinder.ImportCustom(customLogic[0]);

                    var parameters = customMethod.Parameters;
                    if (parameters.Count != 1)
                    {
                        throw new WeavingException(
                            string.Format("Custom equals of type {0} have to have one parameter.", type.FullName));
                    }
                    if (parameters[0].ParameterType.Resolve().FullName != type.FullName)
                    {
                        throw new WeavingException(
                            string.Format("Custom equals of type {0} have to have one parameter of type {0}.", type.FullName));
                    }

                    MethodReference selectedMethod;
                    TypeReference resolverType;
                    if (customMethod.DeclaringType.HasGenericParameters)
                    {
                        var genericInstanceType = type.GetGenericInstanceType(type);
                        resolverType = ReferenceFinder.ImportCustom(genericInstanceType);
                        var newRef = new MethodReference(customMethod.Name, customMethod.ReturnType)
                            {
                                DeclaringType = resolverType,
                                HasThis = true,
                            };
                        newRef.Parameters.Add(customMethod.Parameters[0].Name, resolverType);

                        selectedMethod = newRef;
                    }
                    else
                    {
                        resolverType = type;
                        selectedMethod = customMethod;
                    }

                    var imported = ReferenceFinder.ImportCustom(selectedMethod);
                    if (!type.IsValueType)
                    {
                        ins.Add(Instruction.Create(OpCodes.Ldarg_0));
                    }
                    else
                    {
                        var argVariable = body.Variables.Add("argVariable", resolverType);
                        ins.Add(Instruction.Create(OpCodes.Ldarg_0));
                        ins.Add(Instruction.Create(OpCodes.Stloc, argVariable));

                        ins.Add(Instruction.Create(OpCodes.Ldloca, argVariable));
                    }
                    ins.Add(Instruction.Create(OpCodes.Ldarg_1));
                    ins.Add(Instruction.Create(imported.GetCallForMethod(), imported));
                },
                AddReturnFalse);
        }
开发者ID:rjasica,项目名称:Equals,代码行数:58,代码来源:EqualsInjector.cs

示例7: AddCheckEqualsReference

        static void AddCheckEqualsReference(TypeDefinition type, Collection<Instruction> ins, bool skipBoxingSecond)
        {
            var resolvedType = type.IsValueType ? type.GetGenericInstanceType(type) : null;
            ins.If(
                c =>
                {
                    c.Add(Instruction.Create(OpCodes.Ldnull));
                    c.Add(Instruction.Create(OpCodes.Ldarg_1));
                    if (type.IsValueType && !skipBoxingSecond)
                    {
                        c.Add(Instruction.Create(OpCodes.Box, resolvedType));
                    }
                    c.Add(Instruction.Create(OpCodes.Call, ReferenceFinder.Object.ReferenceEquals));
                },
                AddReturnFalse);

            ins.If(
                c =>
                {
                    c.Add(Instruction.Create(OpCodes.Ldarg_0));
                    if (type.IsValueType)
                    {
                        c.Add(Instruction.Create(OpCodes.Ldobj, resolvedType));
                        c.Add(Instruction.Create(OpCodes.Box, resolvedType));
                    }
                    c.Add(Instruction.Create(OpCodes.Ldarg_1));
                    if (type.IsValueType && !skipBoxingSecond)
                    {
                        c.Add(Instruction.Create(OpCodes.Box, resolvedType));
                    }
                    c.Add(Instruction.Create(OpCodes.Call, ReferenceFinder.Object.ReferenceEquals));
                },
                AddReturnTrue);
        }
开发者ID:rjasica,项目名称:Equals,代码行数:34,代码来源:EqualsInjector.cs


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