Exemplo n.º 1
0
 public static VirtualPropertyInfo Create(string name,
                                          Type declaringType,
                                          Type reflectedType,
                                          Type propertyType,
                                          PropertyAttributes attributes,
                                          bool readable,
                                          bool writable)
 {
     return
         internalizedCache.GetOrAdd(
             GetUniqueKey(declaringType, reflectedType, propertyType, readable, writable, name, attributes),
             key =>
             {
                 VirtualMethodInfo getterBaseDefinition = null;
                 VirtualPropertyInfo baseProperty = null;
                 if (declaringType != reflectedType)
                 {
                     baseProperty = Create(name, declaringType, declaringType, propertyType, attributes, readable,
                                           writable);
                     getterBaseDefinition = baseProperty.getMethod;
                 }
                 const MethodAttributes methodAttributes =
                     MethodAttributes.NewSlot | MethodAttributes.SpecialName |
                     MethodAttributes.HideBySig
                     | MethodAttributes.Virtual | MethodAttributes.Public;
                 var getter = new VirtualMethodInfo("get_" + name, declaringType, reflectedType, methodAttributes,
                                                    baseDefinition : getterBaseDefinition);
                 var prop = new VirtualPropertyInfo(name, declaringType, reflectedType, propertyType, getter,
                                                    null, attributes, baseProperty);
                 return prop;
             });
 }
 public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, Type returnType, Type[] parameterTypes)
 {
     var pb = _typeBuilder.DefineProperty(name, attributes, returnType, parameterTypes);
     _members.Add(pb);
     _paramsByMember.Add(pb, parameterTypes);
     return pb;
 }
Exemplo n.º 3
0
 internal VirtualPropertyInfo(string name,
                              Type declaringType,
                              Type reflectedType,
                              Type propertyType,
                              VirtualMethodInfo getMethod,
                              VirtualMethodInfo setMethod,
                              PropertyAttributes attributes,
                              VirtualPropertyInfo baseDefinition)
 {
     if (declaringType == null)
         throw new ArgumentNullException(nameof(declaringType));
     if (reflectedType == null)
         throw new ArgumentNullException(nameof(reflectedType));
     if (propertyType == null)
         throw new ArgumentNullException(nameof(propertyType));
     if (name == null)
         throw new ArgumentNullException(nameof(name));
     DeclaringType = declaringType;
     ReflectedType = reflectedType;
     PropertyType = propertyType;
     this.getMethod = getMethod;
     this.setMethod = setMethod;
     Name = name;
     Attributes = attributes;
     BaseDefinition = baseDefinition ?? this;
     MetadataToken = VirtualMemberMetadataTokenAllocator.AllocateToken();
 }
Exemplo n.º 4
0
		// private ParameterInfo[] indexParameters;

		public PropertyEmitter(AbstractTypeEmitter parentTypeEmitter, string name, PropertyAttributes attributes,
		                       Type propertyType, Type[] arguments)
		{
			this.parentTypeEmitter = parentTypeEmitter;

			// DYNPROXY-73 - AmbiguousMatchException for properties
			// This is a workaround for a framework limitation in CLR 2.0 
			// This limitation was removed in CLR 2.0 SP1, but we don't want to 
			// tie ourselves to that version. This perform the lookup for the new overload
			// dynamically, so we have a nice fallback on vanilla CLR 2.0

			if (TypeBuilderMethods.DefineProperty == null || true) // TODO
			{
				DefineProperty_Clr2_0 oldDefineProperty = parentTypeEmitter.TypeBuilder.DefineProperty;
				builder = oldDefineProperty(name, attributes, propertyType, arguments);
			}
			else
			{
				var newDefinedProperty = (DefineProperty_Clr_2_0_SP1)
				                         Delegate.CreateDelegate(typeof(DefineProperty_Clr_2_0_SP1),
				                                                 parentTypeEmitter.TypeBuilder,
				                                                 TypeBuilderMethods.DefineProperty);
				builder = newDefinedProperty(
					name, attributes, CallingConventions.HasThis, propertyType,
					null, null, arguments, null, null);
			}
		}
		public PropertyInfoMirror (TypeMirror parent, long id, string name, MethodMirror get_method, MethodMirror set_method, PropertyAttributes attrs) : base (parent.VirtualMachine, id) {
			this.parent = parent;
			this.name = name;
			this.attrs = attrs;
			this.get_method = get_method;
			this.set_method = set_method;
		}
Exemplo n.º 6
0
 public MarshalAccessorProperty(int index, JsObject getter, JsObject setter, PropertyAttributes attributes)
 {
     Index = index;
     Getter = getter;
     Setter = setter;
     Attributes = attributes;
 }
Exemplo n.º 7
0
        // private ParameterInfo[] indexParameters;
        public PropertyEmitter(AbstractTypeEmitter parentTypeEmitter, String name, PropertyAttributes attributes,
		                       Type propertyType)
        {
            this.parentTypeEmitter = parentTypeEmitter;

            builder = parentTypeEmitter.TypeBuilder.DefineProperty(name, attributes, propertyType, new Type[0]);
        }
Exemplo n.º 8
0
 // Constructs a PropertyBuilder.  
 //
 internal PropertyBuilder(
     ModuleBuilder       mod,            // the module containing this PropertyBuilder
     String              name,           // property name
     SignatureHelper     sig,            // property signature descriptor info
     PropertyAttributes  attr,           // property attribute such as DefaultProperty, Bindable, DisplayBind, etc
     Type                returnType,     // return type of the property.
     PropertyToken       prToken,        // the metadata token for this property
     TypeBuilder         containingType) // the containing type
 {
     if (name == null)
         throw new ArgumentNullException("name");
     if (name.Length == 0)
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
     if (name[0] == '\0')
         throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), "name");
     Contract.EndContractBlock();
     
     m_name = name;
     m_moduleBuilder = mod;
     m_signature = sig;
     m_attributes = attr;
     m_returnType = returnType;
     m_prToken = prToken;
     m_tkProperty = prToken.Token;
     m_containingType = containingType;
 }
