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