private static IEnumerable<FieldInfo> GetAllFields(System.Type tp)
        {
            if (tp == null) yield break;

            foreach (var f in tp.GetFields(BindingFlags.Public | BindingFlags.Instance))
            {
                yield return f;
            }

            System.Type stopType = null;
            if (TypeUtil.IsType(tp, typeof(MonoBehaviour)))
                stopType = typeof(MonoBehaviour);
            else if (TypeUtil.IsType(tp, typeof(UnityEngine.Object)))
                stopType = tp.BaseType;
            else
                stopType = typeof(object);

            while (tp != null && tp != stopType)
            {
                foreach (var f in tp.GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
                {
                    yield return f;
                }
                tp = tp.BaseType;
            }
        }
예제 #2
0
파일: ValueWriter.cs 프로젝트: externl/ice
        private static void writeFields(string name, object obj, System.Type c, Dictionary<Ice.Object, object> objectTable,
                                        OutputBase output)
        {
            if(!c.Equals(typeof(object)))
            {
                //
                // Write the superclass first.
                //
                writeFields(name, obj, c.BaseType, objectTable, output);

                //
                // Write the declared fields of the given class.
                //
                FieldInfo[] fields =
                    c.GetFields(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);

                for(int i = 0; i < fields.Length; i++)
                {
                    string fieldName = (name != null ? name + '.' + fields[i].Name : fields[i].Name);

                    try
                    {
                        object val = fields[i].GetValue(obj);
                        writeValue(fieldName, val, objectTable, output);
                    }
                    catch(System.UnauthorizedAccessException)
                    {
                        Debug.Assert(false);
                    }
                }
            }
        }
예제 #3
0
 public static IEnumerable<DeclaredPersistentProperty> PersistentInfo(System.Type @class, IEnumerable<Property> properties, bool includeEmbedded)
 {
     // a persistent property can be anything including a noop "property" declared in the mapping
     // for query only. In this case I will apply some trick to get the MemberInfo.
     var candidateMembers =
         @class.GetFields(DefaultBindingFlags).Concat(@class.GetProperties(DefaultBindingFlags).Cast<MemberInfo>()).ToList();
     var candidateMembersNames = candidateMembers.Select(m => m.Name).ToList();
     foreach (var property in properties)
     {
         if(includeEmbedded && property.PropertyAccessorName=="embedded")
             yield return new DeclaredPersistentProperty(property, DeclaredPersistentProperty.NotAvailableMemberInfo);
         var exactMemberIdx = candidateMembersNames.IndexOf(property.Name);
         if (exactMemberIdx >= 0)
         {
             // No metter which is the accessor the audit-attribute should be in the property where available and not
             // to the member used to read-write the value. (This method work even for access="field").
             yield return new DeclaredPersistentProperty(property, candidateMembers[exactMemberIdx]);
         }
         else
         {
             // try to find the field using field-name-strategy
             //
             // This part will run for:
             // 1) query only property (access="none" or access="noop")
             // 2) a strange case where the element <property> is declared with a "field.xyz" but only a field is used in the class. (Only God may know way)
             var exactFieldIdx = GetMemberIdxByFieldNamingStrategies(candidateMembersNames, property);
             if (exactFieldIdx >= 0)
             {
                 yield return new DeclaredPersistentProperty(property, candidateMembers[exactFieldIdx]);
             }
         }
     }
 }
예제 #4
0
        internal static Array GetEnumValues(System.Type enumType)
        {
            //			if (!enumType.IsEnum())
            //				throw new ArgumentException("Not an enumeration type", "enumType");

            IList result = Platform.CreateArrayList();
            FieldInfo[] fields = enumType.GetFields(BindingFlags.Static | BindingFlags.Public);
            foreach (FieldInfo field in fields)
            {
                result.Add(field.GetValue(null));
            }
            object[] arr = new object[result.Count];
            result.CopyTo(arr, 0);
            return arr;
        }
        public static void CopyValuesFrom(this Component to, Component from, System.Type type)
        {
            if (type == typeof(UnityEngine.MonoBehaviour) || type == null)
                return;

            // Copied fields can be restricted with BindingFlags
            FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            foreach (FieldInfo field in fields)
            {
                field.SetValue(to, field.GetValue(from));
            }

            // Keep going untill we hit UnityEngine.MonoBehaviour type.
            CopyValuesFrom(to, from, type.BaseType);
        }
예제 #6
0
	/// <summary>
	/// Gets the value of an Enum, based on it's Description Attribute or named value
	/// </summary>
	/// <param name="value">The Enum type</param>
	/// <param name="description">The description or name of the element</param>
	/// <returns>The value, or the passed in description, if it was not found</returns>
	public static object GetEnumValue (System.Type value, string description)
	{
		FieldInfo [] fis = value.GetFields ();
		foreach (FieldInfo fi in fis) {
			DescriptionAttribute [] attributes =
				(DescriptionAttribute []) fi.GetCustomAttributes (typeof (DescriptionAttribute), false);
			if (attributes.Length > 0) {
				if (attributes [0].Description == description) {
					return fi.GetValue (fi.Name);
				}
			}
			if (fi.Name == description) {
				return fi.GetValue (fi.Name);
			}
		}
		return description;
	}
예제 #7
0
        protected override IList<Newtonsoft.Json.Serialization.JsonProperty> CreateProperties(System.Type type, MemberSerialization memberSerialization)
        {
            var props = type.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            List<Newtonsoft.Json.Serialization.JsonProperty> jsonProps = new List<Newtonsoft.Json.Serialization.JsonProperty>();

            foreach (var prop in props)
            {
                jsonProps.Add(base.CreateProperty(prop, memberSerialization));
            }

            foreach (var field in type.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance))
            {
                jsonProps.Add(base.CreateProperty(field, memberSerialization));
            }

            jsonProps.ForEach(p => { p.Writable = true; p.Readable = true; });
            return jsonProps;
        }
