private void InitializeMethodDefinition(Cts.MethodDesc entity, Method record)
        {
            record.Name      = HandleString(entity.Name);
            record.Signature = HandleMethodSignature(entity.Signature);

            if (entity.HasInstantiation)
            {
                var genericParams = new List <GenericParameter>(entity.Instantiation.Length);
                foreach (var p in entity.Instantiation)
                {
                    genericParams.Add(HandleGenericParameter((Cts.GenericParameterDesc)p));
                }
                record.GenericParameters = genericParams;
            }

            if (entity.Signature.Length > 0)
            {
                List <Parameter> parameters = new List <Parameter>(entity.Signature.Length);
                for (ushort i = 0; i < entity.Signature.Length; i++)
                {
                    parameters.Add(new Parameter
                    {
                        Sequence = i
                    });
                }

                var ecmaEntity = entity as Cts.Ecma.EcmaMethod;
                if (ecmaEntity != null)
                {
                    Ecma.MetadataReader            reader       = ecmaEntity.MetadataReader;
                    Ecma.MethodDefinition          methodDef    = reader.GetMethodDefinition(ecmaEntity.Handle);
                    Ecma.ParameterHandleCollection paramHandles = methodDef.GetParameters();

                    Debug.Assert(paramHandles.Count == entity.Signature.Length);

                    int i = 0;
                    foreach (var paramHandle in paramHandles)
                    {
                        Ecma.Parameter param = reader.GetParameter(paramHandle);
                        parameters[i].Flags = param.Attributes;
                        parameters[i].Name  = HandleString(reader.GetString(param.Name));

                        // TODO: CustomAttributes
                        // TODO: DefaultValue

                        i++;
                    }
                }

                record.Parameters = parameters;
            }

            record.Flags     = GetMethodAttributes(entity);
            record.ImplFlags = GetMethodImplAttributes(entity);

            //TODO: MethodImpls
            //TODO: RVA
            //TODO: CustomAttributes
        }
Beispiel #2
0
        private void InitializeMethodDefinition(Cts.MethodDesc entity, Method record)
        {
            record.Name      = HandleString(entity.Name);
            record.Signature = HandleMethodSignature(entity.Signature);

            if (entity.HasInstantiation)
            {
                record.GenericParameters.Capacity = entity.Instantiation.Length;
                foreach (var p in entity.Instantiation)
                {
                    record.GenericParameters.Add(HandleGenericParameter((Cts.GenericParameterDesc)p));
                }
            }

            var ecmaEntity = entity as Cts.Ecma.EcmaMethod;

            if (ecmaEntity != null)
            {
                Ecma.MetadataReader            reader       = ecmaEntity.MetadataReader;
                Ecma.MethodDefinition          methodDef    = reader.GetMethodDefinition(ecmaEntity.Handle);
                Ecma.ParameterHandleCollection paramHandles = methodDef.GetParameters();

                record.Parameters.Capacity = paramHandles.Count;
                foreach (var paramHandle in paramHandles)
                {
                    Ecma.Parameter param       = reader.GetParameter(paramHandle);
                    Parameter      paramRecord = new Parameter
                    {
                        Flags    = param.Attributes,
                        Name     = HandleString(reader.GetString(param.Name)),
                        Sequence = checked ((ushort)param.SequenceNumber)
                    };

                    Ecma.ConstantHandle defaultValue = param.GetDefaultValue();
                    if (!defaultValue.IsNil)
                    {
                        paramRecord.DefaultValue = HandleConstant(ecmaEntity.Module, defaultValue);
                    }

                    Ecma.CustomAttributeHandleCollection paramAttributes = param.GetCustomAttributes();
                    if (paramAttributes.Count > 0)
                    {
                        paramRecord.CustomAttributes = HandleCustomAttributes(ecmaEntity.Module, paramAttributes);
                    }

                    record.Parameters.Add(paramRecord);
                }

                Ecma.CustomAttributeHandleCollection attributes = methodDef.GetCustomAttributes();
                if (attributes.Count > 0)
                {
                    record.CustomAttributes = HandleCustomAttributes(ecmaEntity.Module, attributes);
                }
            }
            else
            {
                throw new NotImplementedException();
            }

            record.Flags     = GetMethodAttributes(entity);
            record.ImplFlags = GetMethodImplAttributes(entity);

            //TODO: RVA
        }