Exemplo n.º 9
0
		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;
		}
Exemplo n.º 10
0
 public void DefineProperty(object index, object value, PropertyAttributes attributes)
 {
     DefineProperty(
         _global.ResolveIdentifier(JsValue.ToString(index)),
         value,
         attributes
     );
 }
		internal MetadataPropertyInfo (IMetadataImport importer, int propertyToken, MetadataType declaringType)
		{
			m_importer = importer;
			m_propertyToken = propertyToken;
			m_declaringType = declaringType;

			int mdTypeDef;
			int pchProperty;
			int pdwPropFlags;
			IntPtr ppvSig;
			int pbSig;
			int pdwCPlusTypeFlag;
			IntPtr ppDefaultValue;
			int pcchDefaultValue;
			int rmdOtherMethod;
			int pcOtherMethod;

			m_importer.GetPropertyProps (
				m_propertyToken,
				out mdTypeDef,
				null,
				0,
				out pchProperty,
				out pdwPropFlags,
				out ppvSig,
				out pbSig,
				out pdwCPlusTypeFlag,
				out ppDefaultValue,
				out pcchDefaultValue,
				out m_pmdSetter,
				out m_pmdGetter,
				out rmdOtherMethod,
				0,
				out pcOtherMethod);

			StringBuilder szProperty = new StringBuilder (pchProperty);
			m_importer.GetPropertyProps (
				m_propertyToken,
				out mdTypeDef,
				szProperty,
				pchProperty,
				out pchProperty,
				out pdwPropFlags,
				out ppvSig,
				out pbSig,
				out pdwCPlusTypeFlag,
				out ppDefaultValue,
				out pcchDefaultValue,
				out m_pmdSetter,
				out m_pmdGetter,
				out rmdOtherMethod,
				0,
				out pcOtherMethod);

			m_propAttributes = (PropertyAttributes) pdwPropFlags;
			m_name = szProperty.ToString ();
			MetadataHelperFunctions.GetCustomAttribute (importer, propertyToken, typeof (System.Diagnostics.DebuggerBrowsableAttribute));
		}
Exemplo n.º 12
0
        public JsSchema Add(int index, PropertyAttributes attributes, ref object[] values, object value)
        {
            // The entry shouldn't be in our schema yet.
            Debug.Assert(GetOffset(index) < 0);

            // Get or create the new schema.
            JsSchema schema = null;

            // Check whether we already have a transformation.
            if (_transformations != null)
                schema = _transformations.GetValue(MakeIndex(index, attributes));

            int newOffset;

            // Build the new schema if we don't have it yet and add it to the
            // list of transformations.
            if (schema == null)
            {
                schema = new JsSchema(this);

                // Apply the mutation to the new schema. We get a free entry or,
                // if there isn't any, increase the array size.

                var freeList = schema._freeList;
                if (freeList == null)
                {
                    schema.GrowFreeEntries();
                    freeList = schema._freeList;
                }

                schema._freeList = freeList.Next;
                newOffset = freeList.Index;

                schema._node = new Node(true, index, attributes, newOffset, _node);

                if (_transformations == null)
                    _transformations = new SchemaTransformationHashSet(InitialTransformationsSize);

                _transformations.Add(MakeIndex(index, attributes), schema);
            }
            else
            {
                newOffset = schema.GetOffset(index);

                // The attributes of this property of the new schema should
                // be the same as what we're adding.
                Debug.Assert(schema.GetAttributes(index) == attributes);
            }

            // Apply the transformation to the values array.
            if (_arraySize != schema._arraySize)
                Array.Resize(ref values, schema._arraySize);

            values[newOffset] = value;

            return schema;
        }
Exemplo n.º 13
0
		public PropertyEmitter(AbstractTypeEmitter parentTypeEmitter, string name, PropertyAttributes attributes,
		                       Type propertyType, Type[] arguments)
		{
			this.parentTypeEmitter = parentTypeEmitter;

			builder = parentTypeEmitter.TypeBuilder.DefineProperty(
				name, attributes, CallingConventions.HasThis, propertyType,
				null, null, arguments, null, null);
		}
Exemplo n.º 14
0
 public void DefineAccessor(int index, JsObject getter, JsObject setter, PropertyAttributes attributes)
 {
     EnsurePropertyStore();
     PropertyStore.DefineProperty(
         index,
         new PropertyAccessor(getter, setter),
         attributes
     );
 }
Exemplo n.º 15
0
 public void DefineProperty(int index, JsFunction @delegate, int argumentCount, PropertyAttributes attributes)
 {
     EnsurePropertyStore();
     PropertyStore.DefineProperty(
         index,
         Global.CreateFunction(Global.GetIdentifier(index), @delegate, argumentCount),
         attributes
     );
 }