예제 #8
0
		internal static Array GetEnumValues(System.Type enumType)
		{
			if (!enumType.IsEnum)
				throw new ArgumentException("Not an enumeration type", "enumType");

#if NETCF_1_0 || NETCF_2_0 || SILVERLIGHT
            IList result = Platform.CreateArrayList();
			FieldInfo[] fields = enumType.GetFields(BindingFlags.Static | BindingFlags.Public);
			foreach (FieldInfo field in fields)
			{
				result.Add(field.GetValue(null));
			}
            object[] arr = new object[result.Count];
            result.CopyTo(arr, 0);
            return arr;
#else
			return Enum.GetValues(enumType);
#endif
		}
예제 #9
0
        internal static Array GetEnumValues(System.Type enumType)
        {
            //TODO: COMENTADO. SEGUN LAS REFERENCIAS DEL PROYECTO, TODOS LOS TIPOS
            //QUE INVOCAN A ESTE METODO SON SIEMPRE DE TIPO "ENUM"
            //if (!enumType.IsEnum)
            //    throw new ArgumentException("Not an enumeration type", "enumType");

            #if NETCF_1_0 || NETCF_2_0 || SILVERLIGHT
            IList result = Platform.CreateArrayList();
            FieldInfo[] fields = enumType.GetFields(BindingFlags.Static | BindingFlags.Public);
            foreach (FieldInfo field in fields)
            {
                result.Add(field.GetValue(null));
            }
            object[] arr = new object[result.Count];
            result.CopyTo(arr, 0);
            return arr;
            #else
            return Enum.GetValues(enumType);
            #endif
        }
