internal ByteBuffer GetSignature(ModuleBuilder module) { ByteBuffer bb = new ByteBuffer(16); switch (type) { case 0: if (unmanaged) { Signature.WriteStandAloneMethodSig(module, bb, module.universe.MakeStandAloneMethodSig(unmanagedCallConv, returnType, returnTypeCustomModifiers, args.ToArray(), customModifiers.ToArray())); } else { Signature.WriteStandAloneMethodSig(module, bb, module.universe.MakeStandAloneMethodSig(callingConvention, returnType, returnTypeCustomModifiers, args.ToArray(), optionalArgs.ToArray(), customModifiers.ToArray())); } break; case Signature.FIELD: FieldSignature.Create(args[0], customModifiers[0]).WriteSig(module, bb); break; case Signature.PROPERTY: Signature.WritePropertySig(module, bb, callingConvention, returnType, returnTypeCustomModifiers, args.ToArray(), customModifiers.ToArray()); break; case Signature.LOCAL_SIG: Signature.WriteLocalVarSig(module, bb, locals, customModifiers); break; default: throw new InvalidOperationException(); } return(bb); }
public void Create() { var field = NormalizingMemberInfoFromExpressionUtility.GetField(() => Type.EmptyTypes); var signature = FieldSignature.Create(field); Assert.That(signature.FieldType, Is.SameAs(typeof(Type[]))); }
public void Equals_True() { var signature1 = new FieldSignature(typeof(int)); var signature2 = new FieldSignature(typeof(int)); Assert.That(signature1.Equals(signature2), Is.True); }
public IMemberSignature ReadMemberRefSignature(uint sig, IGenericContext context) { IMemberSignature signature = null; BlobSignatureReader reader; if (TryGetBlobReader(sig, context, out reader)) { using (reader) { byte flag = reader.ReadByte(); if (flag == 0x6) { FieldSignature fieldsignature = new FieldSignature(); fieldsignature.ReturnType = reader.ReadTypeReference((ElementType)reader.ReadByte()); signature = fieldsignature; } else { MethodSignature methodsignature = new MethodSignature(); if ((flag & 0x20) != 0) { methodsignature.HasThis = true; flag = (byte)(flag & -33); } if ((flag & 0x40) != 0) { methodsignature.ExplicitThis = true; flag = (byte)(flag & -65); } if ((flag & 0x10) != 0) { int genericsig = NETGlobals.ReadCompressedInt32(reader); if (!context.IsDefinition) { AddMissingGenericParameters(context.Method, genericsig - 1); } } methodsignature.CallingConvention = (MethodCallingConvention)flag; uint paramCount = NETGlobals.ReadCompressedUInt32(reader); methodsignature.ReturnType = reader.ReadTypeReference(); ParameterReference[] parameters = new ParameterReference[paramCount]; for (int i = 0; i < paramCount; i++) { parameters[i] = new ParameterReference() { ParameterType = reader.ReadTypeReference((ElementType)reader.ReadByte()) }; } methodsignature.Parameters = parameters; signature = methodsignature; } } } return(signature); }
public FieldDefinition(string name, FieldAttributes attributes, FieldSignature signature) : base(new MetadataToken(MetadataTokenType.Field)) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (signature == null) { throw new ArgumentNullException(nameof(signature)); } _name = new LazyValue <string>(name); Attributes = attributes; _signature = new LazyValue <FieldSignature>(signature); _constant = new LazyValue <Constant>(); _declaringType = new LazyValue <TypeDefinition>(); _fieldRva = new LazyValue <FieldRva>(); _fieldMarshal = new LazyValue <FieldMarshal>(); _fieldLayout = new LazyValue <FieldLayout>(); _pinvokeMap = new LazyValue <ImplementationMap>(); CustomAttributes = new CustomAttributeCollection(this); }
public void NewTypeReference() { var module = ModuleDefinition.FromBytes(Properties.Resources.HelloWorld); // Import arbitrary type as reference. var importer = new ReferenceImporter(module); var reference = importer.ImportType(typeof(MemoryStream)); // Ensure type ref is added to the module by adding a dummy field referencing it. module.GetOrCreateModuleType().Fields.Add(new FieldDefinition( "MyField", FieldAttributes.Public | FieldAttributes.Static, FieldSignature.CreateStatic(reference.ToTypeSignature()))); // Rebuild. var builder = new ManagedPEImageBuilder(); var result = builder.CreateImage(module); // Assert valid token. var newToken = result.TokenMapping[reference]; Assert.NotEqual(0u, newToken.Rid); // Assert token resolves to the same type reference. var newModule = ModuleDefinition.FromImage(result.ConstructedImage); var newReference = (TypeReference)newModule.LookupMember(newToken); Assert.Equal(reference.Namespace, newReference.Namespace); Assert.Equal(reference.Name, newReference.Name); }
public void NewFieldDefinition() { var module = ModuleDefinition.FromBytes(Properties.Resources.HelloWorld); // Create new field. var field = new FieldDefinition( "MyField", FieldAttributes.Public | FieldAttributes.Static, FieldSignature.CreateStatic(module.CorLibTypeFactory.Object)); module.GetOrCreateModuleType().Fields.Add(field); // Rebuild. var builder = new ManagedPEImageBuilder(); var result = builder.CreateImage(module); // Assert valid token. var newToken = result.TokenMapping[field]; Assert.NotEqual(0u, newToken.Rid); // Assert token resolves to the new field. var newModule = ModuleDefinition.FromImage(result.ConstructedImage); var newField = (FieldDefinition)newModule.LookupMember(newToken); Assert.Equal(field.Name, newField.Name); }
/// <inheritdoc /> public FieldSignature ImportFieldSignature(FieldSignature signature) { return(new FieldSignature(ImportTypeSignature(signature.FieldType)) { Attributes = signature.Attributes }); }
/// <summary> /// Creates a new field definition. /// </summary> /// <param name="name">The name of the field.</param> /// <param name="attributes">The attributes.</param> /// <param name="signature">The signature of the field.</param> /// <remarks> /// For a valid .NET image, if <see cref="CallingConventionSignature.HasThis"/> of the signature referenced by /// <paramref name="signature"/> is set, the <see cref="FieldAttributes.Static"/> bit should be unset in /// <paramref name="attributes"/> and vice versa. /// </remarks> public FieldDefinition(string name, FieldAttributes attributes, FieldSignature signature) : this(new MetadataToken(TableIndex.Field, 0)) { Name = name; Attributes = attributes; Signature = signature; }
public void FieldLoaderConsistency(FieldInfo t) { var signature = FieldSignature.FromReflection(t); var ilSpy = cx.GetField(signature); Assert.Equal(signature, SymbolLoader.Field(ilSpy)); }
/// <summary> /// Gets the type of the field. /// </summary> /// <returns>The type of the field.</returns> protected override SigType GetFieldType() { FieldSignature fsig = new FieldSignature(); fsig.LoadSignature(this.Module.Metadata, this.signature); return(fsig.Type); }
public void GetHashCode_ForEqualObjects() { var signature1 = new FieldSignature(typeof(int)); var signature2 = new FieldSignature(typeof(int)); Assert.That(signature1.GetHashCode(), Is.EqualTo(signature2.GetHashCode())); }
/// <summary> /// Initializes a new instance of the <see cref="CilRuntimeField"/> class. /// </summary> /// <param name="module">The module.</param> /// <param name="name">The name.</param> /// <param name="signature">The signature.</param> /// <param name="token">The token.</param> /// <param name="offset">The offset.</param> /// <param name="rva">The rva.</param> /// <param name="declaringType">Type of the declaring.</param> /// <param name="attributes">The attributes.</param> public CilRuntimeField(ITypeModule module, string name, FieldSignature signature, Token token, uint offset, uint rva, RuntimeType declaringType, FieldAttributes attributes) : base(module, token, declaringType) { this.Name = name; this.Signature = signature; base.Attributes = attributes; base.RVA = rva; }
protected override void ResolveInternal(ConstantPoolItemBase[] constantPool) { base.ResolveInternal(constantPool); NameAndType.Resolve(constantPool); this.Signature = JVMdotNET.Core.ClassFile.Signature.Signature.ParseFieldSignature(NameAndType.Descriptor); }
public FieldDef Resolve(ModuleDef module, FieldSignature signature) { if (!TryResolve(module, signature, out FieldDef definition)) { throw new PatchException("missing field " + signature); } return(definition); }
public void InstantiateFieldSignature() { var signature = new FieldSignature(new GenericParameterSignature(GenericParameterType.Type, 0)); var context = new GenericContext(GetProvider(_module.CorLibTypeFactory.String), null); var newSignature = signature.InstantiateGenericTypes(context); Assert.Equal(new FieldSignature(_module.CorLibTypeFactory.String), newSignature, Comparer); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldMapSimpleRecordWithString() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldMapSimpleRecordWithString() { // When System.Reflection.MethodInfo echo = typeof(ClassWithProcedureWithSimpleArgs).GetMethod("echo", typeof(string)); IList <FieldSignature> signature = (new MethodSignatureCompiler(new TypeMappers())).SignatureFor(echo); // THen assertThat(signature, contains(FieldSignature.inputField("name", Neo4jTypes.NTString))); }
public IMemberSignature ReadMemberRefSignature(uint sig, IGenericContext context) { IMemberSignature signature = null; using (BlobSignatureReader reader = GetBlobReader(sig, context)) { byte flag = reader.ReadByte(); if (flag == 0x6) { FieldSignature fieldsignature = new FieldSignature(); fieldsignature.ReturnType = ReadTypeReference(reader, (ElementType)reader.ReadByte()); signature = fieldsignature; } else { MethodSignature methodsignature = new MethodSignature(); if ((flag & 0x20) != 0) { methodsignature.HasThis = true; flag = (byte)(flag & -33); } if ((flag & 0x40) != 0) { methodsignature.ExplicitThis = true; flag = (byte)(flag & -65); } if ((flag & 0x10) != 0) { uint genericsig = NETGlobals.ReadCompressedUInt32(reader); } methodsignature.CallingConvention = (MethodCallingConvention)flag; uint num3 = NETGlobals.ReadCompressedUInt32(reader); ElementType type = (ElementType)reader.ReadByte(); methodsignature.ReturnType = ReadTypeReference(reader, type); if (num3 != 0) { ParameterReference[] parameters = new ParameterReference[num3]; for (int i = 0; i < num3; i++) { parameters[i] = new ParameterReference() { ParameterType = ReadTypeReference(reader, (ElementType)reader.ReadByte()) }; } methodsignature.Parameters = parameters; } signature = methodsignature; } } return(signature); }
internal FieldDefinition(MetadataHeader header, MetadataToken token, MetadataRow <ushort, uint, uint> row) : base(header, token, row) { var stringStream = header.GetStream <StringStream>(); Attributes = (FieldAttributes)row.Column1; _name = new LazyValue <string>(() => stringStream.GetStringByOffset(row.Column2)); _signature = new LazyValue <FieldSignature>(() => FieldSignature.FromReader(header, header.GetStream <BlobStream>().CreateBlobReader(row.Column3))); }
public InternalField(AssemblyLoader loader, MetadataRow row, int index) : base(loader, TableId.Field, index) { _flags = (FieldAttributes)row[Schema.Field.Flags].Value; Name = row[Schema.Field.Name].String; var sigBlob = row[Schema.Field.Signature].Blob; _signature = FieldSignature.Decode(sigBlob); }
private static void AddNamedArgument(List <CustomAttributeNamedArgument> list, Type attributeType, string fieldName, Type valueType, object value) { // some fields are not available on the .NET Compact Framework version of DllImportAttribute FieldInfo field = attributeType.FindField(fieldName, FieldSignature.Create(valueType, new CustomModifiers())); if (field != null) { list.Add(new CustomAttributeNamedArgument(field, new CustomAttributeTypedArgument(valueType, value))); } }
/// <summary> /// Initializes a new instance of the <see cref="CilGenericField"/> class. /// </summary> /// <param name="module">The module.</param> /// <param name="genericField">The generic field.</param> /// <param name="signature">The signature.</param> /// <param name="declaringType">Type of the declaring.</param> public CilGenericField(ITypeModule module, RuntimeField genericField, FieldSignature signature, CilGenericType declaringType) : base(module, declaringType) { this.Signature = signature; this.Attributes = genericField.Attributes; //TODO //this.SetAttributes(genericField.CustomAttributes); base.Name = genericField.Name; }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void superClusterRoutingProcedureShouldHaveCorrectSignature() public virtual void SuperClusterRoutingProcedureShouldHaveCorrectSignature() { GetRoutersForAllDatabasesProcedure proc = new GetRoutersForAllDatabasesProcedure(null, Config.defaults()); ProcedureSignature procSig = proc.Signature(); IList <FieldSignature> output = Arrays.asList(FieldSignature.outputField("ttl", Neo4jTypes.NTInteger), FieldSignature.outputField("routers", Neo4jTypes.NTList(Neo4jTypes.NTMap))); assertEquals("The output signature of the GetRoutersForAllDatabasesProcedure should not change.", procSig.OutputSignature(), output); }
public void Equals_False() { var signature = new FieldSignature(typeof(int)); Assert.That(signature.Equals(null), Is.False); var signatureWithDifferentFieldType = new FieldSignature(typeof(string)); Assert.That(signature.Equals(signatureWithDifferentFieldType), Is.False); }
private void ResolveFields() { foreach (CilRuntimeField field in baseGenericType.Fields) { FieldSignature signature = new FieldSignature(field.Signature, genericArguments); CilGenericField genericInstanceField = new CilGenericField(Module, field, signature, this); Fields.Add(genericInstanceField); } }
public void ImportFieldFromExternalModuleShouldResultInMemberRef() { var type = new TypeReference(_dummyAssembly, null, "Type"); var field = new MemberReference(type, "Field", FieldSignature.CreateStatic(_module.CorLibTypeFactory.String)); var result = _importer.ImportField(field); Assert.Equal(field, result, _comparer); Assert.Same(_module, result.Module); }
public void PersistentFieldSignature() { var module = ModuleDefinition.FromFile(typeof(SingleField).Assembly.Location); var field = (FieldDefinition)module.LookupMember( typeof(SingleField).GetField(nameof(SingleField.IntField)).MetadataToken); field.Signature = FieldSignature.CreateInstance(module.CorLibTypeFactory.Byte); var newField = RebuildAndLookup(field); Assert.True(newField.Signature.FieldType.IsTypeOf("System", "Byte"), "Field type should be System.Byte"); }
internal FieldBuilder(TypeBuilder type, string name, Type fieldType, CustomModifiers customModifiers, FieldAttributes attribs) { this.typeBuilder = type; this.name = name; this.pseudoToken = type.ModuleBuilder.AllocPseudoToken(); this.nameIndex = type.ModuleBuilder.Strings.Add(name); this.fieldSig = FieldSignature.Create(fieldType, customModifiers); ByteBuffer sig = new ByteBuffer(5); fieldSig.WriteSig(this.typeBuilder.ModuleBuilder, sig); this.signature = this.typeBuilder.ModuleBuilder.Blobs.Add(sig); this.attribs = attribs; this.typeBuilder.ModuleBuilder.Field.AddVirtualRecord(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHaveCorrectSignature() public virtual void ShouldHaveCorrectSignature() { // given GetServersProcedureForMultiDC proc = new GetServersProcedureForMultiDC(null); // when ProcedureSignature signature = proc.Signature(); // then assertThat(signature.InputSignature(), containsInAnyOrder(FieldSignature.inputField("context", NTMap))); assertThat(signature.OutputSignature(), containsInAnyOrder(FieldSignature.outputField("ttl", NTInteger), FieldSignature.outputField("servers", NTList(NTMap)))); }
/// <inheritdoc /> public virtual MemberReference ImportField(FieldInfo field) { var signature = new FieldSignature(ImportTypeSignature(field.FieldType)); if (!field.IsStatic) { signature.Attributes |= CallingConventionAttributes.HasThis; } var declaringType = ImportType(field.DeclaringType); return(ImportMember(new MemberReference(declaringType, field.Name, signature))); }
public void StructReadonlyField() { var roField = new FieldSignature(MyStruct, "ROField", Accessibility.APublic, TypeSignature.Int32, false, true); cx.AddType(MyStructDef.AddMember(new FieldDef(roField))); var thisP = ParameterExpression.Create(TypeReference.ByReferenceType(MyStruct), "this"); var body = Expression.FieldAccess(roField, thisP).Dereference(); cx.AddTestExpr(body, thisP); check.CheckOutput(cx); }