private void AddJavaModuleAttribute(ModuleBuilder mb)
		{
			Type typeofJavaModuleAttribute = JVM.LoadType(typeof(JavaModuleAttribute));
			PropertyInfo[] propInfos = new PropertyInfo[] {
				typeofJavaModuleAttribute.GetProperty("Jars")
			};
			object[] propValues = new object[] {
				jarList.ToArray()
			};
			if (nameMappings.Count > 0)
			{
				string[] list = new string[nameMappings.Count * 2];
				int i = 0;
				foreach (KeyValuePair<string, string> kv in nameMappings)
				{
					list[i++] = kv.Key;
					list[i++] = kv.Value;
				}
				CustomAttributeBuilder cab = new CustomAttributeBuilder(typeofJavaModuleAttribute.GetConstructor(new Type[] { JVM.Import(typeof(string[])) }), new object[] { list }, propInfos, propValues);
				mb.SetCustomAttribute(cab);
			}
			else
			{
				CustomAttributeBuilder cab = new CustomAttributeBuilder(typeofJavaModuleAttribute.GetConstructor(Type.EmptyTypes), new object[0], propInfos, propValues);
				mb.SetCustomAttribute(cab);
			}
		}
Exemple #2
0
			internal ParameterInfoImpl(PropertyInfo property, int parameter)
			{
				this.property = property;
				this.parameter = parameter;
			}
		public abstract PropertyInfo SelectProperty(BindingFlags bindingAttr, PropertyInfo[] match, Type returnType, Type[] indexes, ParameterModifier[] modifiers);
		internal GenericPropertyInfo(Type typeInstance, PropertyInfo property)
		{
			this.typeInstance = typeInstance;
			this.property = property;
		}
		internal PropertyInfoWithReflectedType(Type reflectedType, PropertyInfo property)
		{
			this.reflectedType = reflectedType;
			this.property = property;
		}
		public override PropertyInfo SelectProperty(BindingFlags bindingAttr, PropertyInfo[] match, Type returnType, Type[] indexes, ParameterModifier[] modifiers)
		{
			int matchCount = 0;
			foreach (PropertyInfo property in match)
			{
				if (indexes == null || MatchParameterTypes(property.GetIndexParameters(), indexes))
				{
					if (returnType != null)
					{
						if (property.PropertyType.IsPrimitive)
						{
							if (!IsAllowedPrimitiveConversion(returnType, property.PropertyType))
							{
								continue;
							}
						}
						else
						{
							if (!property.PropertyType.IsAssignableFrom(returnType))
							{
								continue;
							}
						}
					}
					match[matchCount++] = property;
				}
			}

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

			if (matchCount == 1)
			{
				return match[0];
			}

			PropertyInfo bestMatch = match[0];
			bool ambiguous = false;
			for (int i = 1; i < matchCount; i++)
			{
				int best = MatchTypes(bestMatch.PropertyType, match[i].PropertyType, returnType);
				if (best == 0 && indexes != null)
				{
					best = MatchSignatures(bestMatch.PropertySignature, match[i].PropertySignature, indexes);
				}
				if (best == 0)
				{
					int depth1 = GetInheritanceDepth(bestMatch.DeclaringType);
					int depth2 = GetInheritanceDepth(match[i].DeclaringType);
					if (bestMatch.Name == match[i].Name && depth1 != depth2)
					{
						if (depth1 > depth2)
						{
							best = 1;
						}
						else
						{
							best = 2;
						}
					}
					else
					{
						ambiguous = true;
					}
				}
				if (best == 2)
				{
					ambiguous = false;
					bestMatch = match[i];
				}
			}
			if (ambiguous)
			{
				throw new AmbiguousMatchException();
			}
			return bestMatch;
		}
Exemple #7
0
 void AddAttributes(PropertyInfo propertyDefinition, IUnresolvedEntity targetEntity)
 {
     AddCustomAttributes(propertyDefinition.CustomAttributes, targetEntity.Attributes);
 }
Exemple #8
0
        public IUnresolvedProperty ReadProperty(PropertyInfo property, IUnresolvedTypeDefinition parentType, EntityType propertyType = EntityType.Property)
        {
            if (property == null)
                throw new ArgumentNullException("property");
            if (parentType == null)
                throw new ArgumentNullException("parentType");

            var p = new DefaultUnresolvedProperty(parentType, property.Name);
            p.EntityType = propertyType;
            TranslateModifiers(property.GetMethod ?? property.SetMethod, p);
            if (property.GetMethod != null && property.SetMethod != null)
                p.Accessibility = MergePropertyAccessibility (GetAccessibility (property.GetMethod.Attributes), GetAccessibility (property.SetMethod.Attributes));
            p.ReturnType = ReadTypeReference(property.PropertyType, typeAttributes: property.CustomAttributes);

            p.Getter = ReadMethod(property.GetMethod, parentType, EntityType.Accessor, p);
            p.Setter = ReadMethod(property.SetMethod, parentType, EntityType.Accessor, p);

            foreach (var par in property.GetIndexParameters ()) {
                p.Parameters.Add(ReadParameter(par));
            }

            AddAttributes(property, p);

            var accessor = p.Getter ?? p.Setter;
            if (accessor != null && accessor.IsExplicitInterfaceImplementation) {
                p.Name = property.Name.Substring(property.Name.LastIndexOf('.') + 1);
                p.IsExplicitInterfaceImplementation = true;
                foreach (var mr in accessor.ExplicitInterfaceImplementations) {
                    p.ExplicitInterfaceImplementations.Add(new AccessorOwnerMemberReference(mr));
                }
            }

            FinishReadMember(p, property);
            return p;
        }
Exemple #9
0
 static void Process(PropertyInfo propInfo)
 {
     foreach (var attr in propInfo.__GetCustomAttributes (TypeManager.AttributeType, false))
         if (attr.AttributeType.FullName == "Mono.Embedding.ThunkAttribute")
             foreach (var method in propInfo.GetAccessors())
                 Process(method, method.ReturnType, attr);
 }
 string GetValueExpression(PropertyInfo p)
 {
     var type = p.PropertyType;
     if (type.IsGenericType && type.GetGenericArguments ().Any (t => targets.Contains (t)) || targets.Contains (type) && !type.IsEnum) {
         if (type.IsGenericType && type.GetGenericTypeDefinition () == univ.Import (typeof (IList<>)))
             return String.Format ("(from x in impl.{0} select Extensions.GetWrappedItem<{1}> (x)).ToList ()", p.Name, type.GetGenericArguments () [0].CSName ());
         else if (type.IsArray)
             return String.Format ("(from x in impl.{0} select Extensions.GetWrappedItem<{1}> (x)).ToArray ()", p.Name, type.CSName ().Substring (0, type.CSName ().LastIndexOf ('[')));
         else
             return "(" + type.CSFullName () + ") " + p.Name;
     }
     else
         return "impl." + p.Name;
 }
 string GetModifier(PropertyInfo p)
 {
     if (p.IsAbstract ())
         return "abstract ";
     if (p.IsOverride ())
         return "override ";
     if (p.GetGetMethod ().IsVirtual)
         return "virtual ";
     return null;
 }