本文整理汇总了C#中Mono.Cecil.FieldReference.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# FieldReference.Resolve方法的具体用法?C# FieldReference.Resolve怎么用?C# FieldReference.Resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Cecil.FieldReference
的用法示例。
在下文中一共展示了FieldReference.Resolve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WeakEventWeaver
public WeakEventWeaver(FieldReference eventDelegate, ModuleImporter moduleimporter)
{
_eventDelegate = eventDelegate.Resolve();
_moduleimporter = moduleimporter;
_closedGenericEventHandler = moduleimporter.GetClosedEventHandlerT(eventDelegate.FieldType.GetEventArgsType());
_isGenericHandler = _closedGenericEventHandler.FullName.Equals(eventDelegate.FieldType.FullName);
}
示例2: FixFieldReference
private FieldReference FixFieldReference(FieldReference yourFieldRef)
{
if (yourFieldRef == null) {
Log_called_to_fix_null("field");
return null;
}
Log_fixing_reference("field", yourFieldRef);
Asserts.AssertTrue(yourFieldRef.DeclaringType != null);
var yourFieldDef = yourFieldRef.Resolve();
if (yourFieldDef.IsDisablePatching()) {
Log_trying_to_fix_disabled_reference("field", yourFieldRef);
}
var targetType = FixTypeReference(yourFieldRef.DeclaringType);
var targetBaseFieldDef = yourFieldRef;
if (yourFieldDef.Module.Assembly.IsPatchingAssembly()) {
//additional checking
var targetFieldDef = CurrentMemberCache.Fields.TryGet(yourFieldDef)?.TargetMember;
if (targetFieldDef == null) {
throw Errors.Could_not_resolve_reference("field", yourFieldRef);
}
targetBaseFieldDef = targetFieldDef;
} else {
//we assume that types that aren't in a patching assembly will never reference types in a patching assembly
targetBaseFieldDef = yourFieldRef;
}
var newFieldRef = targetBaseFieldDef.CloneReference();
newFieldRef.DeclaringType = targetType;
newFieldRef.FieldType = FixTypeReference(newFieldRef.FieldType);
var targetFieldRef = TargetAssembly.MainModule.Import(newFieldRef);
Log_fixed_reference("field", yourFieldRef, targetFieldRef);
targetFieldRef.Module.Assembly.AssertEqual(TargetAssembly);
return targetFieldRef;
}
示例3: CheckAndSaveStateField
private bool CheckAndSaveStateField(FieldReference foundStateField)
{
FieldDefinition foundFieldDef = foundStateField.Resolve();
if (stateField == null)
{
stateField = foundFieldDef;
}
else if(stateField != foundFieldDef)
{
return false;
}
return true;
}
示例4: CreateWellName
private static void CreateWellName(FieldReference fr)
{
var name = CleanName(fr.Name);
var start = name.IndexOf(NONWELLFLAG);
if (start == -1)
{
if (IsNameRepeated(fr.DeclaringType, name)) name = "f_" + name + "_" + GetShortName(fr.FieldType);
}
else
{
var fd = fr.Resolve();
if (fd.DeclaringType.IsEnum)
{
var value = fd.Constant.ToString().Replace('-', 'n');
var suffix = "_" + value;
name = Replace(name, start, 1, "V") + suffix;
}
else
{
var suffix = "_" + GetShortName(fd.FieldType);
name = fd.IsLiteral
? Replace(name, start, 1, "CONST").ToUpper() + suffix.ToUpper() + "_" + Regex.Replace(fd.Constant.ToString(), @"\W", "_")
: Replace(name, start, 1, "f") + suffix;
}
}
fr.mWellName = Regex.Replace(name, @"\W", "_");
}
示例5: IsBlacklisted
private bool IsBlacklisted(FieldReference field)
{
var fieldDef = field.Resolve();
if (fieldDef == null)
return true; // TODO: log
if (ReferenceEquals(Module, fieldDef.Module))
return false;
return _accessLists.IsBlacklisted(fieldDef);
}
示例6: GetFieldName
protected virtual string GetFieldName(FieldReference field)
{
FieldDefinition fieldDefinition = field.Resolve();
if (fieldDefinition != null && fieldDefinition.Module.FilePath == this.ModuleContext.Module.FilePath)
{
if (this.TypeContext != null && this.TypeContext.BackingFieldToNameMap.ContainsKey(fieldDefinition))
{
return this.TypeContext.BackingFieldToNameMap[fieldDefinition];
}
return this.ModuleContext.RenamedMembersMap[fieldDefinition.MetadataToken.ToUInt32()];
}
return Utilities.EscapeName(GenericHelper.GetNonGenericName(field.Name), this.Language);
}
示例7: GetFieldReferenceId
private UInt16 GetFieldReferenceId(
FieldReference fieldReference)
{
UInt16 referenceId;
if (_context.FieldReferencesTable.TryGetFieldReferenceId(fieldReference, out referenceId))
{
referenceId |= 0x8000; // External field reference
}
else
{
_context.FieldsTable.TryGetFieldReferenceId(fieldReference.Resolve(), false, out referenceId);
}
return referenceId;
}
示例8: GetFieldDefinition
static FieldDefinition GetFieldDefinition(FieldReference field)
{
if (field != null && field.DeclaringType.IsGenericInstance)
return field.Resolve();
else
return field as FieldDefinition;
}
示例9: AddField
private void AddField(FieldReference field) {
if (field == null || IsIgnored(field)) {
return;
}
AddType(field.FieldType);
AddType(field.DeclaringType);
FieldDefinition resolvedField = field.Resolve();
fields.Add(resolvedField);
}
示例10: CheckAndSaveCurrentItemField
private bool CheckAndSaveCurrentItemField(FieldReference foundCurrentItemFieldRef)
{
FieldDefinition fieldDef = foundCurrentItemFieldRef.Resolve();
if(currentItemField == null)
{
currentItemField = fieldDef;
}
else if(currentItemField != fieldDef)
{
return false;
}
return true;
}
示例11: IsObsolete
static bool IsObsolete(FieldReference field)
{
if (field == null)
return false;
bool obsolete = false;
if (!fields.TryGetValue (field, out obsolete)) {
FieldDefinition fd = field.Resolve ();
obsolete = fd.HasAttribute ("System", "ObsoleteAttribute");
fields.Add (field, obsolete);
}
return obsolete;
}
示例12: GenericFieldComparer
static bool GenericFieldComparer(FieldReference fieldReference, FieldDefinition fieldDefinition)
{
return fieldDefinition == fieldReference.Resolve();
}
示例13: FindLinked
public virtual FieldReference FindLinked(FieldReference field)
{
FieldDefinition def = field.Resolve();
if (def == null || !def.HasCustomAttributes) {
return field;
}
CustomAttribute attrib = null;
foreach (CustomAttribute attrib_ in def.CustomAttributes) {
if (attrib_.AttributeType.FullName == "MonoMod.MonoModLinkTo") {
attrib = attrib_;
break;
}
}
if (attrib == null) {
return field;
}
TypeDefinition type = null;
if (attrib.ConstructorArguments[0].Type.FullName == "System.String") {
//TODO get type from name
} else {
type = FindType((TypeReference) attrib.ConstructorArguments[0].Value).Resolve();
}
//TODO get method from name
for (int i = 0; i < type.Fields.Count; i++) {
if (type.Methods[i].Name == ((string) attrib.ConstructorArguments[1].Value)) {
//Probably check for more than that
field = type.Fields[i];
break;
}
}
//TODO cache somewhere
return field;
}
示例14: IsAutoPropertyConstructorInitializerExpression
private bool IsAutoPropertyConstructorInitializerExpression(FieldReference fieldReference, out PropertyDefinition property)
{
FieldDefinition fieldDefinition = fieldReference.Resolve();
if (fieldDefinition != null)
{
Dictionary<FieldDefinition, PropertyDefinition> map = this.typeContext.FieldToPropertyMap;
if (map.ContainsKey(fieldDefinition) &&
map[fieldDefinition] != null &&
!map[fieldDefinition].ShouldStaySplit())
{
property = map[fieldDefinition];
return true;
}
}
property = null;
return false;
}
示例15: IsVisibleFrom
bool IsVisibleFrom (TypeDefinition type, FieldReference reference)
{
if (reference == null)
return true;
FieldDefinition field = reference.Resolve ();
if (field == null)
return true;
TypeDefinition dec = (TypeDefinition) field.DeclaringType;
if (!IsVisibleFrom (type, dec))
return false;
if (field.IsPublic)
return true;
if (type == dec || IsNestedIn (type, dec))
return true;
if (field.IsFamily && InHierarchy (type, dec))
return true;
if (field.IsFamilyOrAssembly && (!AreInDifferentAssemblies (type, dec) || InHierarchy (type, dec)))
return true;
if (field.IsFamilyAndAssembly && (!AreInDifferentAssemblies (type, dec) && InHierarchy (type, dec)))
return true;
if (!AreInDifferentAssemblies (type, dec) && field.IsAssembly)
return true;
return false;
}