예제 #10
0
        internal static Array GetEnumValues(System.Type enumType)
        {
            if (!IsEnumType(enumType))
                throw new ArgumentException("Not an enumeration type", "enumType");

#if NETCF_1_0 || NETCF_2_0 || SILVERLIGHT
            IList result = Platform.CreateArrayList();
            FieldInfo[] fields = enumType.GetFields(BindingFlags.Static | BindingFlags.Public);
            foreach (FieldInfo field in fields)
            {
                // Note: Argument to GetValue() ignored since the fields are static,
                //     but Silverlight for Windows Phone throws exception if we pass null
                result.Add(field.GetValue(enumType));
            }
            object[] arr = new object[result.Count];
            result.CopyTo(arr, 0);
            return arr;
#else
            return Enum.GetValues(enumType);
#endif
        }
 private void ShowFieldInfo(System.Type type, MonoImporter importer, List<string> names, List<UnityEngine.Object> objects, ref bool didModify)
 {
   if (!MonoScriptImporterInspector.IsTypeCompatible(type))
     return;
   this.ShowFieldInfo(type.BaseType, importer, names, objects, ref didModify);
   foreach (System.Reflection.FieldInfo field in type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
   {
     if (!field.IsPublic)
     {
       object[] customAttributes = field.GetCustomAttributes(typeof (SerializeField), true);
       if (customAttributes == null || customAttributes.Length == 0)
         continue;
     }
     if (field.FieldType.IsSubclassOf(typeof (UnityEngine.Object)) || field.FieldType == typeof (UnityEngine.Object))
     {
       UnityEngine.Object defaultReference = importer.GetDefaultReference(field.Name);
       UnityEngine.Object @object = EditorGUILayout.ObjectField(ObjectNames.NicifyVariableName(field.Name), defaultReference, field.FieldType, false, new GUILayoutOption[0]);
       names.Add(field.Name);
       objects.Add(@object);
       if (defaultReference != @object)
         didModify = true;
     }
   }
 }
예제 #12
0
		/// <summary>
		/// Converts the string representation of the name or numeric value of one or 
		/// more enumerated constants to an equivalent enumerated object.
		/// </summary>
		/// <param name="enumType">The type to convert to.</param>
		/// <param name="value">The enum string value.</param>
		/// <param name="ignoreCase">If <c>true</c>, ignore case; otherwise, regard case.</param>
		/// <returns>An object of type <paramref name="enumType" /> whose value is represented by <paramref name="value" />.</returns>
		private static object ParseEnum(System.Type enumType, string value, bool ignoreCase) 
		{
#if !NETCF
			return Enum.Parse(enumType, value, ignoreCase);
#else
			FieldInfo[] fields = enumType.GetFields(BindingFlags.Public | BindingFlags.Static);

			string[] names = value.Split(new char[] {','});
			for (int i = 0; i < names.Length; ++i) 
			{
				names[i] = names [i].Trim();
			}

			long retVal = 0;

			try 
			{
				// Attempt to convert to numeric type
				return Enum.ToObject(enumType, Convert.ChangeType(value, typeof(long), CultureInfo.InvariantCulture));
			} 
			catch {}

			foreach (string name in names) 
			{
				bool found = false;
				foreach(FieldInfo field in fields) 
				{
					if (String.Compare(name, field.Name, ignoreCase) == 0) 
					{
						retVal |= ((IConvertible) field.GetValue(null)).ToInt64(CultureInfo.InvariantCulture);
						found = true;
						break;
					}
				}
				if (!found) 
				{
					throw new ArgumentException("Failed to lookup member [" + name + "] from Enum type [" + enumType.Name + "]");
				}
			}
			return Enum.ToObject(enumType, retVal);
#endif
		}		
		public UserDefinedTypeImporter(System.Type realType)
		{
			RealType = realType;

			RealTypeName = UserDefinedTypeSupport.GetTypeName(realType);
			var fields = realType.GetFields();
			var properties = realType.GetProperties();
			FieldSetters = new System.Collections.Generic.Dictionary<string, SetterDelegate>(fields.Length + properties.Length + 1);
			FieldSetters["__Type"] = this.CheckType;
			foreach (var field in UserDefinedTypeSupport.GetFields(RealType))
			{
				FieldSetters[field.Name] = CreateFieldSetter(realType, field.Member);
			}
			foreach (var property in UserDefinedTypeSupport.GetProperties(RealType))
			{
				FieldSetters[property.Name] = CreatePropertySetter(realType, property.Member);
			}
		}
예제 #14
0
		/// <summary>
		/// Get all other fileds name other than the primary key.
		/// </summary>
		/// <param name="t"></param>
		/// <param name="primaryKey"></param>
		/// <returns></returns>
		public string[] _get_other_fields_name(System.Type t, string primaryKey)
		{
			FieldInfo[] fields = t.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
			string[] result = new string[fields.Length-1];
			int pos = 0;
			for (int i=0; i<fields.Length; i++)
			{
				if (fields[i].Name != primaryKey)
					result[pos++] = fields[i].Name;
			}

			Debug.Assert(pos == result.Length);

			return result;
		}
예제 #15
0
파일: ClassType.cs 프로젝트: nomit007/f4
        /// <summary>
        /// Map the Java members of the specified
        /// class to my slots for reflection.
        /// </summary>
        private void finishSlots(System.Type type, bool staticOnly)
        {
            // map the class's fields to my slots
              FieldInfo[] fields = type.GetFields();
              for (int i=0; i<fields.Length; i++)
            finishField(fields[i]);

              // map the class's methods to my slots
              MethodInfo[] methods = type.GetMethods();
              for (int i=0; i<methods.Length; i++)
            finishMethod(methods[i], staticOnly);
        }
예제 #16
0
 /// <summary> Gets the xml enum value from the associated attributed enum. </summary>
 public virtual string GetXmlEnumValue(System.Type enumType, object enumValue)
 {
     // Enumeration's members have a XmlEnumAttribute; its Name is the value to return
     System.Reflection.FieldInfo[] fields = enumType.GetFields();
     foreach( System.Reflection.FieldInfo field in fields )
     {
         if( field.Name == System.Enum.GetName(enumType, enumValue) )
         {
             System.Xml.Serialization.XmlEnumAttribute attribute =
                 System.Attribute.GetCustomAttribute( field, typeof(System.Xml.Serialization.XmlEnumAttribute), false ) as System.Xml.Serialization.XmlEnumAttribute;
             if( attribute != null )
                 return attribute.Name;
             else
                 throw new MappingException( string.Format( "{0} is missing XmlEnumAttribute on {1} value. Please, contact the NHibernate team to fix this issue.", enumType, enumValue ) );
         }
     }
     throw new MappingException( string.Format( "{0} doesn't contain the field {1}. Please, contact the NHibernate team to fix this issue.", enumType, enumValue ) );
 }
 private PathInfo[] GetSubPropertiesOnType(System.Type typeToGetPropertiesOn, string currentPath)
 {
     List<PathInfo> list = new List<PathInfo>();
     if ((typeToGetPropertiesOn != typeof(string)) && (!TypeProvider.IsAssignable(typeof(Delegate), typeToGetPropertiesOn) || this.boundType.IsSubclassOf(typeof(Delegate))))
     {
         currentPath = string.IsNullOrEmpty(currentPath) ? string.Empty : (currentPath + ".");
         ITypeProvider service = this.serviceProvider.GetService(typeof(ITypeProvider)) as ITypeProvider;
         foreach (PropertyInfo info in this.GetProperties(typeToGetPropertiesOn))
         {
             MethodInfo getMethod = info.GetGetMethod();
             System.Type memberType = BindHelpers.GetMemberType(info);
             if (memberType != null)
             {
                 if (service != null)
                 {
                     System.Type type = service.GetType(memberType.FullName, false);
                     memberType = (type != null) ? type : memberType;
                 }
                 if (((this.IsPropertyBrowsable(info) && (getMethod != null)) && (memberType != null)) && ((!IsTypePrimitive(memberType) || TypeProvider.IsAssignable(this.boundType, memberType)) && (!(this.boundType != typeof(object)) || !(memberType == typeof(object)))))
                 {
                     string name = info.Name;
                     name = currentPath + name + this.ConstructIndexString(getMethod);
                     list.Add(new PathInfo(name, info, memberType));
                     list.AddRange(this.GetArraySubProperties(memberType, name));
                 }
             }
         }
         foreach (FieldInfo info3 in typeToGetPropertiesOn.GetFields(BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance))
         {
             System.Type fromType = BindHelpers.GetMemberType(info3);
             if ((fromType != null) && !TypeProvider.IsAssignable(typeof(DependencyProperty), fromType))
             {
                 if (service != null)
                 {
                     System.Type type4 = service.GetType(fromType.FullName, false);
                     fromType = (type4 != null) ? type4 : fromType;
                 }
                 if (((this.IsPropertyBrowsable(info3) && (fromType != null)) && (!IsTypePrimitive(fromType) || TypeProvider.IsAssignable(this.boundType, fromType))) && ((!(this.boundType != typeof(object)) || !(fromType == typeof(object))) && (TypeProvider.IsAssignable(typeof(Delegate), this.boundType) || !TypeProvider.IsAssignable(typeof(Delegate), fromType))))
                 {
                     string path = currentPath + info3.Name;
                     list.Add(new PathInfo(path, info3, BindHelpers.GetMemberType(info3)));
                     list.AddRange(this.GetArraySubProperties(fromType, path));
                 }
             }
         }
         if (this.boundType.IsSubclassOf(typeof(Delegate)))
         {
             foreach (EventInfo info4 in typeToGetPropertiesOn.GetEvents(BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance))
             {
                 System.Type type5 = BindHelpers.GetMemberType(info4);
                 if (type5 != null)
                 {
                     if (service != null)
                     {
                         System.Type type6 = service.GetType(type5.FullName, false);
                         type5 = (type6 != null) ? type6 : type5;
                     }
                     if ((this.IsPropertyBrowsable(info4) && (type5 != null)) && TypeProvider.IsAssignable(this.boundType, type5))
                     {
                         list.Add(new PathInfo(currentPath + info4.Name, info4, type5));
                     }
                 }
             }
         }
     }
     return list.ToArray();
 }
예제 #18
0
        protected static string GetPropertyInfo(System.Type type)
        {
            string markdown = "";
            foreach(FieldInfo field in type.GetFields() )
            {
                TooltipAttribute attribute = (TooltipAttribute)Attribute.GetCustomAttribute(field, typeof(TooltipAttribute));
                if (attribute == null )
                {
                    continue;
                }

                // Change field name to how it's displayed in the inspector
                string propertyName = Regex.Replace(field.Name, "(\\B[A-Z])", " $1");
                if (propertyName.Length > 1)
                {
                    propertyName = propertyName.Substring(0,1).ToUpper() + propertyName.Substring(1);
                }
                else
                {
                    propertyName = propertyName.ToUpper();
                }

                markdown += propertyName + " | " + field.FieldType + " | " + attribute.tooltip + "\n";
            }

            if (markdown.Length > 0)
            {
                markdown = "\nProperty | Type | Description\n --- | --- | ---\n" + markdown + "\n";
            }

            return markdown;
        }
 private void ShowFieldInfo(System.Type type, MonoImporter importer, List<string> names, List<UnityEngine.Object> objects, ref bool didModify)
 {
     if (IsTypeCompatible(type))
     {
         this.ShowFieldInfo(type.BaseType, importer, names, objects, ref didModify);
         foreach (System.Reflection.FieldInfo info in type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
         {
             if (!info.IsPublic)
             {
                 object[] customAttributes = info.GetCustomAttributes(typeof(SerializeField), true);
                 if ((customAttributes == null) || (customAttributes.Length == 0))
                 {
                     continue;
                 }
             }
             if (info.FieldType.IsSubclassOf(typeof(UnityEngine.Object)) || (info.FieldType == typeof(UnityEngine.Object)))
             {
                 UnityEngine.Object defaultReference = importer.GetDefaultReference(info.Name);
                 UnityEngine.Object item = EditorGUILayout.ObjectField(ObjectNames.NicifyVariableName(info.Name), defaultReference, info.FieldType, false, new GUILayoutOption[0]);
                 names.Add(info.Name);
                 objects.Add(item);
                 if (defaultReference != item)
                 {
                     didModify = true;
                 }
             }
         }
     }
 }
예제 #20
0
 // TODO: Consider adding functionality to TypeExtensions to avoid this difference.
 private static Dictionary<object, string> GetNameMapping(System.Type enumType) =>
     enumType.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static)
         .ToDictionary(f => f.GetValue(null),
                       f => (f.GetCustomAttributes(typeof(OriginalNameAttribute), false)
                             .FirstOrDefault() as OriginalNameAttribute)
                             // If the attribute hasn't been applied, fall back to the name of the field.
                             ?.Name ?? f.Name);
예제 #21
0
 public static void DisposField(System.Type type, Dictionary<string, ClassMethodInfo> cmfDict) {
    FieldInfo[] array =  type.GetFields(BindingFlags.GetField | BindingFlags.SetField | BindingFlags.Instance | BindingFlags);
    foreach (FieldInfo info in array)
    {
        string key = type.Namespace + "." + type.Name + "." + info.Name;
        ClassMethodInfo cmf = !cmfDict.ContainsKey(key) ? new ClassMethodInfo() : cmfDict[key];
        cmf.fullName = key;
        cmf.className = type.Name;
        cmf.name = info.Name;
        cmf.returnName = info.FieldType.Name;
        cmf.isStatic = info.IsStatic;
        cmf.isCanRead = true;
        cmf.isCanWrite = true;
        cmf.isPf = true;
        cmfDict[key] = cmf;
    }
 }
예제 #22
0
        static void DisconectState( object obj,System.Type type,int stateID )
        {
            System.Reflection.FieldInfo[] fields = type.GetFields( System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public );

            foreach( System.Reflection.FieldInfo field in fields )
            {
                bool serializeField = false;

                if( field.IsPublic )
                {
                    serializeField = true;
                }
                else
                {
                    object[] attributes = field.GetCustomAttributes( typeof(SerializeField),false );
                    if( attributes!=null && attributes.Length>0 )
                    {
                        serializeField = true;
                    }
                }

                if( serializeField )
                {
                    DisconectStateObject( field.GetValue(obj),stateID );
                }
            }
        }
예제 #23
0
        public static compiled_type_node get_type_node(System.Type st)
		{
            //(ssyy) Обрабатываем параметры generic-типов
            //Сделаю потом, если это понадобится.
            //if (st.IsGenericParameter)
            //{
            //}
            //if (st.Name.EndsWith("&") == true)
            
            //(ssyy) Лучше так
			if (st.IsByRef)
			{
				//return get_type_node(st.Module.GetType(st.FullName.Substring(0,st.FullName.Length-1)));
                return get_type_node(st.GetElementType());
            }
			compiled_type_node ctn;//=compiled_types[st];
            if (compiled_types.TryGetValue(st, out ctn))
			{
                //ctn.reinit_scope();
                return ctn;
			}
			ctn=new compiled_type_node(st);
            
            //Если это не чистить, будет ошибка. Т.к. при следующей компиляции области видимости могут изменится.
            //Но если это чистить то тоже ошибка. нужна еще одна статическая таблица для стандартных типов
			compiled_types[st] = ctn;
			
            ctn.init_constructors();
            ctn.mark_if_delegate();
            ctn.mark_if_array();
            if (st.IsEnum)
            {
                internal_interface ii = SystemLibrary.SystemLibrary.integer_type.get_internal_interface(internal_interface_kind.ordinal_interface);
                ordinal_type_interface oti_old = (ordinal_type_interface)ii;
                enum_const_node lower_value = new enum_const_node(0, ctn, ctn.loc);
                enum_const_node upper_value = new enum_const_node(st.GetFields().Length-2, ctn, ctn.loc);
                ordinal_type_interface oti_new = new ordinal_type_interface(oti_old.inc_method, oti_old.dec_method,
                    oti_old.inc_value_method, oti_old.dec_value_method,
                    oti_old.lower_eq_method, oti_old.greater_eq_method, 
                    oti_old.lower_method, oti_old.greater_method,
                    lower_value, upper_value, oti_old.value_to_int, oti_old.ordinal_type_to_int);

                ctn.add_internal_interface(oti_new);
                SystemLibrary.SystemLibrary.make_binary_operator(compiler_string_consts.gr_name, ctn, SemanticTree.basic_function_type.enumgr, SystemLibrary.SystemLibrary.bool_type);
                SystemLibrary.SystemLibrary.make_binary_operator(compiler_string_consts.greq_name, ctn, SemanticTree.basic_function_type.enumgreq, SystemLibrary.SystemLibrary.bool_type);
                SystemLibrary.SystemLibrary.make_binary_operator(compiler_string_consts.sm_name, ctn, SemanticTree.basic_function_type.enumsm, SystemLibrary.SystemLibrary.bool_type);
                SystemLibrary.SystemLibrary.make_binary_operator(compiler_string_consts.smeq_name, ctn, SemanticTree.basic_function_type.enumsmeq, SystemLibrary.SystemLibrary.bool_type);
                InitEnumOperations(ctn);
            }
            //ctn.init_scope();
            //TODO: Тут надо подумать. Может как-то сделать по другому?
            if (!NetHelper.NetHelper.IsStandType(st))
			{
				SystemLibrary.SystemLibrary.init_reference_type(ctn);
			}
			return ctn;
		}
		protected bool MatchComponentPattern(System.Type subject)
		{
			const BindingFlags flattenHierarchyMembers =
				BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;

			if (declaredModel.IsEntity(subject))
			{
				return false;
			}
			var modelInspector = (IModelInspector) this;
			return !subject.IsEnum && (subject.Namespace == null || !subject.Namespace.StartsWith("System")) /* hack */
							&& !modelInspector.IsEntity(subject)
							&& !subject.GetProperties(flattenHierarchyMembers).Cast<MemberInfo>().Concat(
			       		subject.GetFields(flattenHierarchyMembers)).Any(m => modelInspector.IsPersistentId(m));
		}
예제 #25
0
파일: NLS.cs 프로젝트: sinsay/SSE
        /// <param name="clazz">
        /// </param>
        private static void Load(System.Type clazz)
        {
            System.Reflection.FieldInfo[] fieldArray = clazz.GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Static);

            bool isFieldAccessible = clazz.IsPublic;

            // build a map of field names to Field objects
            int len = fieldArray.Length;
            System.Collections.IDictionary fields = new System.Collections.Hashtable(len * 2);
            for (int i = 0; i < len; i++)
            {
                fields[fieldArray[i].Name] = fieldArray[i];
                LoadfieldValue(fieldArray[i], isFieldAccessible, clazz);
            }
        }
		protected bool MatchEntity(System.Type subject)
		{
			const BindingFlags flattenHierarchyMembers =
				BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
			if(declaredModel.Components.Contains(subject))
			{
				return false;
			}
			var modelInspector = (IModelInspector) this;
			return subject.IsClass &&
			       subject.GetProperties(flattenHierarchyMembers).Cast<MemberInfo>().Concat(subject.GetFields(flattenHierarchyMembers)).Any(m => modelInspector.IsPersistentId(m));
		}
 private static FieldInfo[] GetInstanceFields(System.Type type)
 {
     BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;
     if (!WsdlGenerator.s_marshalByRefType.IsAssignableFrom(type))
     {
         bindingAttr |= BindingFlags.NonPublic;
     }
     FieldInfo[] fields = type.GetFields(bindingAttr);
     int length = fields.Length;
     if (length == 0)
     {
         return emptyFieldSet;
     }
     for (int i = 0; i < fields.Length; i++)
     {
         if (fields[i].IsStatic)
         {
             length--;
             fields[i] = fields[length];
             fields[length] = null;
         }
     }
     if (length < fields.Length)
     {
         FieldInfo[] destinationArray = new FieldInfo[length];
         Array.Copy(fields, destinationArray, length);
         return destinationArray;
     }
     return fields;
 }