Exemplo n.º 16
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.º 17
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.º 18
0
        public void DefineProperty(PropertyAttributes attributes, PropertyAttributes expected)
        {
            TypeBuilder type = Helpers.DynamicType(TypeAttributes.Class | TypeAttributes.Public);

            type.DefineProperty("TestProperty", attributes, typeof(int), null, null, new Type[] { typeof(int) }, null, null);

            Type createdType = type.CreateTypeInfo().AsType();
            PropertyInfo createdProperty = createdType.GetProperty("TestProperty", BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            
            Assert.Equal(typeof(int), createdProperty.PropertyType);
            Assert.Equal(expected, createdProperty.Attributes);
        }
Exemplo n.º 19
0
        public void DefineAccessor(int index, JsFunction getter, JsFunction setter, PropertyAttributes attributes)
        {
            var getterObject =
                getter != null
                    ? Global.CreateFunction(null, getter, 0)
                    : null;
            var setterObject =
                setter != null
                    ? Global.CreateFunction(null, setter, 1)
                    : null;

            DefineAccessor(index, getterObject, setterObject, attributes);
        }
Exemplo n.º 20
0
#pragma warning restore 169, 414
		
		internal PropertyBuilder (TypeBuilder tb, string name, PropertyAttributes attributes, Type returnType, Type[] returnModReq, Type[] returnModOpt, Type[] parameterTypes, Type[][] paramModReq, Type[][] paramModOpt) {
			this.name = name;
			this.attrs = attributes;
			this.type = returnType;
			this.returnModReq = returnModReq;
			this.returnModOpt = returnModOpt;
			this.paramModReq = paramModReq;
			this.paramModOpt = paramModOpt;
			if (parameterTypes != null) {
				this.parameters = new Type [parameterTypes.Length];
				System.Array.Copy (parameterTypes, this.parameters, this.parameters.Length);
			}
			typeb = tb;
			table_idx = tb.get_next_table_index (this, 0x17, true);
		}
Exemplo n.º 21
0
        public PropertyMetadata(
            PropertyInfo propertyInfo, 
            MethodMetadata getMethod, 
            MethodMetadata setMethod)
            : base(propertyInfo)
        {
            _propertyInfo = propertyInfo;

            _getMethod = getMethod;
            _setMethod = setMethod;

            _indexerTypes = GetIndexerTypes(_propertyInfo);

            _propertyAttributes = propertyInfo.Attributes;
        }
Exemplo n.º 22
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="typeBuilder">Type builder</param>
 /// <param name="name">Name of the property</param>
 /// <param name="attributes">Attributes for the property (public, private, etc.)</param>
 /// <param name="getMethodAttributes">Get method attributes</param>
 /// <param name="setMethodAttributes">Set method attributes</param>
 /// <param name="propertyType">Property type for the property</param>
 /// <param name="parameters">Parameter types for the property</param>
 public DefaultPropertyBuilder(TypeBuilder typeBuilder, string name,
                               PropertyAttributes attributes, MethodAttributes getMethodAttributes,
                               MethodAttributes setMethodAttributes,
                               Type propertyType, IEnumerable<Type> parameters)
 {
     if (typeBuilder == null)
         throw new ArgumentNullException("typeBuilder");
     if (string.IsNullOrEmpty(name))
         throw new ArgumentNullException("name");
     Name = name;
     Type = typeBuilder;
     Attributes = attributes;
     GetMethodAttributes = getMethodAttributes;
     SetMethodAttributes = setMethodAttributes;
     DataType = propertyType;
     Parameters = new List<ParameterBuilder>();
     if (parameters != null)
     {
         int x = 1;
         foreach (var parameter in parameters)
         {
             Parameters.Add(new ParameterBuilder(parameter, x));
             ++x;
         }
     }
     Field = new FieldBuilder(Type, "_" + name + "field", propertyType, FieldAttributes.Private);
     Builder = Type.Builder.DefineProperty(name, attributes, propertyType,
                                           (parameters != null && parameters.Count() > 0)
                                               ? parameters.ToArray()
                                               : System.Type.EmptyTypes);
     GetMethod = new MethodBuilder(Type, "get_" + name, getMethodAttributes, parameters, propertyType);
     GetMethod.Generator.Emit(OpCodes.Ldarg_0);
     GetMethod.Generator.Emit(OpCodes.Ldfld, Field.Builder);
     GetMethod.Generator.Emit(OpCodes.Ret);
     var setParameters = new List<Type>();
     if (parameters != null)
     {
         setParameters.AddRange(parameters);
     }
     setParameters.Add(propertyType);
     SetMethod = new MethodBuilder(Type, "set_" + name, setMethodAttributes, setParameters, typeof (void));
     SetMethod.Generator.Emit(OpCodes.Ldarg_0);
     SetMethod.Generator.Emit(OpCodes.Ldarg_1);
     SetMethod.Generator.Emit(OpCodes.Stfld, Field.Builder);
     SetMethod.Generator.Emit(OpCodes.Ret);
     Builder.SetGetMethod(GetMethod.Builder);
     Builder.SetSetMethod(SetMethod.Builder);
 }
        /// <summary>
        /// Creates a new PropertyDescriptor instance.
        /// </summary>
        /// <param name="value"> The initial value for the property. </param>
        /// <param name="attributes"> The property attributes. </param>
        public PropertyDescriptor(object value, PropertyAttributes attributes)
        {
            this.attributes = attributes;
            this.value = value;

            // If the property is an accessor property, the state of the writable flag is dependant
            // whether the setter function exists. 
            if (this.value is PropertyAccessorValue)
            {
                this.attributes |= PropertyAttributes.IsAccessorProperty;
                if (this.Setter != null)
                    this.attributes |= PropertyAttributes.Writable;
                else
                    this.attributes &= ~PropertyAttributes.Writable;
            }
        }
Exemplo n.º 24
0
        public void DefineProperty(string name, PropertyAttributes attributes, Type returnType, Type[] parameterTypes, string expectedName, PropertyAttributes expectedPropertyAttributes)
        {
            TypeBuilder type = Helpers.DynamicType(TypeAttributes.Class | TypeAttributes.Public);
            PropertyBuilder property = type.DefineProperty(name, attributes, returnType, parameterTypes);
            Assert.Equal(name, property.Name);
            Assert.Equal(attributes, property.Attributes);
            Assert.Equal(returnType, property.PropertyType);

            Type createdType = type.CreateTypeInfo().AsType();
            Assert.Equal(type.AsType().GetProperties(Helpers.AllFlags), createdType.GetProperties(Helpers.AllFlags));

            PropertyInfo createdProperty = createdType.GetProperty(expectedName, Helpers.AllFlags);
            Assert.Equal(expectedName, createdProperty.Name);
            Assert.Equal(expectedPropertyAttributes, createdProperty.Attributes);
            Assert.Equal(returnType ?? typeof(void), createdProperty.PropertyType);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="TypeBuilder">Type builder</param>
 /// <param name="Name">Name of the property</param>
 /// <param name="Attributes">Attributes for the property (public, private, etc.)</param>
 /// <param name="GetMethodAttributes">Get method attributes</param>
 /// <param name="SetMethodAttributes">Set method attributes</param>
 /// <param name="PropertyType">Property type for the property</param>
 /// <param name="Parameters">Parameter types for the property</param>
 public DefaultPropertyBuilder(TypeBuilder TypeBuilder, string Name,
     PropertyAttributes Attributes, MethodAttributes GetMethodAttributes,
     MethodAttributes SetMethodAttributes,
     Type PropertyType, List<Type> Parameters)
     : base()
 {
     if (TypeBuilder == null)
         throw new ArgumentNullException("TypeBuilder");
     if (string.IsNullOrEmpty(Name))
         throw new ArgumentNullException("Name");
     this.Name = Name;
     this.Type = TypeBuilder;
     this.Attributes = Attributes;
     this.GetMethodAttributes = GetMethodAttributes;
     this.SetMethodAttributes = SetMethodAttributes;
     this.DataType = PropertyType;
     this.Parameters = new List<ParameterBuilder>();
     if (Parameters != null)
     {
         int x = 1;
         foreach (Type Parameter in Parameters)
         {
             this.Parameters.Add(new ParameterBuilder(Parameter, x));
             ++x;
         }
     }
     Field = new FieldBuilder(Type, "_" + Name + "field", PropertyType, FieldAttributes.Private);
     Builder = Type.Builder.DefineProperty(Name, Attributes, PropertyType,
         (Parameters != null && Parameters.Count > 0) ? Parameters.ToArray() : System.Type.EmptyTypes);
     GetMethod = new MethodBuilder(Type, "get_" + Name, GetMethodAttributes, Parameters, PropertyType);
     GetMethod.Generator.Emit(OpCodes.Ldarg_0);
     GetMethod.Generator.Emit(OpCodes.Ldfld, Field.Builder);
     GetMethod.Generator.Emit(OpCodes.Ret);
     List<Type> SetParameters = new List<System.Type>();
     if (Parameters != null)
     {
         SetParameters.AddRange(Parameters);
     }
     SetParameters.Add(PropertyType);
     SetMethod = new MethodBuilder(Type, "set_" + Name, SetMethodAttributes, SetParameters, typeof(void));
     SetMethod.Generator.Emit(OpCodes.Ldarg_0);
     SetMethod.Generator.Emit(OpCodes.Ldarg_1);
     SetMethod.Generator.Emit(OpCodes.Stfld, Field.Builder);
     SetMethod.Generator.Emit(OpCodes.Ret);
     Builder.SetGetMethod(GetMethod.Builder);
     Builder.SetSetMethod(SetMethod.Builder);
 }
Exemplo n.º 26
0
		internal CodeProperty (CodeClass cls, string name, PropertyAttributes attributes, MethodAttributes methodAttributes, Type returnType, Type[] parameterTypes) 
		{
			this.cls = cls;
			this.typeBuilder = cls.TypeBuilder;
			this.name = name;
			this.attributes = attributes;
			this.methodAttributes = methodAttributes;
			this.returnType = returnType;
			this.parameterTypes = parameterTypes;
		
			PropertyBuilder pb = typeBuilder.DefineProperty (name, attributes, returnType, parameterTypes);
			pb.SetGetMethod (typeBuilder.DefineMethod ("get_" + name, methodAttributes, CallingConventions.Standard, returnType, Type.EmptyTypes));
			pb.SetSetMethod (typeBuilder.DefineMethod ("set_" + name, methodAttributes, CallingConventions.Standard, typeof (void), new Type [] {returnType}));
			get_builder = new CodeBuilder (cls);
			set_builder = new CodeBuilder (cls);
			propertyInfo = pb;
		}
Exemplo n.º 27
0
        private void ExecutePosTest(PropertyAttributes propertyAttr)
        {
            TypeBuilder myTypeBuilder;
            PropertyBuilder myPropertyBuilder;
            PropertyAttributes actualAttributes;
            myTypeBuilder = GetTypeBuilder(
                                    DynamicTypeName,
                                    TypeAttributes.Class |
                                    TypeAttributes.Public);

            myPropertyBuilder = myTypeBuilder.DefineProperty(
                                    DynamicPropertyName,
                                    propertyAttr,
                                    typeof(int),
                                    null);
            actualAttributes = myPropertyBuilder.Attributes;
            Assert.Equal(propertyAttr, actualAttributes);
        }
Exemplo n.º 28
0
        public void GeneralPositiveTest(PropertyAttributes attr)
        {
            AssemblyName myAsmName =
                new AssemblyName("TypeBuilderDefineProperty");
            AssemblyBuilder myAssembly = AssemblyBuilder.DefineDynamicAssembly(
                 myAsmName, AssemblyBuilderAccess.Run);
            ModuleBuilder myModule = TestLibrary.Utilities.GetModuleBuilder(myAssembly, "Module1");

            TypeBuilder myType = myModule.DefineType("Sample",
                TypeAttributes.Class | TypeAttributes.Public);

            myType.DefineProperty("TestProperty", attr, typeof(int), null, null, new Type[] { typeof(int) }, null, null);

            Type t = myType.CreateTypeInfo().AsType();

            PropertyInfo pi = t.GetProperty("TestProperty", BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            Assert.NotNull(pi);
            Assert.Equal(typeof(int), pi.PropertyType);
        }
Exemplo n.º 29
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="TypeBuilder">Type builder</param>
 /// <param name="Name">Name of the property</param>
 /// <param name="Attributes">Attributes for the property (public, private, etc.)</param>
 /// <param name="GetMethodAttributes">Get method attributes</param>
 /// <param name="SetMethodAttributes">Set method attributes</param>
 /// <param name="PropertyType">Property type for the property</param>
 /// <param name="Parameters">Parameter types for the property</param>
 public PropertyBuilder(TypeBuilder TypeBuilder, 
     string Name,
     PropertyAttributes Attributes, 
     MethodAttributes GetMethodAttributes,
     MethodAttributes SetMethodAttributes,
     Type PropertyType, 
     IEnumerable<Type> Parameters)
     : base()
 {
     if (TypeBuilder == null)
         throw new ArgumentNullException("TypeBuilder");
     if (string.IsNullOrEmpty(Name))
         throw new ArgumentNullException("Name");
     this.Name = Name;
     this.Type = TypeBuilder;
     this.Attributes = Attributes;
     this.GetMethodAttributes = GetMethodAttributes;
     this.SetMethodAttributes = SetMethodAttributes;
     this.DataType = PropertyType;
     this.Parameters = new List<ParameterBuilder>();
     if (Parameters != null)
     {
         int x = 1;
         foreach (Type Parameter in Parameters)
         {
             this.Parameters.Add(new ParameterBuilder(Parameter, x));
             ++x;
         }
     }
     Builder = Type.Builder.DefineProperty(Name, Attributes, PropertyType,
         (Parameters != null && Parameters.Count() > 0) ? Parameters.ToArray() : System.Type.EmptyTypes);
     GetMethod = new MethodBuilder(Type, "get_" + Name, GetMethodAttributes, Parameters, PropertyType);
     List<Type> SetParameters = new List<System.Type>();
     if (Parameters != null)
         SetParameters.AddRange(Parameters);
     SetParameters.Add(PropertyType);
     SetMethod = new MethodBuilder(Type, "set_" + Name, SetMethodAttributes, SetParameters, typeof(void));
     Builder.SetGetMethod(GetMethod.Builder);
     Builder.SetSetMethod(SetMethod.Builder);
 }
 internal PropertyBuilder(ModuleBuilder mod, string name, SignatureHelper sig, PropertyAttributes attr, Type returnType, System.Reflection.Emit.PropertyToken prToken, TypeBuilder containingType)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (name.Length == 0)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
     }
     if (name[0] == '\0')
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), "name");
     }
     this.m_name = name;
     this.m_moduleBuilder = mod;
     this.m_signature = sig;
     this.m_attributes = attr;
     this.m_returnType = returnType;
     this.m_prToken = prToken;
     this.m_tkProperty = prToken.Token;
     this.m_containingType = containingType;
 }
