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


C# MethodBase.Ret方法代码示例

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


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

示例1: IsInvariantTo

        public static bool IsInvariantTo(this MethodBase source, MethodBase method)
        {
            if (source.IsGenericMethod || method.IsGenericMethod) throw new NotImplementedException(); // TODO: implement it somewhen

            var me = source.GetParameters();
            var he = method.GetParameters();

            if (source.Ret() != method.Ret() && !source.Ret().IsAssignableFrom(method.Ret())) return false;
            if (me.Length != he.Length) return false;
            for (var i = 0; i < me.Length; i++)
                if (he[i].ParameterType != me[i].ParameterType && !he[i].ParameterType.IsAssignableFrom(me[i].ParameterType)) return false;

            return true;
        }
开发者ID:xeno-by,项目名称:xenogears,代码行数:14,代码来源:MethodInfoTrait.cs

示例2: OverrideMethod

        public static MethodBuilder OverrideMethod(this TypeBuilder source, MethodBase parentMethod, Func<ILGenerator, ILGenerator> body, IDictionary<MethodBase, MethodBuilder> map)
        {
            // don't defer this check since default error message doesn't say
            // what exact method is the reason of the failure to compile the class
            parentMethod.IsVirtual.AssertTrue();
            parentMethod.IsFinal.AssertFalse();

            var attrs = parentMethod.Attributes;
            attrs &= ~MethodAttributes.NewSlot;
            attrs &= ~MethodAttributes.Abstract;

            var derived = source.DefineMethod(
                // that's an awesome idea but it hurts reflector and debuggability
//                String.Format("{0}_{1}", parentMethod.Name, parentMethod.DeclaringType.ToShortString()),
                parentMethod.Name,
                attrs,
                parentMethod.Ret(),
                parentMethod.Params());
            parentMethod.GetParameters().ForEach((pi, i) => derived.DefineParameter(i + 1, ParmA.None, pi.Name));

            // the stuff below ain't necessary at all since we don't change the name
//            // note. the checks are very important since otherwise we get an exception:
//            // System.TypeLoadException: Signature of the body and declaration in a method implementation do not match.
//            if (!parentMethod.IsAbstract && !parentMethod.IsGenericMethod)
//            {
//                source.DefineMethodOverride(derived, parentMethod);
//            }

            if (body != null) body(derived.il());
            if (map != null) map[parentMethod] = derived;
            return derived;
        }
开发者ID:xeno-by,项目名称:xenogears,代码行数:32,代码来源:OverrideMethodHelper.cs

示例3: DefineOverride

        public static MethodBuilder DefineOverride(this TypeBuilder t, MethodBase @base)
        {
            MethodAttributes fixt = 0;
            var allAttrs = Enum.GetValues(typeof(MethodAttributes)).Cast<MethodAttributes>();
            var validAttrs = allAttrs
                .Where(a => a != MethodAttributes.Abstract)
                .Where(a => a != MethodAttributes.NewSlot);
            validAttrs.ForEach(a => fixt |= (a & @base.Attributes));

            (@base is MethodInfo).AssertTrue();
            var @override = t.DefineMethod(
                @base.Name,
                fixt,
                @base.Ret(),
                @base.Params());

            return @override;
        }
开发者ID:xeno-by,项目名称:xenogears,代码行数:18,代码来源:MyTrait.cs


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