Exemplo n.º 1
0
 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();
 }
Exemplo n.º 2
0
        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;
                }
            }
        }
Exemplo n.º 3
0
        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]);
            }
        }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
        public PropertySig ReadPropertySignature()
        {
            uint blobIindex = ReadBlobIndex();

            if (blobIindex == 0)
            {
                return(null);
            }

            var sigReader = GetSignatureBlobReader(blobIindex);

            var sig = new PropertySig();

            sig.Read(sigReader);

            return(sig);
        }
Exemplo n.º 8
0
        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));
            }
        }
Exemplo n.º 9
0
        private void LinkData(CLIFile pFile)
        {
            int cursor = 0;

            ExpandedType = new PropertySig(pFile, Type, ref cursor);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
		/// <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;
		}
Exemplo n.º 13
0
 PropertySig ResolveGenericArgs(PropertySig sig)
 {
     return(ResolveGenericArgs2(new PropertySig(), sig));
 }
Exemplo n.º 14
0
 PropertySig ResolveGenericArgs(PropertySig sig) => ResolveGenericArgs2(new PropertySig(), sig);
Exemplo n.º 15
0
 public virtual void VisitPropertySig(PropertySig property)
 {
 }
Exemplo n.º 16
0
		public virtual void VisitPropertySig (PropertySig property)
		{
		}
Exemplo n.º 17
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="name">Name</param>
		/// <param name="sig">Property signature</param>
		public PropertyDefUser(UTF8String name, PropertySig sig)
			: this(name, sig, 0) {
		}