Exemplo n.º 31
0
 /// <inheritdoc />
 public IPropertyBuilder Attributes(PropertyAttributes attributes)
 {
     this.PropertyAttributes = attributes;
     return(this);
 }
Exemplo n.º 32
0
 public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, Type returnType, Type[] parameterTypes)
 {
     return(DefineProperty(name, attributes, returnType, null, null, parameterTypes, null, null));
 }
 public static PropertyBuilder DefineProperty(this TypeBuilder tb, string name, PropertyAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
 {
     return(tb.DefineProperty(name, attributes, returnType, parameterTypes));
 }
Exemplo n.º 34
0
 public void DynamicPropertyLoadWait(PropertyAttributes attributes)
 {
     attributes.IsBrowsable = (CommPointType == CommPointATCInfo.CommPointATCTypes.TransportRequest ||
                               CommPointType == CommPointATCInfo.CommPointATCTypes.TransportFinished ||
                               CommPointType == CommPointATCInfo.CommPointATCTypes.TransportRequestOrFinished);
 }
Exemplo n.º 35
0
 public PropertyBuilder __DefineProperty(string name, PropertyAttributes attributes, CallingConventions callingConvention,
                                         Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
 {
     return(DefinePropertyImpl(name, attributes, callingConvention, false, returnType, parameterTypes,
                               PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, Util.NullSafeLength(parameterTypes))));
 }
Exemplo n.º 36
0
        //     OBJECT SERIALIZATION AND DESERIALIZATION
        //_________________________________________________________________________________________

        /// <summary>
        /// Creates a property descriptor from an object containing any of the following
        /// properties: configurable, writable, enumerable, value, get, set.
        /// </summary>
        /// <param name="obj"> The object to get the property values from. </param>
        /// <param name="defaults"> The values to use if the relevant value is not specified. </param>
        /// <returns> A PropertyDescriptor that corresponds to the object. </returns>
        public static PropertyDescriptor FromObject(ObjectInstance obj, PropertyDescriptor defaults)
        {
            if (obj == null)
            {
                return(PropertyDescriptor.Undefined);
            }

            // Read configurable attribute.
            bool configurable = defaults.IsConfigurable;

            if (obj.HasProperty("configurable"))
            {
                configurable = TypeConverter.ToBoolean(obj["configurable"]);
            }

            // Read writable attribute.
            bool writable = defaults.IsWritable;

            if (obj.HasProperty("writable"))
            {
                writable = TypeConverter.ToBoolean(obj["writable"]);
            }

            // Read enumerable attribute.
            bool enumerable = defaults.IsEnumerable;

            if (obj.HasProperty("enumerable"))
            {
                enumerable = TypeConverter.ToBoolean(obj["enumerable"]);
            }

            // Read property value.
            object value = defaults.Value;

            if (obj.HasProperty("value"))
            {
                value = obj["value"];
            }

            // The descriptor is an accessor if get or set is present.
            bool isAccessor = false;

            // Read get accessor.
            FunctionInstance getter = defaults.Getter;

            if (obj.HasProperty("get"))
            {
                if (obj.HasProperty("value"))
                {
                    throw new JavaScriptException(ErrorType.TypeError, "Property descriptors cannot have both 'get' and 'value' set");
                }
                if (obj.HasProperty("writable"))
                {
                    throw new JavaScriptException(ErrorType.TypeError, "Property descriptors with 'get' or 'set' defined must not have 'writable' set");
                }
                if (obj["get"] is FunctionInstance)
                {
                    getter = (FunctionInstance)obj["get"];
                }
                else if (TypeUtilities.IsUndefined(obj["get"]) == true)
                {
                    getter = null;
                }
                else
                {
                    throw new JavaScriptException(ErrorType.TypeError, "Property descriptor 'get' must be a function");
                }
                isAccessor = true;
            }

            // Read set accessor.
            FunctionInstance setter = defaults.Setter;

            if (obj.HasProperty("set"))
            {
                if (obj.HasProperty("value"))
                {
                    throw new JavaScriptException(ErrorType.TypeError, "Property descriptors cannot have both 'set' and 'value' set");
                }
                if (obj.HasProperty("writable"))
                {
                    throw new JavaScriptException(ErrorType.TypeError, "Property descriptors with 'get' or 'set' defined must not have 'writable' set");
                }
                if (obj["set"] is FunctionInstance)
                {
                    setter = (FunctionInstance)obj["set"];
                }
                else if (TypeUtilities.IsUndefined(obj["set"]) == true)
                {
                    setter = null;
                }
                else
                {
                    throw new JavaScriptException(ErrorType.TypeError, "Property descriptor 'set' must be a function");
                }
                isAccessor = true;
            }

            // Build up the attributes enum.
            PropertyAttributes attributes = PropertyAttributes.Sealed;

            if (configurable == true)
            {
                attributes |= PropertyAttributes.Configurable;
            }
            if (writable == true)
            {
                attributes |= PropertyAttributes.Writable;
            }
            if (enumerable == true)
            {
                attributes |= PropertyAttributes.Enumerable;
            }

            // Either a value or an accessor is possible.
            object descriptorValue = value;

            if (isAccessor == true)
            {
                descriptorValue = new PropertyAccessorValue(getter, setter);
            }

            // Create the new property descriptor.
            return(new PropertyDescriptor(descriptorValue, attributes));
        }
Exemplo n.º 37
0
 public PropertyDefinition(string name, PropertyAttributes attributes, TypeReference propertyType) : base(name, propertyType)
 {
     this.constant   = Mixin.NotResolved;
     this.attributes = (ushort)attributes;
     base.token      = new MetadataToken(TokenType.Property);
 }
Exemplo n.º 38
0
        private MutablePropertyInfo CreateProperty(MutableType mutableType, PropertyAttributes attributes)
        {
            var getMethod = MutableMethodInfoObjectMother.Create(returnType: typeof(int));

            return(_factory.CreateProperty(mutableType, "dummy", attributes, getMethod, null));
        }
Exemplo n.º 39
0
 public void DynamicPropertyAssemblyPLCconfig(PropertyAttributes attributes)
 {
     attributes.IsBrowsable = Controller != null && threeWaySwitchInfo.controlType == ControlTypes.Controller;
 }
Exemplo n.º 40
0
 //public void DynamicPropertyArrival_Point_Arrival_Delay_CallForwardPoint(PropertyAttributes attributes)
 public void DynamicPropertyArrival_Point(PropertyAttributes attributes)
 {
     attributes.IsBrowsable = (commPointDatcomInfo.commPointType == CommPointDatcomInfo.CommPointTypes.Arrival_Point);// ||
     //commPointDatcomInfo.commPointType == CommPointDatcomInfo.CommPointTypes.Arrival_Delay ||
     //commPointDatcomInfo.commPointType == CommPointDatcomInfo.CommPointTypes.CallForwardPoint);
 }
Exemplo n.º 41
0
        public void Attributes(Type type, string name, PropertyAttributes expected)
        {
            PropertyInfo propertyInfo = GetProperty(type, name);

            Assert.Equal(expected, propertyInfo.Attributes);
        }
Exemplo n.º 42
0
        //public void DynamicPropertyDelayPoint(PropertyAttributes attributes)
        //{
        //    attributes.IsBrowsable = (CommPointType == CommPointDatcomInfo.CommPointTypes.DelayPoint || CommPointType == CommPointDatcomInfo.CommPointTypes.Arrival_Delay);
        //}

        //public void DynamicPropertyCallForwardPoint(PropertyAttributes attributes)
        //{
        //    attributes.IsBrowsable = CommPointType == CommPointDatcomInfo.CommPointTypes.CallForwardPoint;   //.CallForwardPoint;
        //}

        public void DynamicPropertyArrivalPoint(PropertyAttributes attributes)
        {
            attributes.IsBrowsable = CommPointType == CommPointDatcomInfo.CommPointTypes.Arrival_Point;
        }
Exemplo n.º 43
0
 public PropertyDefinition(string name, PropertyAttributes attributes, TypeReference propertyType)
     : base(name, propertyType)
 {
     this.attributes = (ushort)attributes;
     this.token      = new MetadataToken(TokenType.Property);
 }
Exemplo n.º 44
0
 public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
 {
     throw new PlatformNotSupportedException();
 }
Exemplo n.º 45
0
        private PEPropertySymbol(
            PEModuleSymbol moduleSymbol,
            PENamedTypeSymbol containingType,
            PropertyDefinitionHandle handle,
            PEMethodSymbol getMethod,
            PEMethodSymbol setMethod,
            int countOfCustomModifiers,
            ParamInfo <TypeSymbol>[] propertyParams,
            MetadataDecoder metadataDecoder)
        {
            _containingType = containingType;
            var module = moduleSymbol.Module;
            PropertyAttributes      mdFlags = 0;
            BadImageFormatException mrEx    = null;

            try
            {
                module.GetPropertyDefPropsOrThrow(handle, out _name, out mdFlags);
            }
            catch (BadImageFormatException e)
            {
                mrEx = e;

                if ((object)_name == null)
                {
                    _name = string.Empty;
                }
            }

            _getMethod = getMethod;
            _setMethod = setMethod;
            _handle    = handle;

            SignatureHeader         unusedCallingConvention;
            BadImageFormatException getEx = null;
            var getMethodParams           = (object)getMethod == null ? null : metadataDecoder.GetSignatureForMethod(getMethod.Handle, out unusedCallingConvention, out getEx);
            BadImageFormatException setEx = null;
            var setMethodParams           = (object)setMethod == null ? null : metadataDecoder.GetSignatureForMethod(setMethod.Handle, out unusedCallingConvention, out setEx);

            // NOTE: property parameter names are not recorded in metadata, so we have to
            // use the parameter names from one of the indexers
            // NB: prefer setter names to getter names if both are present.
            bool isBad;

            _parameters = setMethodParams is null
                ? GetParameters(moduleSymbol, this, propertyParams, getMethodParams, getMethod.IsMetadataVirtual(), out isBad)
                : GetParameters(moduleSymbol, this, propertyParams, setMethodParams, setMethod.IsMetadataVirtual(), out isBad);

            if (getEx != null || setEx != null || mrEx != null || isBad)
            {
                _lazyUseSiteDiagnostic = new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, this);
            }

            var returnInfo          = propertyParams[0];
            var typeCustomModifiers = CSharpCustomModifier.Convert(returnInfo.CustomModifiers);

            if (returnInfo.IsByRef)
            {
                if (moduleSymbol.Module.HasIsReadOnlyAttribute(handle))
                {
                    _refKind = RefKind.RefReadOnly;
                }
                else
                {
                    _refKind = RefKind.Ref;
                }
            }
            else
            {
                _refKind = RefKind.None;
            }

            // CONSIDER: Can we make parameter type computation lazy?
            TypeSymbol originalPropertyType = returnInfo.Type;

            originalPropertyType = DynamicTypeDecoder.TransformType(originalPropertyType, typeCustomModifiers.Length, handle, moduleSymbol, _refKind);

            // Dynamify object type if necessary
            originalPropertyType = originalPropertyType.AsDynamicIfNoPia(_containingType);

            // We start without annotation (they will be decoded below)
            var propertyType = TypeSymbolWithAnnotations.Create(nonNullTypesContext: this, originalPropertyType, isAnnotated: false, typeCustomModifiers);

            // Decode nullable before tuple types to avoid converting between
            // NamedTypeSymbol and TupleTypeSymbol unnecessarily.
            propertyType = NullableTypeDecoder.TransformType(propertyType, handle, moduleSymbol);
            propertyType = TupleTypeDecoder.DecodeTupleTypesIfApplicable(propertyType, handle, moduleSymbol);

            _propertyType = propertyType;

            // A property is bogus and must be accessed by calling its accessors directly if the
            // accessor signatures do not agree, both with each other and with the property,
            // or if it has parameters and is not an indexer or indexed property.
            bool callMethodsDirectly = !DoSignaturesMatch(module, metadataDecoder, propertyParams, _getMethod, getMethodParams, _setMethod, setMethodParams) ||
                                       MustCallMethodsDirectlyCore();

            if (!callMethodsDirectly)
            {
                if ((object)_getMethod != null)
                {
                    _getMethod.SetAssociatedProperty(this, MethodKind.PropertyGet);
                }

                if ((object)_setMethod != null)
                {
                    _setMethod.SetAssociatedProperty(this, MethodKind.PropertySet);
                }
            }

            if (callMethodsDirectly)
            {
                _flags |= Flags.CallMethodsDirectly;
            }

            if ((mdFlags & PropertyAttributes.SpecialName) != 0)
            {
                _flags |= Flags.IsSpecialName;
            }

            if ((mdFlags & PropertyAttributes.RTSpecialName) != 0)
            {
                _flags |= Flags.IsRuntimeSpecialName;
            }
        }
