當前位置: 首頁>>代碼示例>>C#>>正文


C# FieldReference.FieldMatches方法代碼示例

本文整理匯總了C#中Mono.Cecil.FieldReference.FieldMatches方法的典型用法代碼示例。如果您正苦於以下問題:C# FieldReference.FieldMatches方法的具體用法?C# FieldReference.FieldMatches怎麽用?C# FieldReference.FieldMatches使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.Cecil.FieldReference的用法示例。


在下文中一共展示了FieldReference.FieldMatches方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: foreach

        FieldReference IImportMapper.MapField(FieldReference fref)
        {
            if (fref.DeclaringType.Scope.Name == _targetModule.Name)
                return fref;

            foreach (var cInj in _classInjectees.Where(i => i is TypeAddInjectee).Cast<TypeAddInjectee>())
            {
                var injCecilType = cInj.GetInjecteeCecilType(_injectionModule);
                if (!fref.DeclaringType.TypeMatches(injCecilType))
                    continue;

                var type = _targetModule.FindMatchingType(cInj.Import(_targetModule, fref.DeclaringType.Scope, this));
                if (type == null)
                    throw new InvalidOperationException("Unable to find add class for: " + fref.DeclaringType);

                var field = type.FindMatchingField(fref, true);
                var decl = FixTypeImport(_targetModule, fref.DeclaringType);
                return new FieldReference(field.Name, field.FieldType, decl);
            }

            foreach (var cInj in _classInjectees.Where(i => i is TypeTargetInjecteeBase))
            {
                var injCecilType = cInj.GetInjecteeCecilType(_injectionModule);
                if (!fref.DeclaringType.TypeMatches(injCecilType))
                    continue;

                var classInjectee = cInj as TypeInjectee;
                var classStubInjectee = cInj as TypeStubInjectee;

                if (classInjectee != null)
                {
                    foreach (var inj in classInjectee.Injectees.Where(i => i is FieldInjecteeBase).Cast<FieldInjecteeBase>())
                    {
                        if (!fref.FieldMatches(inj.InjecteeField))
                            continue;

                        if (inj is FieldStubInjectee)
                            return ((FieldStubInjectee)inj).GetTargetCecilDefintion(_targetModule);
                    }
                }
                else if (classStubInjectee != null)
                {
                    var stubTargetClass = classStubInjectee.TargetType;
                    var tdef = _targetModule.FindMatchingType(stubTargetClass);
                    if (tdef == null)
                        throw new InvalidOperationException("Type not found for: " + stubTargetClass.Name);

                    var target = tdef.FindMatchingField(fref);
                    if (target == null)
                        throw new InvalidOperationException("Target field not found for: " + stubTargetClass.Name);

                    return target;
                }
            }

            return null;
        }
開發者ID:MarkusSintonen,項目名稱:MNetInjector,代碼行數:57,代碼來源:Injector.cs


注:本文中的Mono.Cecil.FieldReference.FieldMatches方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。