Inheritance: System.Reflection.ICustomAttributeProvider
		public static object [] GetObjectData (object obj, MemberInfo [] members)
		{
			if (obj == null)
				throw new ArgumentNullException ("obj");

			if (members == null)
				throw new ArgumentNullException ("members");

			int n = members.Length;
			object [] result = new object [n];
			for (int i = 0; i < n; i++) {
				MemberInfo member = members [i];
				if (member == null)
					throw new ArgumentNullException (String.Format ("members[{0}]", i));

				if (member.MemberType != MemberTypes.Field)
					throw new SerializationException (
							String.Format ("members [{0}] is not a field.", i));

				FieldInfo fi = member as FieldInfo; // members must be fields
				result [i] = fi.GetValue (obj);
			}

			return result;
		}
        public string GetMemberModifiers(MemberInfo memberInfo)
        {
            ArgumentUtility.CheckNotNull ("memberInfo", memberInfo);

              switch (memberInfo.MemberType)
              {
            case MemberTypes.Method:
            case MemberTypes.Constructor:
              return GetMethodModifiers (memberInfo, memberInfo);
            case MemberTypes.Field:
              return GetFieldModifiers ((FieldInfo)memberInfo);

            case MemberTypes.Property:
              var propertyInfo = (PropertyInfo) memberInfo;
              return GetMethodModifiers (propertyInfo.GetGetMethod (true) ?? propertyInfo.GetSetMethod (true), memberInfo);

            case MemberTypes.Event:
              var eventInfo = (EventInfo) memberInfo;
              return GetMethodModifiers (eventInfo.GetAddMethod (true), memberInfo);

            case MemberTypes.NestedType:
              return _typeModifierUtility.GetTypeModifiers ((Type) memberInfo);

            case MemberTypes.Custom:
            case MemberTypes.TypeInfo:
              return "TODO special MemberTypes";

            default:
              throw new Exception ("unknown member type");
              }
        }
Example #3
0
        public static bool IsSerializableMember(MemberInfo member)
        {
            if (member.MemberType == MemberTypes.Method)
                return false;

            var field = member as FieldInfo;
            if (field != null)
            {
                if (IsSerializableFieldPredicate != null)
                    return IsSerializableFieldPredicate(field);

                return DefaultIsSerializableField(field);
            }

            var property = member as PropertyInfo;
            if (property != null)
            {
                if (IsSerializablePropertyPredicate != null)
                    return IsSerializablePropertyPredicate(property);

                return DefaultIsSerializableProperty(property);
            }

            return false;
        }
        public MemberMetadata(MemberInfo memberInfo)
        {
            _type = MemberType.None;
            _memberType = null;
            _mi = null;
            _fp = null;

            memberInfo.ThrowIfNull("memberInfo", "Parameter cannot be null.");
            switch (memberInfo.MemberType)
            {
                case MemberTypes.Field:
                    _type = MemberType.Field;
                    _mi = memberInfo;
                    _memberType = (memberInfo as FieldInfo).FieldType;
                    break;
                case MemberTypes.Property:
                    _type = MemberType.Property;
                    _memberType = (memberInfo as PropertyInfo).PropertyType;
                    _fp = new FastReflection.FastProperty((memberInfo as PropertyInfo), true);
                    _mi = memberInfo;
                    break;
                default:
                    break;
            }
        }
		private static void UpdateDefaultValue(MemberInfo memberInfo, MetaProperty info)
		{
			var defaultAttribute = memberInfo.GetCustomAttribute<DefaultValueAttribute>();
			if (defaultAttribute == null) return;

			info.DefaultValue = defaultAttribute.Value;
		}
Example #6
0
        internal MemberListBinding(MemberInfo member, ReadOnlyCollection<ElementInit> initializers)
