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