Exemplo n.º 46
0
 public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
 {
     return(DefineProperty(name, attributes, callingConvention, returnType, null, null, parameterTypes, null, null));
 }
Exemplo n.º 47
0
 /// <summary>
 /// Creates a new PropertyDescriptor instance with a getter function and, optionally, a
 /// setter function.
 /// </summary>
 /// <param name="getter"> The function to call to retrieve the property value. </param>
 /// <param name="setter"> The function to call to set the property value. </param>
 /// <param name="attributes"> The property attributes (whether the property is writable or
 /// not is implied by whether there is a setter function). </param>
 public PropertyDescriptor(FunctionInstance getter, FunctionInstance setter, PropertyAttributes attributes)
     : this(new PropertyAccessorValue(getter, setter), attributes)
 {
 }
Exemplo n.º 48
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.attributes = (int)flags;
 }
Exemplo n.º 49
0
 void Add(PropertyAttributes a)
 {
 }
Exemplo n.º 50
0
 //Used only for a controller ???
 public void DynamicPropertyRouteBlockedTimeout(PropertyAttributes attributes)
 {
     attributes.IsBrowsable = RouteBlockedBehaviour == RouteBlocked.Wait_Timeout && Controller != null;
 }
 // Token: 0x06004BB2 RID: 19378 RVA: 0x00112580 File Offset: 0x00110780
 internal PropertyBuilder(ModuleBuilder mod, string name, SignatureHelper sig, PropertyAttributes attr, Type returnType, PropertyToken prToken, TypeBuilder containingType)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (name.Length == 0)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
     }
     if (name[0] == '\0')
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), "name");
     }
     this.m_name           = name;
     this.m_moduleBuilder  = mod;
     this.m_signature      = sig;
     this.m_attributes     = attr;
     this.m_returnType     = returnType;
     this.m_prToken        = prToken;
     this.m_tkProperty     = prToken.Token;
     this.m_containingType = containingType;
 }