#pragma warning disable 618
            : base(MemberBindingType.ListBinding, member)
        {
#pragma warning restore 618
            Initializers = initializers;
        }
        private object GetProviderObjectFromMember(MemberInfo member)
        {
            object providerObject = null;
            object instance = null;

            switch (member.MemberType)
            {
                case MemberTypes.Property:
                    PropertyInfo providerProperty = member as PropertyInfo;
                    MethodInfo getMethod = providerProperty.GetGetMethod(true);
                    if (!getMethod.IsStatic)
                        //instance = ProviderCache.GetInstanceOf(providerType);
                        instance = Reflect.Construct(providerType, providerArgs);
                    providerObject = providerProperty.GetValue(instance, null);
                    break;

                case MemberTypes.Method:
                    MethodInfo providerMethod = member as MethodInfo;
                    if (!providerMethod.IsStatic)
                        //instance = ProviderCache.GetInstanceOf(providerType);
                        instance = Reflect.Construct(providerType, providerArgs);
                    providerObject = providerMethod.Invoke(instance, null);
                    break;

                case MemberTypes.Field:
                    FieldInfo providerField = member as FieldInfo;
                    if (!providerField.IsStatic)
                        //instance = ProviderCache.GetInstanceOf(providerType);
                        instance = Reflect.Construct(providerType, providerArgs);
                    providerObject = providerField.GetValue(instance);
                    break;
            }

            return providerObject;
        }
 public SourceInfo(string source, string arg, MemberInfo memberInfo, Type type, CodeGenerator ilg) {
     this.Source = source;
     this.Arg = arg ?? source;
     this.MemberInfo = memberInfo;
     this.Type = type;
     this.ILG = ilg;
 }
        protected virtual bool CanBeRouteParameter(MemberInfo info)
        {
            return (info.MemberType == MemberTypes.Field || info.MemberType == MemberTypes.Property)
                   && !info.HasCustomAttribute<ExcludeFromRouteAttribute>()
                   && IsValidForRoute(info.GetMemberType());

        }
 public PersistAggregationInfo(object aggregatedObject,string[] keyMapping,MemberInfo mi)
 {
     p_aggregatedObject=aggregatedObject;
     p_mi=mi;
     foreach(string mapping in keyMapping)
         p_alKeyMapping.Add(new KeyMappingInfo(mapping));
 }
Example #11
0
 public ComputedIndex(DocumentMapping mapping, MemberInfo[] members)
 {
     _members = members;
     var field = mapping.FieldFor(members);
     _locator = field.SqlLocator.Replace("d.", "");
     _table = mapping.Table;
 }
		protected ISqlExpression[] ConvertArgs(MemberInfo member, ISqlExpression[] args)
		{
			if (member is MethodInfo)
			{
				var method = (MethodInfo)member;

				if (method.DeclaringType.IsGenericType)
					args = args.Concat(method.DeclaringType.GetGenericArguments().Select(t => (ISqlExpression)SqlDataType.GetDataType(t))).ToArray();

				if (method.IsGenericMethod)
					args = args.Concat(method.GetGenericArguments().Select(t => (ISqlExpression)SqlDataType.GetDataType(t))).ToArray();
			}

			if (ArgIndices != null)
			{
				var idxs = new ISqlExpression[ArgIndices.Length];

				for (var i = 0; i < ArgIndices.Length; i++)
					idxs[i] = args[ArgIndices[i]];

				return idxs;
			}

			return args;
		}
        public static PropertyMap GetPropertyMap(this IMappingEngine mappingEngine, MemberInfo sourceMemberInfo, Type destinationMemberType)
        {
            var typeMap = mappingEngine.ConfigurationProvider.FindTypeMapFor(sourceMemberInfo.DeclaringType, destinationMemberType);

            if (typeMap == null)
            {
                const string MessageFormat = "Missing map from {0} to {1}. " +
                                             "Create using Mapper.CreateMap<{0}, {1}>.";
                var message = string.Format(MessageFormat, sourceMemberInfo.DeclaringType.Name, destinationMemberType.Name);
                throw new InvalidOperationException(message);
            }

            var propertyMap = typeMap.GetPropertyMaps()
                .FirstOrDefault(pm => pm.CanResolveValue() &&
                                      pm.SourceMember != null && pm.SourceMember.Name == sourceMemberInfo.Name);

            if (propertyMap == null)
            {
                const string MessageFormat = "Missing property map from {0} to {1} for {2} property. " +
                                             "Create using Mapper.CreateMap<{0}, {1}>.";
                var message = string.Format(MessageFormat, sourceMemberInfo.DeclaringType.Name, destinationMemberType.Name,
                    sourceMemberInfo.Name);
                throw new InvalidOperationException(message);
            }
            return propertyMap;
        }
