public void Read(ClrModuleReader reader) { this.PropertyDefinition = new PropertyDefinition(); this.PropertyDefinition.Attributes = (PropertyAttributes)reader.Binary.ReadUInt16(); this.PropertyDefinition.Name = reader.ReadString(); this.Type = reader.ReadPropertySignature(); }
void ReadProperties() { if (!m_tHeap.HasTable(PropertyTable.RId)) { m_properties = new PropertyDefinition [0]; return; } PropertyTable propsTable = m_tableReader.GetPropertyTable(); PropertyMapTable pmapTable = m_tableReader.GetPropertyMapTable(); m_properties = new PropertyDefinition [propsTable.Rows.Count]; for (int i = 0; i < pmapTable.Rows.Count; i++) { PropertyMapRow pmapRow = pmapTable [i]; if (pmapRow.Parent == 0) { continue; } TypeDefinition owner = GetTypeDefAt(pmapRow.Parent); GenericContext context = new GenericContext(owner); int start = (int)pmapRow.PropertyList, last = propsTable.Rows.Count + 1, end; if (i < pmapTable.Rows.Count - 1) { end = (int)pmapTable [i + 1].PropertyList; } else { end = last; } if (end > last) { end = last; } for (int j = start; j < end; j++) { PropertyRow prow = propsTable [j - 1]; PropertySig psig = m_sigReader.GetPropSig(prow.Type); PropertyDefinition pdef = new PropertyDefinition( m_root.Streams.StringsHeap [prow.Name], GetTypeRefFromSig(psig.Type, context), prow.Flags); pdef.MetadataToken = MetadataToken.FromMetadataRow(TokenType.Property, j - 1); pdef.PropertyType = GetModifierType(psig.CustomMods, pdef.PropertyType); if (!IsDeleted(pdef)) { owner.Properties.Add(pdef); } m_properties [j - 1] = pdef; } } }
private void RemapPropertySig(PropertySig propertySig) { propertySig.RetType = RemapReference(propertySig.RetType); for (var i = 0; i < propertySig.Params.Count; i++) { propertySig.Params[i] = RemapReference(propertySig.Params[i]); } }
public PropertyDefOptions(PropertyDef prop) { this.Attributes = prop.Attributes; this.Name = prop.Name; this.PropertySig = prop.PropertySig; this.Constant = prop.Constant; this.GetMethods.AddRange(prop.GetMethods); this.SetMethods.AddRange(prop.SetMethods); this.OtherMethods.AddRange(prop.OtherMethods); this.CustomAttributes.AddRange(prop.CustomAttributes); }
public PropertyDefOptions(PropertyDef prop) { Attributes = prop.Attributes; Name = prop.Name; PropertySig = prop.PropertySig; Constant = prop.Constant; GetMethods.AddRange(prop.GetMethods); SetMethods.AddRange(prop.SetMethods); OtherMethods.AddRange(prop.OtherMethods); CustomAttributes.AddRange(prop.CustomAttributes); }
private void LoadProperty(MosaType declType, MosaProperty.Mutator property, PropertyDef propertyDef) { PropertySig propertySig = propertyDef.PropertySig; property.UnderlyingObject = new UnitDesc <PropertyDef, PropertySig>(propertyDef.Module, propertyDef, propertySig); property.DeclaringType = declType; property.Name = propertyDef.Name; property.PropertyAttributes = (MosaPropertyAttributes)propertyDef.Attributes; }
public PropertySig ReadPropertySignature() { uint blobIindex = ReadBlobIndex(); if (blobIindex == 0) { return(null); } var sigReader = GetSignatureBlobReader(blobIindex); var sig = new PropertySig(); sig.Read(sigReader); return(sig); }
private static void WrapField(TypeDef type, string fieldName, string propertyName, string access) { FieldDef field = type.Fields.First(f => f.Name == fieldName); var propertySignature = PropertySig.CreateInstance(field.FieldType); var property = new PropertyDefUser(propertyName, propertySignature); type.Properties.Add(property); bool propertyValid = false; if (access.Contains("read")) { var getterSignature = MethodSig.CreateInstance(field.FieldType); MethodDefUser getter = new MethodDefUser("nuterra_get_" + propertyName, getterSignature, MethodAttributes.Public | MethodAttributes.HideBySig); getter.DeclaringType = type; getter.Body = new CilBody(); getter.Body.Instructions.Add(OpCodes.Ldarg_0.ToInstruction()); getter.Body.Instructions.Add(OpCodes.Ldfld.ToInstruction(field)); getter.Body.Instructions.Add(OpCodes.Ret.ToInstruction()); property.GetMethod = getter; propertyValid = true; } if (access.Contains("write")) { var setterSignature = MethodSig.CreateInstance(type.Module.CorLibTypes.Void, field.FieldType); MethodDefUser setter = new MethodDefUser("nuterra_set_" + propertyName, setterSignature, MethodAttributes.Public | MethodAttributes.HideBySig); setter.DeclaringType = type; setter.Body = new CilBody(); setter.Body.Instructions.Add(OpCodes.Ldarg_0.ToInstruction()); setter.Body.Instructions.Add(OpCodes.Ldarg_1.ToInstruction()); setter.Body.Instructions.Add(OpCodes.Stfld.ToInstruction(field)); setter.Body.Instructions.Add(OpCodes.Ret.ToInstruction()); property.SetMethod = setter; propertyValid = true; } if (!propertyValid) { throw new ArgumentException("wrap_field must define read and/or write accessor", nameof(access)); } }
private void LinkData(CLIFile pFile) { int cursor = 0; ExpandedType = new PropertySig(pFile, Type, ref cursor); }
public static PropertyDef AddProperty(ModuleDefMD module, string typeDefName, string propertyName, PropertySig type, PropertyAttributes propertyAttributeLeft) { var typeDef = module.Find(typeDefName, true); if (typeDef == null) { return(null); } var propertyDef = new PropertyDefUser(propertyName, type, propertyAttributeLeft); var existingTypeDef = typeDef.Properties.FirstOrDefault(property => property.Name == propertyName); if (existingTypeDef != null) { return(existingTypeDef); } typeDef.Properties.Add(propertyDef); return(propertyDef); }
private MosaType LoadGenericTypeInstanceSig(GenericInstSig typeSig) { //Debug.Assert(false, typeSig.FullName); MosaType origin = GetType(typeSig.GenericType); MosaType result = metadata.Controller.CreateType(origin); var desc = result.GetUnderlyingObject <UnitDesc <TypeDef, TypeSig> >(); using (var resultType = metadata.Controller.MutateType(result)) { resultType.UnderlyingObject = desc.Clone(typeSig); resultType.ElementType = origin; foreach (var genericArg in typeSig.GenericArguments) { resultType.GenericArguments.Add(GetType(genericArg)); } metadata.Resolver.EnqueueForResolve(result); GenericArgumentResolver resolver = new GenericArgumentResolver(); resolver.PushTypeGenericArguments(typeSig.GenericArguments); for (int i = 0; i < result.Methods.Count; i++) { MosaMethod method = metadata.Controller.CreateMethod(result.Methods[i]); using (var mosaMethod = metadata.Controller.MutateMethod(method)) { mosaMethod.DeclaringType = result; mosaMethod.UnderlyingObject = method.GetUnderlyingObject <UnitDesc <MethodDef, MethodSig> >(); } resultType.Methods[i] = method; metadata.Resolver.EnqueueForResolve(method); } for (int i = 0; i < result.Fields.Count; i++) { MosaField field = metadata.Controller.CreateField(result.Fields[i]); using (var mosaField = metadata.Controller.MutateField(field)) { mosaField.DeclaringType = result; mosaField.UnderlyingObject = field.GetUnderlyingObject <UnitDesc <FieldDef, FieldSig> >(); } resultType.Fields[i] = field; metadata.Resolver.EnqueueForResolve(field); } for (int i = 0; i < result.Properties.Count; i++) { MosaProperty property = metadata.Controller.CreateProperty(result.Properties[i]); PropertySig newSig = property.GetPropertySig().Clone(); newSig.RetType = resolver.Resolve(newSig.RetType); using (var mosaProperty = metadata.Controller.MutateProperty(property)) { mosaProperty.DeclaringType = result; mosaProperty.UnderlyingObject = property.GetUnderlyingObject <UnitDesc <PropertyDef, PropertySig> >(); } resultType.Properties[i] = property; metadata.Resolver.EnqueueForResolve(property); } resultType.HasOpenGenericParams = typeSig.HasOpenGenericParameter(); } metadata.Controller.AddType(result); return(result); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name</param> /// <param name="sig">Property signature</param> /// <param name="flags">Flags</param> public PropertyDefUser(UTF8String name, PropertySig sig, PropertyAttributes flags) { this.name = name; this.type = sig; this.flags = flags; }
PropertySig ResolveGenericArgs(PropertySig sig) { return(ResolveGenericArgs2(new PropertySig(), sig)); }
PropertySig ResolveGenericArgs(PropertySig sig) => ResolveGenericArgs2(new PropertySig(), sig);
public virtual void VisitPropertySig(PropertySig property) { }
public virtual void VisitPropertySig (PropertySig property) { }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name</param> /// <param name="sig">Property signature</param> public PropertyDefUser(UTF8String name, PropertySig sig) : this(name, sig, 0) { }