예제 #28
0
        internal void buildFieldList(DatabaseImpl db, System.Type cls, ArrayList list)
        {
            System.Type superclass = cls.BaseType;
            if (superclass != null && superclass != typeof(MarshalByRefObject))
            {
                buildFieldList(db, superclass, list);
            }
            System.Reflection.FieldInfo[] flds = cls.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly);
            bool isWrapper = typeof(PersistentWrapper).IsAssignableFrom(cls);
            bool hasTransparentAttribute = cls.GetCustomAttributes(typeof(TransparentPersistenceAttribute), true).Length != 0;

            for (int i = 0; i < flds.Length; i++)
            {
                FieldInfo f = flds[i];
                if (!f.IsNotSerialized && !f.IsStatic)
                {
                    FieldDescriptor fd = new FieldDescriptor();
                    fd.field = f;
                    fd.fieldName = f.Name;
                    fd.className = getTypeName(cls);
                    Type fieldType = f.FieldType;
                    FieldType type = getTypeCode(fieldType);
                    switch (type)
                    {
                        case FieldType.tpInt:
                            if (isWrapper && isObjectProperty(cls, f))
                            {
                                hasReferences = true;
                                type = FieldType.tpOid;
                            }
                            break;
                        case FieldType.tpArrayOfOid:
                            fd.constructor = GetConstructor(f, "ConstructArray");
                            hasReferences = true;
                            break;
                        case FieldType.tpLink:
                            fd.constructor = GetConstructor(f, "ConstructLink");
                            hasReferences = true;
                            break;

                        case FieldType.tpArrayOfObject:
                        case FieldType.tpObject:
                            hasReferences = true;
                            if (hasTransparentAttribute && isVolanteInternalType(fieldType))
                            {
                                fd.recursiveLoading = true;
                            }
                            break;
                        case FieldType.tpValue:
                            fd.valueDesc = db.getClassDescriptor(f.FieldType);
                            hasReferences |= fd.valueDesc.hasReferences;
                            break;
                        case FieldType.tpArrayOfValue:
                            fd.valueDesc = db.getClassDescriptor(f.FieldType.GetElementType());
                            hasReferences |= fd.valueDesc.hasReferences;
                            break;
                    }
                    fd.type = type;
                    list.Add(fd);
                }
            }
        }