Example #14
0
 public string AssignmentBodyCode(MemberInfo idMember)
 {
     return $@"
     document.{idMember.Name} = ""newId""; //your id generation algorithm here
     assigned = true;
     ";
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="MonoMobile.Views.BindingExpression"/> class.
        /// </summary>
        /// <param name='binding'>
        /// Binding.
        /// </param>
        /// <param name='targetProperty'>
        /// ViewModel.<targetProperty>.
        /// </param>
        /// <param name='target'>
        /// ViewModel to hock into.
        /// </param>
        /// <exception cref='ArgumentNullException'>
        /// Is thrown when an argument passed to a method is invalid because it is <see langword="null" /> .
        /// </exception>
        public BindingExpression(Binding binding, MemberInfo targetProperty, object target)
        {
            if (binding == null)
                throw new ArgumentNullException("binding");

            if (targetProperty == null)
                throw new ArgumentNullException("targetProperty");

            if (target == null)
                throw new ArgumentNullException("target");

            Binding = binding;
            Binding.Target = target;
            TargetProperty = targetProperty;
            if(string.IsNullOrEmpty(binding.TargetPath))
            {
                binding.TargetPath = targetProperty.Name;
            }

            object viewSource = Binding.Source;
            _ViewProperty = viewSource.GetType().GetNestedMember(ref viewSource, Binding.SourcePath, true);
            Binding.ViewSource = viewSource;
            SourceProperty = _ViewProperty;

            var dataContext = viewSource as IDataContext;
            if (dataContext != null && dataContext.DataContext != null)
            {
                var source = dataContext.DataContext;

                SourceProperty = source.GetType().GetNestedMember(ref source, Binding.SourcePath, true);
                Binding.Source = source;
            }
        }
        bool IsEncryptedMember(MemberInfo arg)
        {
            var propertyInfo = arg as PropertyInfo;
            if (propertyInfo != null)
            {
                if (propertyInfo.GetIndexParameters().Length > 0)
                {
                    if (conventions.IsEncryptedProperty(propertyInfo))
                    {
                        throw new Exception("Cannot encrypt or decrypt indexed properties that return a WireEncryptedString.");
                    }

                    return false;
                }

                return conventions.IsEncryptedProperty(propertyInfo);
            }

            var fieldInfo = arg as FieldInfo;
            if (fieldInfo != null)
            {
                return fieldInfo.FieldType == typeof(WireEncryptedString);
            }

            return false;
        }
        /// <summary>
        /// This method supports the Fluorine infrastructure and is not intended to be used directly from your code.
        /// </summary>
        /// <param name="invocationManager"></param>
        /// <param name="memberInfo"></param>
        /// <param name="obj"></param>
        /// <param name="arguments"></param>
        /// <param name="result"></param>
        public void HandleResult(IInvocationManager invocationManager, MemberInfo memberInfo, object obj, object[] arguments, object result)
		{
			if( result is DataSet )
			{
				DataSet dataSet = result as DataSet;
				ASObject asoResult = new ASObject(_remoteClass);

#if !(NET_1_1)
                foreach (KeyValuePair<object, object> entry in invocationManager.Properties)
#else
				foreach(DictionaryEntry entry in invocationManager.Properties)
#endif
				{
					if( entry.Key is DataTable )
					{
						DataTable dataTable = entry.Key as DataTable;
						if( dataSet.Tables.IndexOf(dataTable) != -1 )
						{
							if( !dataTable.ExtendedProperties.ContainsKey("alias") )
								asoResult[dataTable.TableName] = entry.Value;
							else
								asoResult[ dataTable.ExtendedProperties["alias"] as string ] = entry.Value;
						}
					}
				}
				invocationManager.Result = asoResult;
			}
		}
        /// <summary>
        /// Returns the attributes on <paramref name="member"/> that this convention applies to.
        /// </summary>
        /// <param name="member"></param>
        /// <returns></returns>
        public Attribute[] GetAttributes(MemberInfo member)
        {
            if (member == null)
            {
                throw Error.ArgumentNull("member");
            }

            Attribute[] attributes =
                member
                .GetCustomAttributes(inherit: true)
                .OfType<Attribute>()
                .Where(AttributeFilter)
                .ToArray();

            if (!AllowMultiple && attributes.Length > 1)
            {
                throw Error.InvalidOperation(
                    SRResources.MultipleAttributesFound,
                    member.Name,
                    member.ReflectedType.Name,
                    attributes.First().GetType().Name);
            }

            return attributes;
        }
Example #19
0
 public MapCallInfo(Type targetType, Type[] genericTypes, Flags bindingFlags, MemberTypes memberTypes, string name, Type[] parameterTypes, MemberInfo memberInfo, bool isReadOperation, Type sourceType, MemberTypes sourceMemberTypes, MemberTypes targetMemberTypes, string[] names) : base(targetType, genericTypes, bindingFlags, memberTypes, name, parameterTypes, memberInfo, isReadOperation)
 {
     SourceType = sourceType;
     SourceMemberTypes = sourceMemberTypes;
     TargetMemberTypes = targetMemberTypes;
     Names = names;
 }
 public ArrayArgumentHandler(Object aObj, MemberInfo aInfo, Type aType, int aMin, int aMax)
     : base(aObj, aInfo, aType, aMin, aMax)
 {
     elementType = type.GetElementType();
       listType = typeof(List<>).MakeGenericType(new Type[] { elementType });
       list = listType.GetConstructor(new Type[] { }).Invoke(null);
 }
	public ComponentAsIdMapper(System.Type componentType, MemberInfo declaringTypeMember, HbmCompositeId id, HbmMapping mapDoc)
	{
		this.id = id;
		this.mapDoc = mapDoc;
		id.@class = componentType.GetShortClassName(mapDoc);
		accessorPropertyMapper = new AccessorPropertyMapper(declaringTypeMember.DeclaringType, declaringTypeMember.Name, x => id.access = x);
	}
Example #22
0
        public TestRunState RunMember(ITestListener testListener, Assembly assembly, MemberInfo member)
        {
            var method = member as MethodInfo;
            if (method != null)
            {
                if (method.IsDispose())
                {
                    var listener = new TestDrivenListener(testListener);
                    listener.CaseSkipped(new SkipResult(new Case(method), "Dispose() is not a test."));
                    return TestRunState.Success;
                }

                return Run(testListener, runner => runner.RunMethods(assembly, method));
            }

            var type = member as Type;
            if (type != null)
            {
                var types = GetTypeAndNestedTypes(type).ToArray();

                return Run(testListener, runner => runner.RunTypes(assembly, types));
            }

            return TestRunState.Error;
        }
Example #23
0
        internal static TypeAttributeMapping FromMember(TypeMapping declaringType, MemberInfo memberInfo)
        {
            string name = null;
            SqlType sqlType = GetSqlType(memberInfo);
            int size = -1;
            int scale = -1;
            bool nullable = true;

            object[] attrs = memberInfo.GetCustomAttributes(true);
            for (int i = 0; i < attrs.Length; i++) {
                object attr = attrs[i];

                if (attr is ColumnAttribute) {
                    ColumnAttribute columnAttr = (ColumnAttribute)attr;
                    name = columnAttr.ColumnName;
                    sqlType = columnAttr.SqlType;
                    size = columnAttr.Size;
                    scale = columnAttr.Scale;
                } else if (attr is NotNullAttribute) {
                    nullable = false;
                }
            }

            TType type = GetTType(sqlType, size, scale);

            return new TypeAttributeMapping(declaringType, name, type, nullable);
        }
Example #24
0
        public override string Serialize(MemberInfo storageType, object value,
            ISerializationOperator serializationOperator) {

            if (value == null) return "null";

            if (_serializer == null) {
                throw new InvalidOperationException("No protobuf-net serializer is loaded");
            }

            UnityObjectReferenceHack.ActiveOperator = serializationOperator;

            using (var stream = new MemoryStream()) {
                _serializer.Serialize(stream, value, new SerializationContext() {
                    Context = serializationOperator
                });

                UnityObjectReferenceHack.ActiveOperator = null;

#if !UNITY_EDITOR && UNITY_WINRT
                return Convert.ToBase64String(stream.ToArray(), 0, (int)stream.Length);
#else
                return Convert.ToBase64String(stream.GetBuffer(), 0, (int)stream.Length);
#endif
            }
        }
Example #25
0
 //.........................................................................
 public CLSMethod(string name, Type type, MemberInfo[] methods, bool isStatic)
 {
     InnerIsStatic = isStatic;
     InnerType = type;
     InnerMethInfos = methods;
     InnerName = name;
 }
 /// <summary>
 /// Gets the Id generator for an Id member.
 /// </summary>
 /// <param name="memberInfo">The member.</param>
 /// <returns>An Id generator.</returns>
 public virtual IIdGenerator GetIdGenerator(MemberInfo memberInfo)
 {
     if (memberInfo.DeclaringType.GetInterfaces().Any(intf => intf == typeof(IEntity)) &&
         (memberInfo.Name == "ID" || memberInfo.Name == "Id" || memberInfo.Name == "iD" ||
         memberInfo.Name == "id" || memberInfo.Name == "_id"))
     {
         switch (memberInfo.MemberType)
         {
             case MemberTypes.Property:
                 PropertyInfo propertyInfo = (PropertyInfo)memberInfo;
                 if (propertyInfo.PropertyType == typeof(Guid) ||
                     propertyInfo.PropertyType == typeof(Guid?))
                     return new GuidGenerator();
                 break;
             case MemberTypes.Field:
                 FieldInfo fieldInfo = (FieldInfo)memberInfo;
                 if (fieldInfo.FieldType == typeof(Guid) ||
                     fieldInfo.FieldType == typeof(Guid?))
                     return new GuidGenerator();
                 break;
             default:
                 break;
         }
     }
     return null;
 }
        public bool IsOverriddenMember(MemberInfo memberInfo)
        {
            ArgumentUtility.CheckNotNull ("memberInfo", memberInfo);

              var methodInfo = memberInfo as MethodInfo;
              if (methodInfo != null)
            return IsOverriddenMethod (methodInfo);

              var propertyInfo = memberInfo as PropertyInfo;
              if (propertyInfo != null)
              {
            return IsOverriddenMethod (propertyInfo.GetGetMethod (true))
               || IsOverriddenMethod (propertyInfo.GetSetMethod (true));
              }

              var eventInfo = memberInfo as EventInfo;
              if (eventInfo != null)
              {
            return IsOverriddenMethod (eventInfo.GetAddMethod (true))
               || IsOverriddenMethod (eventInfo.GetRaiseMethod (true))
               || IsOverriddenMethod (eventInfo.GetRemoveMethod (true));
              }

              return false;
        }
        protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) {
            JsonProperty property = base.CreateProperty(member, memberSerialization);

            Predicate<object> shouldSerialize = property.ShouldSerialize;
            property.ShouldSerialize = obj => (shouldSerialize == null || shouldSerialize(obj)) && !property.IsValueEmptyCollection(obj);
            return property;
        }
        /// <summary>
        /// Initializes a new instance of the MemberInfoData class 
        /// with the provided MemberInfo object's data.
        /// </summary>
        /// <param name="mi">The member info object.</param>
        public MemberInfoData(MemberInfo mi)
        {
            MemberInfo = mi;
            Name = mi.Name;

            if (mi is PropertyInfo)
            {
                IconName = "Property.png";
            }

            MethodInfo methodInfo = mi as MethodInfo;
            if (methodInfo != null)
            {
                IconName = methodInfo.IsStatic ? "Static.png" : "Method.png";
            }

            if (mi is EventInfo)
            {
                IconName = "Event.png";
            }

            FieldInfo field = mi as FieldInfo;
            if (field != null)
            {
                IconName = "Static.png";
            }
        }
Example #30
0
 private void IncludeTypes(MemberInfo memberInfo, RecursionLimiter limiter)
 {
     foreach (Attribute attr in memberInfo.GetCustomAttributes(typeof(SoapIncludeAttribute), false))
     {
         IncludeType(((SoapIncludeAttribute)attr).Type, limiter);
     }
 }