internal PropertyBuilder(TypeBuilder typeBuilder, string name, PropertyAttributes attributes, PropertySignature sig, bool patchCallingConvention) { this.typeBuilder = typeBuilder; this.name = name; this.attributes = attributes; this.sig = sig; this.patchCallingConvention = patchCallingConvention; }
private PropertyBuilder DefinePropertyImpl(string name, PropertyAttributes attributes, CallingConventions callingConvention, bool patchCallingConvention, Type returnType, Type[] parameterTypes, PackedCustomModifiers customModifiers) { if (properties == null) { properties = new List <PropertyBuilder>(); } PropertySignature sig = PropertySignature.Create(callingConvention, returnType, parameterTypes, customModifiers); PropertyBuilder pb = new PropertyBuilder(this, name, attributes, sig, patchCallingConvention); properties.Add(pb); return(pb); }
public void Interface() { var type = TypeSignature.Interface("MyInterface", ns, Accessibility.APublic); var method = MethodSignature.Instance("MyMethod", type, Accessibility.APublic, TypeSignature.Int32, new MethodParameter(TypeSignature.String, "myParameter")); var property = PropertySignature.Create("MyProperty", type, TypeSignature.Boolean, Accessibility.APublic, null); var typeDef = TypeDef.Empty(type) .AddMember(MethodDef.InterfaceDef(method)) .AddMember(PropertyDef.InterfaceDef(property)); cx.AddType(typeDef); check.CheckOutput(cx); }
public void Equals_Object() { var signature = new PropertySignature(typeof(int), new[] { typeof(double), typeof(string) }); object otherSignatureAsObject = new PropertySignature(typeof(int), new[] { typeof(double), typeof(string) }); Assert.That(signature.Equals(otherSignatureAsObject), Is.True); Assert.That(signature.Equals((object)null), Is.False); object completelyUnrelatedObject = new object(); Assert.That(signature.Equals(completelyUnrelatedObject), Is.False); }
public void Equals_False() { var signature = new PropertySignature(typeof(int), new[] { typeof(double), typeof(string) }); Assert.That(signature.Equals(null), Is.False); var signatureWithDifferentPropertyType = new PropertySignature(typeof(string), new[] { typeof(double), typeof(string) }); Assert.That(signature.Equals(signatureWithDifferentPropertyType), Is.False); var signatureWithDifferentIndexParameters = new PropertySignature(typeof(int), new[] { typeof(string), typeof(double) }); Assert.That(signature.Equals(signatureWithDifferentIndexParameters), Is.False); }
public void InstantiatePropertySignatureWithGenericParameterType() { var signature = PropertySignature.CreateStatic( _module.CorLibTypeFactory.String, new GenericParameterSignature(GenericParameterType.Type, 0)); var context = new GenericContext(GetProvider(_module.CorLibTypeFactory.String), null); var newSignature = signature.InstantiateGenericTypes(context); var expected = PropertySignature.CreateStatic( _module.CorLibTypeFactory.String, _module.CorLibTypeFactory.String); Assert.Equal(expected, newSignature, Comparer); }
/// <inheritdoc /> public PropertySignature ImportPropertySignature(PropertySignature signature) { var newSignature = new PropertySignature { Attributes = signature.Attributes, PropertyType = ImportTypeSignature(signature.PropertyType), }; foreach (var parameter in signature.Parameters) { newSignature.Parameters.Add(new ParameterSignature(ImportTypeSignature(parameter.ParameterType))); } return(newSignature); }
/// <summary> /// Determines whether two property signatures are considered equal according to their signatures. /// </summary> /// <param name="signature1">The first signature to compare.</param> /// <param name="signature2">The second signature to compare.</param> /// <returns><c>True</c> if the signatures are considered equal, <c>False</c> otherwise.</returns> public bool Equals(PropertySignature signature1, PropertySignature signature2) { if (signature1 == null && signature2 == null) { return(true); } if (signature1 == null || signature2 == null) { return(false); } return(signature1.Attributes == signature2.Attributes && Equals(signature1.PropertyType, signature2.PropertyType) && EqualsManyTypes(signature1.Parameters.Select(x => x.ParameterType), signature2.Parameters.Select(x => x.ParameterType))); }
public void StandardProperties() { // TODO: remove those CompilerGenerated attributes var type = TypeSignature.Class("MyType", ns, Accessibility.APublic); var prop = PropertySignature.Create("A", type, TypeSignature.String, Accessibility.APublic, Accessibility.AProtected); var td = TypeDef.Empty(type).AddMember( new PropertyDef(prop, getter: MethodDef.Create(prop.Getter, thisP => Expression.Constant("abcd")), setter: MethodDef.Create(prop.Setter, (thisP, xP) => Expression.While(FluentExpression.Box(thisP).CallMethod(MethodSignature.Object_Equals, Expression.Default(TypeSignature.Object)), Expression.Nop)) ) ); cx.AddType(td); check.CheckOutput(cx); }
public MutablePropertyInfo CreateProperty( MutableType declaringType, string name, Type type, IEnumerable <ParameterDeclaration> indexParameters, MethodAttributes accessorAttributes, Func <MethodBodyCreationContext, Expression> getBodyProvider, Func <MethodBodyCreationContext, Expression> setBodyProvider) { ArgumentUtility.CheckNotNull("declaringType", declaringType); ArgumentUtility.CheckNotNullOrEmpty("name", name); ArgumentUtility.CheckNotNull("type", type); ArgumentUtility.CheckNotNull("indexParameters", indexParameters); // Get body provider may be null. // Set body provider may be null. MemberAttributesUtility.ValidateAttributes( "property accessor methods", MemberAttributesUtility.InvalidMethodAttributes, accessorAttributes, "accessorAttributes"); if (getBodyProvider == null && setBodyProvider == null) { throw new ArgumentException("At least one accessor body provider must be specified.", "getBodyProvider"); } var indexParams = indexParameters.ToList(); var signature = new PropertySignature(type, indexParams.Select(pd => pd.Type)); if (declaringType.AddedProperties.Any(p => p.Name == name && PropertySignature.Create(p).Equals(signature))) { throw new InvalidOperationException("Property with equal name and signature already exists."); } var attributes = accessorAttributes | MethodAttributes.SpecialName; MutableMethodInfo getMethod = null, setMethod = null; if (getBodyProvider != null) { getMethod = CreateAccessor(declaringType, "get_" + name, attributes, type, indexParams, getBodyProvider); } if (setBodyProvider != null) { var setterParams = indexParams.Concat(new[] { new ParameterDeclaration(type, "value") }); setMethod = CreateAccessor(declaringType, "set_" + name, attributes, typeof(void), setterParams, setBodyProvider); } return(new MutablePropertyInfo(declaringType, name, PropertyAttributes.None, getMethod, setMethod)); }
private static PropertyDefinition CreateDummyProperty(TypeDefinition dummyType, string name) { var property = new PropertyDefinition(name, 0, PropertySignature.CreateStatic(dummyType.Module.CorLibTypeFactory.Object)); var getMethod = new MethodDefinition($"get_{property.Name}", MethodAttributes.Public | MethodAttributes.Static, MethodSignature.CreateStatic(dummyType.Module.CorLibTypeFactory.Object)); getMethod.CilMethodBody = new CilMethodBody(getMethod) { Instructions = { new CilInstruction(CilOpCodes.Ldnull), new CilInstruction(CilOpCodes.Ret) } }; dummyType.Methods.Add(getMethod); property.Semantics.Add(new MethodSemantics(getMethod, MethodSemanticsAttributes.Getter)); return(property); }
public void PersistentSignature() { var assembly = NetAssemblyFactory.CreateAssembly(DummyAssemblyName, true); var header = assembly.NetDirectory.MetadataHeader; var image = header.LockMetadata(); var property = CreateAndAddDummyProperty(image); var signature = new PropertySignature(image.TypeSystem.Byte); property.Signature = signature; var mapping = header.UnlockMetadata(); image = header.LockMetadata(); property = (PropertyDefinition)image.ResolveMember(mapping[property]); Assert.Equal(signature, property.Signature, _comparer); }
public MethodSemanticsCollectionTest() { var module = new ModuleDefinition("Module"); _property = new PropertyDefinition("Property", 0, PropertySignature.CreateStatic(module.CorLibTypeFactory.Int32)); _property2 = new PropertyDefinition("Property2", 0, PropertySignature.CreateStatic(module.CorLibTypeFactory.Int32)); _getMethod = new MethodDefinition("get_Property", MethodAttributes.Public | MethodAttributes.Static, MethodSignature.CreateStatic(module.CorLibTypeFactory.Int32)); _setMethod = new MethodDefinition("set_Property", MethodAttributes.Public | MethodAttributes.Static, MethodSignature.CreateStatic(module.CorLibTypeFactory.Void, module.CorLibTypeFactory.Int32)); }
public PropertySignature ReadPropertySignature(uint signature, PropertyDefinition parentProperty) { PropertySignature propertySig = null; using (BlobSignatureReader reader = GetBlobReader(signature)) { reader.GenericContext = parentProperty.DeclaringType; byte flag = reader.ReadByte(); if ((flag & 8) == 0) { throw new ArgumentException("Signature doesn't refer to a valid property signature."); } propertySig = new PropertySignature(); propertySig.HasThis = (flag & 0x20) != 0; NETGlobals.ReadCompressedUInt32(reader); propertySig.ReturnType = ReadTypeReference(reader, (ElementType)reader.ReadByte()); } return(propertySig); }
public CSharpSyntaxNode Convert(PropertySignature node) { PropertyDeclarationSyntax csProperty = SyntaxFactory.PropertyDeclaration(node.Type.ToCsNode <TypeSyntax>(), node.Name.Text); if (node.Parent != null && node.Parent.Kind == NodeKind.InterfaceDeclaration) { csProperty = csProperty.AddAccessorListAccessors(SyntaxFactory .AccessorDeclaration(SyntaxKind.GetAccessorDeclaration) .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))); if (!node.HasModify(NodeKind.ReadonlyKeyword)) { csProperty = csProperty.AddAccessorListAccessors(SyntaxFactory .AccessorDeclaration(SyntaxKind.SetAccessorDeclaration) .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))); } } if (node.JsDoc.Count > 0) { csProperty = csProperty.WithLeadingTrivia(SyntaxFactory.Trivia(node.JsDoc[0].ToCsNode <DocumentationCommentTriviaSyntax>())); } return(csProperty); }
/// <summary> /// Adds the given signature to this instance. If this was a stub, it is no longer a stub /// </summary> /// <param name="sig"></param> public void AddSignature(PropertySignature sig) { _signatures.Add(sig); sig.Parent = this; }
internal PropertyModification(TypeModification declaringType, UTF8String name, PropertySignature signature, ModificationKind kind, bool readOnly) : base(declaringType, name, kind, readOnly) => Signature = signature;
/// <summary> /// Erzeugt alle notwendigen Methodensignaturen. /// </summary> protected override void OnCreateDelegates() { // Create signature m_Property = CreateDelegate <PropertySignature>(0); m_Method = CreateDelegate <MethodSignature>(1); }
public void TestPropertySignature() { PropertySignature node = new PropertySignature(GetSymbolAtom(), PrimitiveType.NumberType, true, GetExpressionList(), DefaultLineInfo); CheckSerializationRoundTrip(node); }
public void Validate(Type entityType) { Property = new PropertySignature(entityType, PropertyPath); }
public bool Equals(PropertySignature other) => base.Equals(other);
/// <summary> /// Computes the full name of a property definition, including its declaring type's full name, as well as its /// return type and parameters. /// </summary> /// <param name="name">The name of the property.</param> /// <param name="declaringType">The declaring type of the property if available.</param> /// <param name="signature">The signature of the property.</param> /// <returns>The full name</returns> public static string GetPropertyFullName(string name, ITypeDescriptor declaringType, PropertySignature signature) { string propertyTypeString = signature.ReturnType.FullName ?? TypeSignature.NullTypeToString; string parameterTypesString = signature.ParameterTypes.Count > 0 ? $"[{GetParameterTypesString(signature)}]" : string.Empty; return(declaringType is null ? $"{propertyTypeString} {name}{parameterTypesString}" : $"{propertyTypeString} {declaringType}::{name}{parameterTypesString}"); }
// will return either a PropBlock or a LitBlock public static BaseBlock CreateRHSBlock(object exprSource, Type entityType, DataType otherExprDataType) { if (exprSource == null) { return(new LitBlock(exprSource, otherExprDataType)); } if (exprSource is string) { var source = (string)exprSource; if (entityType == null) { // if entityType is unknown then assume that the rhs is a // literal return(new LitBlock(source, otherExprDataType)); } if (PropertySignature.IsProperty(entityType, source)) { return(new PropBlock(source, entityType)); } else { return(new LitBlock(source, otherExprDataType)); } } if (TypeFns.IsPredefinedType(exprSource.GetType())) { return(new LitBlock(exprSource, otherExprDataType)); } if (exprSource is IDictionary <string, object> ) { var exprMap = (IDictionary <string, object>)exprSource; // note that this is NOT the same a using get and checking for null // because null is a valid 'value'. if (!exprMap.ContainsKey("value")) { throw new Exception( "Unable to locate a 'value' property on: " + exprMap.ToString()); } var value = exprMap["value"]; if (exprMap.ContainsKey("isProperty")) { return(new PropBlock((string)value, entityType)); } else { var dt = (string)exprMap["dataType"]; var dataType = (dt != null) ? DataType.FromName(dt) : otherExprDataType; return(new LitBlock(value, dataType)); } } if (exprSource is IList) { // right now this pretty much implies the values on an 'in' clause return(new LitBlock(exprSource, otherExprDataType)); } if (TypeFns.IsEnumType(exprSource.GetType())) { return(new LitBlock(exprSource, otherExprDataType)); } throw new Exception( "Unable to parse the right hand side of this BinaryExpression: " + exprSource.ToString()); }
/// <nodoc /> public virtual void Visit(PropertySignature propertySignature) { }
public void ToString_WithoutIndexParameters() { var signature = new PropertySignature(typeof(string), Type.EmptyTypes); Assert.That(signature.ToString(), Is.EqualTo("System.String()")); }
public int GetHashCode(PropertySignature obj) { return(GetHashCode(obj.PropertyType) ^ obj.Parameters.Aggregate(0, (i, signature) => i ^ GetHashCode(signature.ParameterType))); }
public void ToString_WithIndexParameters() { var signature = new PropertySignature(typeof(string), new[] { typeof(double), typeof(int) }); Assert.That(signature.ToString(), Is.EqualTo("System.String(System.Double,System.Int32)")); }