public FieldReference ImportFieldReference(FieldReference field, ImportContext context) { if (field.DeclaringType.Module == m_module) { return(field); } ImportCache(); FieldReference f = (FieldReference)m_memberRefCache [field.ToString()]; if (f != null) { return(f); } f = new FieldReference( field.Name, ImportTypeReference(field.DeclaringType, context), ImportTypeReference(field.FieldType, context)); m_module.MemberReferences.Add(f); m_memberRefCache [field.ToString()] = f; return(f); }
private void WeaveDependencyProperty(MethodBody staticCtorBody, FieldReference field, PropertyDefinition property) { var assembly = property.DeclaringType.Module.Assembly; var propertyType = assembly.ImportType(Type.GetType(property.PropertyType.FullName)); var getTypeFromHandle = assembly.ImportMethod(typeof(Type).GetMethod("GetTypeFromHandle")); var register = assembly.ImportMethod(typeof(DependencyProperty).GetMethod("Register", new[] { typeof(string), typeof(Type), typeof(Type) })); // ignore previously weaved DPs if (staticCtorBody.Instructions.Any(i => i.Operand != null && i.Operand.ToString() == field.ToString())) { return; } var ret = staticCtorBody.Instructions.Last(); if (ret.OpCode != OpCodes.Ret) throw new InvalidOperationException("The last instruction should be OpCode.Ret"); HasChanges = true; var proc = staticCtorBody.GetILProcessor(); proc.InsertBefore(ret, proc.Create(OpCodes.Ldstr, property.Name)); proc.InsertBefore(ret, proc.Create(OpCodes.Ldtoken, propertyType)); proc.InsertBefore(ret, proc.Create(OpCodes.Call, getTypeFromHandle)); proc.InsertBefore(ret, proc.Create(OpCodes.Ldtoken, property.DeclaringType)); proc.InsertBefore(ret, proc.Create(OpCodes.Call, getTypeFromHandle)); proc.InsertBefore(ret, proc.Create(OpCodes.Call, register)); proc.InsertBefore(ret, proc.Create(OpCodes.Stsfld, field)); }
internal BfField method_6(FieldReference fieldReference_0) { BfAssembly bfAssembly; BfField result; if (fieldReference_0.DeclaringType.Scope is AssemblyNameReference) { bfAssembly = this.dictionary_0[((AssemblyNameReference)fieldReference_0.DeclaringType.Scope).FullName]; } else { if (!(fieldReference_0.DeclaringType.Scope is ModuleDefinition)) { Logger.LogWarning("GetBfField1", "Couldn't find assembly for field: " + fieldReference_0.ToString()); result = null; return result; } bfAssembly = this.dictionary_0[((ModuleDefinition)fieldReference_0.DeclaringType.Scope).Assembly.Name.FullName]; } string key = BfCache.smethod_2(fieldReference_0.DeclaringType); BfType bfType; bfAssembly.method_4().TryGetValue(key, out bfType); if (bfType == null) { Logger.LogWarning("GetBfField2", "Couldn't find type for field: " + fieldReference_0.ToString()); result = null; } else { foreach (BfField bfField in ((IEnumerable<BfField>)bfType.Fields)) { BfField bfField; if (fieldReference_0.Name == bfField.Name) { result = bfField; return result; } } foreach (FieldDefinition fieldDefinition in bfType.method_2().Fields) { if (fieldDefinition.Name == fieldReference_0.Name) { BfField bfField = new BfField(this, fieldDefinition, bfType); this.fieldCollection_0.method_1(bfField); bfType.Fields.method_1(bfField); result = bfField; return result; } } Logger.LogWarning("GetBfField3", "Couldn't find field " + fieldReference_0.ToString() + " in type: " + bfType.FullName); result = null; } return result; }
public FieldReference ImportFieldReference(FieldReference field, ImportContext context) { if (field.DeclaringType.Module == m_module) return field; ImportCache (); FieldReference f = (FieldReference) m_memberRefCache [field.ToString ()]; if (f != null) return f; f = new FieldReference ( field.Name, ImportTypeReference (field.DeclaringType, context), ImportTypeReference (field.FieldType, context)); m_module.MemberReferences.Add (f); m_memberRefCache [field.ToString ()] = f; return f; }