예제 #29
0
파일: Enum(2).cs 프로젝트: phiree/dzdocs
        public static string[] GetNames(System.Type enumType)
        {
            if(enumType.BaseType==Type.GetType("System.Enum"))
            {
                //get the public static fields (members of the enum)
                System.Reflection.FieldInfo[] fi = enumType.GetFields(BindingFlags.Static | BindingFlags.Public);

                //create a new enum array
                string[] names = new string[fi.Length];

                //populate with the values
                for(int iEnum = 0; iEnum < fi.Length; iEnum++)
                {
                    names[iEnum] = fi[iEnum].Name;
                }

                //return the array
                return names;
            }
            else
            {
                //the type supplied does not derive from enum
                throw new ArgumentException("enumType parameter is not an System.Enum");
            }
        }
예제 #30
0
파일: Emitter.cs 프로젝트: Ancestry/DotQL
        private TupleType TupleTypeFromNative(System.Type type)
        {
            var tupleType = new TupleType();

            // Get attributes
            foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.Instance))
                tupleType.Attributes.Add(Name.FromNative(field.Name), TypeFromNative(field.FieldType));

            // Get references
            foreach (TupleReferenceAttribute r in type.GetCustomAttributes(typeof(TupleReferenceAttribute)))
                tupleType.References.Add
                (
                    Name.FromNative(r.Name),
                    new TupleReference
                    {
                        SourceAttributeNames = (from san in r.SourceAttributeNames select Name.FromNative(san)).ToArray(),
                        Target = Name.FromNative(r.Target),
                        TargetAttributeNames = (from tan in r.TargetAttributeNames select Name.FromNative(tan)).ToArray()
                    }
                );

            // Get keys
            foreach (TupleKeyAttribute k in type.GetCustomAttributes(typeof(TupleKeyAttribute)))
                tupleType.Keys.Add
                (
                    new TupleKey { AttributeNames = (from n in k.AttributeNames select Name.FromNative(n)).ToArray() }
                );

            return tupleType;
        }