Exemplo n.º 52
0
        public static PropertyBuilder dynamicProperty(this TypeBuilder typeBuilder, string propertyName, Type propertyType, PropertyAttributes propertyAttributes)
        {
            var property = typeBuilder.DefineProperty(propertyName,
                                                      propertyAttributes,
                                                      propertyType,
                                                      new Type[] { propertyType });

            var field = typeBuilder.dynamicField_Private("_" + propertyName, propertyType);

            var currGetPropMthdBldr = typeBuilder.dynamicMethod("get_value", propertyType);

            currGetPropMthdBldr.il_get_field(field)
            .il_ret();

            var currSetPropMthdBldr = typeBuilder.dynamicMethod("set_value", null, propertyType);

            currSetPropMthdBldr.il_set_field(field)
            .il_ret();

            property.SetGetMethod(currGetPropMthdBldr);
            property.SetSetMethod(currSetPropMthdBldr);

            return(property);
        }
Exemplo n.º 53
0
 public static bool HasFlag(this PropertyDefinition propertyDefinition, PropertyAttributes attribute)
 => (propertyDefinition.Attributes & attribute) == attribute;
Exemplo n.º 54
0
 /// <summary>
 /// Adds a public property to <paramref name="typeBuilder"/> of name <paramref name="propertyName"/>
 /// </summary>
 /// <param name="typeBuilder"><seealso cref="TypeBuilder"/> that will have the new property</param>
 /// <param name="propertyName">Name of the property</param>
 /// <param name="type">Type of the property</param>
 /// <param name="propertyAttributes"><seealso cref="PropertyAttributes"/></param>
 /// <returns>The new PropertyBuilder object that encapsulates the property</returns>
 public static PropertyBuilder DefineProperty(this TypeBuilder typeBuilder, string propertyName, Type type, PropertyAttributes propertyAttributes)
 {
     return(typeBuilder.DefineProperty(propertyName, propertyAttributes, type, null));
 }
