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


C# TypeReference.SafeEquivalent方法代码示例

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


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

示例1: EmitUnboxOrCastIfNecessary

 /// <summary>
 /// Emits unbox or cast when necessary.
 /// </summary>
 /// <param name="targetType">Type of the target.</param>
 public Instructions EmitUnboxOrCastIfNecessary(TypeReference targetType)
 {
     // for generics and some unknown reason, an unbox_any is needed
     if (targetType.IsGenericParameter)
         return Emit(OpCodes.Unbox_Any, targetType);
     if (targetType.IsValueType)
         return Emit(OpCodes.Unbox_Any, targetType);
     if (!targetType.SafeEquivalent(targetType.Module.SafeImport(typeof(object))))
         return Emit(OpCodes.Castclass, targetType);
     return this;
 }
开发者ID:csuffyy,项目名称:MrAdvice,代码行数:15,代码来源:Instructions.cs

示例2: IsMarker

        /// <summary>
        /// Determines whether the specified type reference is aspect.
        /// </summary>
        /// <param name="typeReference">The type reference.</param>
        /// <param name="markerInterface">The aspect marker interface.</param>
        /// <returns></returns>
        private bool IsMarker(TypeReference typeReference, TypeDefinition markerInterface)
        {
            lock (_isInterface)
            {
                var key = Tuple.Create(typeReference.FullName, markerInterface.FullName);
                // there is a cache, because the same attribute may be found several time
                // and we're in a hurry, the developper is waiting for his program to start!
                bool isMarker;
                if (_isInterface.TryGetValue(key, out isMarker))
                    return isMarker;

                // otherwise look for type or implemented interfaces (recursively)
                var interfaces = typeReference.Resolve().Interfaces;
                _isInterface[key] = isMarker = typeReference.SafeEquivalent(markerInterface)
                                               || interfaces.Any(i => IsMarker(i, markerInterface));
                return isMarker;
            }
        }
开发者ID:csuffyy,项目名称:MrAdvice,代码行数:24,代码来源:AspectWeaver.cs

示例3: EmitStind

 /// <summary>
 /// Emits a stind.
 /// </summary>
 /// <param name="type">The type.</param>
 public Instructions EmitStind(TypeReference type)
 {
     if (type.IsValueType)
     {
         if (type.SafeEquivalent(type.Module.SafeImport(typeof(Byte))) || type.SafeEquivalent(type.Module.SafeImport(typeof(SByte))))
             return Emit(OpCodes.Stind_I1);
         if (type.SafeEquivalent(type.Module.SafeImport(typeof(Int16))) || type.SafeEquivalent(type.Module.SafeImport(typeof(UInt16))))
             return Emit(OpCodes.Stind_I2);
         if (type.SafeEquivalent(type.Module.SafeImport(typeof(Int32))) || type.SafeEquivalent(type.Module.SafeImport(typeof(UInt32))))
             return Emit(OpCodes.Stind_I4);
         if (type.SafeEquivalent(type.Module.SafeImport(typeof(Int64))) || type.SafeEquivalent(type.Module.SafeImport(typeof(UInt64))))
             return Emit(OpCodes.Stind_I8);
         if (type.SafeEquivalent(type.Module.SafeImport(typeof(Single))))
             return Emit(OpCodes.Stind_R4);
         if (type.SafeEquivalent(type.Module.SafeImport(typeof(Double))))
             return Emit(OpCodes.Stind_R8);
         return Emit(OpCodes.Stobj, type);
     }
     return Emit(OpCodes.Stind_Ref);
 }
开发者ID:csuffyy,项目名称:MrAdvice,代码行数:24,代码来源:Instructions.cs


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