Exemplo n.º 55
0
 public void DynamicPropertyLocalControlStratergy(PropertyAttributes attributes)
 {
     attributes.IsBrowsable = ControlType == ControlTypes.Local;
 }
Exemplo n.º 56
0
 public void DynamicPropertyAssemblyPLCconfig(PropertyAttributes attributes)
 {
     attributes.IsBrowsable = Controller != null;
 }
Exemplo n.º 57
0
 /// <summary>
 /// Creates a new <see cref="ModelAttributes"/> for a property.
 /// </summary>
 /// <param name="propertyAttributes">The set of attributes for the property.</param>
 /// <param name="typeAttributes">
 /// The set of attributes for the property's <see cref="Type"/>. See <see cref="PropertyInfo.PropertyType"/>.
 /// </param>
 public ModelAttributes([NotNull] IEnumerable <object> propertyAttributes, [NotNull] IEnumerable <object> typeAttributes)
 {
     PropertyAttributes = propertyAttributes.ToArray();
     TypeAttributes     = typeAttributes.ToArray();
     Attributes         = PropertyAttributes.Concat(TypeAttributes).ToArray();
 }
Exemplo n.º 58
0
 public void DynamicPropertyShowDepth3(PropertyAttributes attributes)
 {
     attributes.IsBrowsable = DepthsInRack > 2;
 }
Exemplo n.º 59
0
 public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers,
                                       Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
 {
     return(DefinePropertyImpl(name, attributes, CallingConventions.Standard, true, returnType, parameterTypes,
                               PackedCustomModifiers.CreateFromExternal(returnTypeOptionalCustomModifiers, returnTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers, parameterTypeRequiredCustomModifiers, Util.NullSafeLength(parameterTypes))));
 }
Exemplo n.º 60
0
 public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
 {
     throw new PlatformNotSupportedException();
 }