System.Type.GetFields(System.Reflection.BindingFlags)

Here are the examples of the csharp api System.Type.GetFields(System.Reflection.BindingFlags) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1498 Examples 7

19 View Source File : DataConverter.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static T Convert<T>(System.Data.Common.DbDataReader reader, ref T obj)
		{
			try
			{
				var fields = typeof(T).GetFields(BindingFlags.Instance | BindingFlags.Public);
				foreach (var f in fields)
				{
					var col = reader.GetOrdinal(f.Name);
					if (col >= 0)
						f.SetValue(obj, ChangeType(reader.GetValue(col), f.FieldType));
				}
				var props = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public);
				foreach (var p in props)
				{
					var col = reader.GetOrdinal(p.Name);
					if (col >= 0)
						p.SetValue(obj, ChangeType(reader.GetValue(col), p.PropertyType), null);
				}
			}
			catch (Exception ex) { TraceLogger.Instance.WriteException(ex); throw; }
			return obj;
		}

19 View Source File : DefaultContractResolver.cs
License : MIT License
Project Creator : akaskela

private MemberInfo GetExtensionDataMemberForType(Type type)
        {
            IEnumerable<MemberInfo> members = GetClreplacedHierarchyForType(type).SelectMany(baseType =>
            {
                IList<MemberInfo> m = new List<MemberInfo>();
                m.AddRange(baseType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly));
                m.AddRange(baseType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly));

                return m;
            });

            MemberInfo extensionDataMember = members.LastOrDefault(m =>
            {
                MemberTypes memberType = m.MemberType();
                if (memberType != MemberTypes.Property && memberType != MemberTypes.Field)
                {
                    return false;
                }

                // last instance of attribute wins on type if there are multiple
                if (!m.IsDefined(typeof(JsonExtensionDataAttribute), false))
                {
                    return false;
                }

                if (!ReflectionUtils.CanReadMemberValue(m, true))
                {
                    throw new JsonException("Invalid extension data attribute on '{0}'. Member '{1}' must have a getter.".FormatWith(CultureInfo.InvariantCulture, GetClrTypeFullName(m.DeclaringType), m.Name));
                }

                Type t = ReflectionUtils.GetMemberUnderlyingType(m);

                Type dictionaryType;
                if (ReflectionUtils.ImplementsGenericDefinition(t, typeof(IDictionary<,>), out dictionaryType))
                {
                    Type keyType = dictionaryType.GetGenericArguments()[0];
                    Type valueType = dictionaryType.GetGenericArguments()[1];

                    if (keyType.IsreplacedignableFrom(typeof(string)) && valueType.IsreplacedignableFrom(typeof(JToken)))
                    {
                        return true;
                    }
                }

                throw new JsonException("Invalid extension data attribute on '{0}'. Member '{1}' type must implement IDictionary<string, JToken>.".FormatWith(CultureInfo.InvariantCulture, GetClrTypeFullName(m.DeclaringType), m.Name));
            });

            return extensionDataMember;
        }

19 View Source File : RoslynDTOWrapperBase.cs
License : GNU General Public License v3.0
Project Creator : Acumatica

protected static void InitializeSharedStaticData(object roslynDTO)
		{
			roslynDTO.ThrowOnNull(nameof(roslynDTO));

			if (Interlocked.CompareExchange(ref _areStaticMembersInitialized, value: INITIALIZED, comparand: NOT_INITIALIZED) == NOT_INITIALIZED)
			{
				RoslynDTOType = roslynDTO.GetType();
				var bindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;

				DtoFields = RoslynDTOType.GetFields(bindingFlags).ToDictionary(field => field.Name);
				DtoProperties = RoslynDTOType.GetProperties(bindingFlags).ToDictionary(property => property.Name);
			}
		}

19 View Source File : ConfigurationBase.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public void SetConfigurations(IDictionary<string, object> dic)
		{
			try
			{
				lock (_root)
				{
					FieldInfo[] fields = this.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public);
					foreach (var f in fields)
					{
						if (dic.ContainsKey(f.Name))
						{
							var val = DataConverter.ChangeType(dic[f.Name], f.FieldType);
							f.SetValue(this, val);
						}
					}
					PropertyInfo[] props = this.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
					foreach (var p in props)
					{
						if (dic.ContainsKey(p.Name))
						{
							var val = DataConverter.ChangeType(dic[p.Name], p.PropertyType);
							p.SetValue(this, val, null);
						}
					}
				}
			}
			catch (Exception ex) { TraceLogger.Instance.WriteException(ex); throw; }
		}

19 View Source File : ZSymbol.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu

private static void PickupConstantSymbols<T>(ref IDictionary<ZSymbol, string> symbols)
            where T : ZSymbol
		{
			Type type = typeof(T);

			FieldInfo[] fields = type.GetFields(BindingFlags.Static | BindingFlags.Public);

			Type codeType = type.GetNestedType("Code", BindingFlags.NonPublic);

			// Pickup constant symbols
			foreach (FieldInfo symbolField in fields.Where(f => typeof(ZSymbol).IsreplacedignableFrom(f.FieldType)))
			{
				FieldInfo symbolCodeField = codeType.GetField(symbolField.Name);
				if (symbolCodeField != null)
				{
					int symbolNumber = (int)symbolCodeField.GetValue(null);

				    var symbol = Activator.CreateInstance(
				        type,
				        BindingFlags.NonPublic | BindingFlags.Instance, 
				        null,
				        new object[] {symbolNumber},
				        null);
					symbolField.SetValue(null, symbol);
					symbols.Add((ZSymbol)symbol, symbolCodeField.Name);
				}
			}
		}

19 View Source File : SimpleAstNodeId.g.cs
License : MIT License
Project Creator : Actipro

public override String GetDescription(Int32 id) {
            FieldInfo[] fields = typeof(SimpleAstNodeId).GetFields((BindingFlags.Public | BindingFlags.Static));
            for (Int32 index = 0; (index < fields.Length); index = (index + 1)) {
                FieldInfo field = fields[index];
                if (id.Equals(field.GetValue(null))) {
                    Object[] customAttributes = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
                    if (((customAttributes != null) 
                                && (customAttributes.Length > 0))) {
                        return ((DescriptionAttribute)(customAttributes[0])).Description;
                    }
                    else {
                        return field.Name;
                    }
                }
            }
            return null;
        }

19 View Source File : DataConverter.cs
License : GNU General Public License v3.0
Project Creator : aiportal

private static void StructToValues(object obj, SetValueCallback setValue, bool hasField, bool hasInternal)
		{
			Debug.replacedert(obj != null);
			try
			{
				// properties
				{
					var flags = BindingFlags.Instance | BindingFlags.Public | (hasInternal ? BindingFlags.NonPublic : 0);
					var props = obj.GetType().GetProperties(flags);
					foreach (var p in props)
					{
						if (hasInternal)
						{
							var m = p.GetSetMethod(true);
							if (m.IsPrivate || m.IsFamily)
								continue;
						}
						if (p.CanRead)
						{
							setValue(p.Name, p.GetValue(obj, null));
						}
					}
				}
				// fields
				if (hasField)
				{
					var flags = BindingFlags.Instance | BindingFlags.Public | (hasInternal ? BindingFlags.NonPublic : 0);
					var flds = obj.GetType().GetFields(flags);
					foreach (var f in flds)
					{
						if (f.IsPrivate || f.IsFamily || f.IsInitOnly)
							continue;
						setValue(f.Name, f.GetValue(obj));
					}
				}
			}
			catch (Exception ex) { TraceLog.WriteException(ex); throw; }
		}

19 View Source File : TypeUtil.cs
License : MIT License
Project Creator : Abc-Arbitrage

public static bool GetIsUnmanagedSlow(Type type)
        {
#if NETCOREAPP
            return !(bool)typeof(RuntimeHelpers).GetMethod(nameof(RuntimeHelpers.IsReferenceOrContainsReferences), BindingFlags.Static | BindingFlags.Public)!
                                                .MakeGenericMethod(type)
                                                .Invoke(null, null)!;
#else
            if (type.IsPrimitive || type.IsPointer || type.IsEnum)
                return true;

            if (!type.IsValueType)
                return false;

            foreach (var field in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
            {
                if (!GetIsUnmanagedSlow(field.FieldType))
                    return false;
            }

            return true;
#endif
        }

19 View Source File : NodeDataCache.cs
License : MIT License
Project Creator : aksyr

public static List<FieldInfo> GetNodeFields(System.Type nodeType) {
            List<System.Reflection.FieldInfo> fieldInfo = new List<System.Reflection.FieldInfo>(nodeType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance));

            // GetFields doesnt return inherited private fields, so walk through base types and pick those up
            System.Type tempType = nodeType;
            while ((tempType = tempType.BaseType) != typeof(XNode.Node)) {
                fieldInfo.AddRange(tempType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance));
            }
            return fieldInfo;
        }

19 View Source File : LootSwap.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static List<(TreasureTableType tableType, FieldInfo field)> GetFields(Type type)
            {
                var fields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Static);

                var filtered = new List<(TreasureTableType tableType, FieldInfo field)>();

                foreach (var field in fields)
                {
                    var fieldName = field.FieldType.FullName;

                    if (!fieldName.Contains("ChanceTable"))
                        continue;

                    if (fieldName.Contains("System.Collections.Generic.List"))
                        continue;

                    if (fieldName.Contains("System.Int32"))
                        filtered.Add((TreasureTableType.ChanceInt, field));
                    else if (fieldName.Contains("SpellId"))
                        filtered.Add((TreasureTableType.ChanceSpell, field));
                    else if (fieldName.Contains("WeenieClreplacedName"))
                        filtered.Add((TreasureTableType.ChanceWcid, field));
                    else if (fieldName.Contains("Boolean"))
                        filtered.Add((TreasureTableType.ChanceBool, field));
                    else if (fieldName.Contains("TreasureItemType_Orig"))
                        filtered.Add((TreasureTableType.ChanceItemType, field));
                    else if (fieldName.Contains("TreasureHeritageGroup"))
                        filtered.Add((TreasureTableType.ChanceHeritage, field));
                    else if (fieldName.Contains("TreasureArmorType"))
                        filtered.Add((TreasureTableType.ChanceArmorType, field));
                    else if (fieldName.Contains("TreasureWeaponType"))
                        filtered.Add((TreasureTableType.ChanceWeaponType, field));
                }
                return filtered;
            }

19 View Source File : Serialization.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static object FromDictionary(Dictionary<string, object> dic, ref object obj)
		{
			System.Diagnostics.Debug.replacedert(obj != null);
			FieldInfo[] fields = obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public);
			foreach (var f in fields)
			{
				if (dic.ContainsKey(f.Name))
				{
					var val = DataConverter.ChangeType(dic[f.Name], f.FieldType);
					f.SetValue(obj, val);
				}
			}
			PropertyInfo[] props = obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
			foreach (var p in props)
			{
				if (dic.ContainsKey(p.Name))
				{
					var val = DataConverter.ChangeType(dic[p.Name], p.PropertyType);
					p.SetValue(obj, val, null);
				}
			}
			return obj;
		}

19 View Source File : DataConverter.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static string Serilize(object val)
		{
			string result = null;
			if (val != null)
			{
				Type type = val.GetType();
				if (type == typeof(string[]))
				{
					result = string.Join(",", val as string[]);
				}
				else
				{
					var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public);
					if (fields.Length > 0)
					{
						//Array.Sort(fields);
						string[] vals = Array.ConvertAll(fields,
							f => System.Convert.ToString(f.GetValue(val))
						);
						result = string.Join(":", vals);
					}
					else
					{
						result = val.ToString();
					}
				}
			}
			return result;
		}

19 View Source File : SimpleLexicalStateId.g.cs
License : MIT License
Project Creator : Actipro

public override String GetDescription(Int32 id) {
            FieldInfo[] fields = typeof(SimpleLexicalStateId).GetFields((BindingFlags.Public | BindingFlags.Static));
            for (Int32 index = 0; (index < fields.Length); index = (index + 1)) {
                FieldInfo field = fields[index];
                if (id.Equals(field.GetValue(null))) {
                    Object[] customAttributes = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
                    if (((customAttributes != null) 
                                && (customAttributes.Length > 0))) {
                        return ((DescriptionAttribute)(customAttributes[0])).Description;
                    }
                    else {
                        return field.Name;
                    }
                }
            }
            return null;
        }

19 View Source File : ConfigurationBase.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public void SetConfigurations(IDictionary<string, object> dic)
		{
			try
			{
				BindingFlags flag = BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | 
					BindingFlags.SetField | BindingFlags.SetProperty;
				lock (_root)
				{
					FieldInfo[] fields = this.GetType().GetFields(flag);
					foreach (var f in fields)
					{
						if (f.IsPrivate || f.IsInitOnly)
							continue;
						if (dic.ContainsKey(f.Name))
						{
							var val = DataConverter.ChangeType(dic[f.Name], f.FieldType);
							f.SetValue(this, val);
						}
					}
					PropertyInfo[] props = this.GetType().GetProperties(flag);
					foreach (var p in props)
					{
						if (dic.ContainsKey(p.Name))
						{
							var val = DataConverter.ChangeType(dic[p.Name], p.PropertyType);
							p.SetValue(this, val, null);
						}
					}
				}
			}
			catch (Exception ex) { TraceLogger.Instance.WriteException(ex); throw; }
		}

19 View Source File : EntityCache.cs
License : Apache License 2.0
Project Creator : aadreja

internal static T CloneObjectWithIL<T>(T enreplacedy)
        {
            Type mainType = typeof(T);

            if (!CachedCloneIL.TryGetValue(mainType, out Delegate cloneIL))
            {
                // Create ILGenerator
                DynamicMethod dymMethod = new DynamicMethod("DoClone", mainType, new Type[] { mainType }, true);
                ConstructorInfo cInfo = mainType.GetConstructor(new Type[] { });

                ILGenerator generator = dymMethod.GetILGenerator();

                LocalBuilder lbf = generator.DeclareLocal(mainType);
                //lbf.SetLocalSymInfo("_temp");

                generator.Emit(OpCodes.Newobj, cInfo); //create new instance of object
                generator.Emit(OpCodes.Stloc_0); //load in memory

                Type type = mainType;
                while (type != null && type != typeof(object))
                {
                    foreach (FieldInfo field in type.GetFields(BindingFlags.Instance
                        | BindingFlags.Public
                        | BindingFlags.NonPublic))
                    {
                        // Load the new object on the eval stack... (currently 1 item on eval stack)
                        generator.Emit(OpCodes.Ldloc_0);
                        // Load initial object (parameter)          (currently 2 items on eval stack)
                        generator.Emit(OpCodes.Ldarg_0);
                        // Replace value by field value             (still currently 2 items on eval stack)
                        generator.Emit(OpCodes.Ldfld, field);
                        // Store the value of the top on the eval stack into the object underneath that value on the value stack.
                        //  (0 items on eval stack)
                        generator.Emit(OpCodes.Stfld, field);
                    }
                    type = type.BaseType;
                }
                

                // Load new constructed obj on eval stack -> 1 item on stack
                generator.Emit(OpCodes.Ldloc_0);
                // Return constructed object.   --> 0 items on stack
                generator.Emit(OpCodes.Ret);

                cloneIL = dymMethod.CreateDelegate(typeof(Func<T, T>));
                CachedCloneIL.Add(mainType, cloneIL);
            }
            return ((Func<T, T>)cloneIL)(enreplacedy);
        }

19 View Source File : DataConverter.cs
License : GNU General Public License v3.0
Project Creator : aiportal

private static string StructToString(object obj)
		{
			Debug.replacedert(obj != null);
			Debug.replacedert(obj.GetType().IsValueType);

			var flds = obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (flds.Length > 0)
			{
				StringBuilder sb = new StringBuilder();
				foreach (var fld in flds)
				{
					sb.Append(ObjectToString(fld.GetValue(obj)));
					sb.Append(FieldSeparator);
				}
				return sb.ToString().TrimEnd(FieldSeparator);
			}
			else
			{
				return obj.ToString();
			}
		}

19 View Source File : SimpleTokenId.g.cs
License : MIT License
Project Creator : Actipro

public override String GetDescription(Int32 id) {
            FieldInfo[] fields = typeof(SimpleTokenId).GetFields((BindingFlags.Public | BindingFlags.Static));
            for (Int32 index = 0; (index < fields.Length); index = (index + 1)) {
                FieldInfo field = fields[index];
                if (id.Equals(field.GetValue(null))) {
                    Object[] customAttributes = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
                    if (((customAttributes != null) 
                                && (customAttributes.Length > 0))) {
                        return ((DescriptionAttribute)(customAttributes[0])).Description;
                    }
                    else {
                        return field.Name;
                    }
                }
            }
            return null;
        }

19 View Source File : AutowiredControllerActivator.cs
License : MIT License
Project Creator : aishang2015

private object CreateInstance(IServiceProvider serviceProvider, Type type, int deep = 1)
        {
            // 超过指定深度,返回null
            if (deep > MaxDeep)
            {
                return null;
            }

            var instance = serviceProvider.GetService(type);

            // 当实例可以从容器中获取时,继续在实例中寻找可以自动注入的对象
            if (instance != null)
            {
                // 在类型中查找
                var autowiredFields = instance.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance);

                // 循环创建实例
                foreach (var field in autowiredFields)
                {
                    var fieldInstance = CreateInstance(serviceProvider, field.FieldType, deep + 1);

                    // 如果实例可以获得,并且其包含自动装配特性,则将其放入字段中
                    if (fieldInstance != null &&
                        field.GetCustomAttribute<AutowiredAttribute>() != null)
                    {
                        field.SetValue(instance, fieldInstance);
                    }
                }
            }
            return instance;
        }

19 View Source File : TransformCopyTest.cs
License : MIT License
Project Creator : 39M

private void replacedertObjectsEqual(object a, object b) {
      if ((a == null) != (b == null)) {
        replacedert.Fail("One object was null an the other was not.");
        return;
      }

      Type typeA = a.GetType();
      Type typeB = b.GetType();

      if (typeA != typeB) {
        replacedert.Fail("Type " + typeA + " is not equal to type " + typeB + ".");
      }

      if (typeA.IsValueType) {
        replacedert.That(a, Is.EqualTo(b));
        return;
      }

      if (a is IList) {
        IList aList = a as IList;
        IList bList = b as IList;

        replacedert.That(aList.Count, Is.EqualTo(bList.Count));

        for (int i = 0; i < aList.Count; i++) {
          replacedertObjectsEqual(aList[i], bList[i]);
        }
      } else {
        FieldInfo[] fields = typeA.GetFields(BindingFlags.Public | BindingFlags.Instance);
        foreach (FieldInfo field in fields) {
          replacedertObjectsEqual(field.GetValue(a), field.GetValue(b));
        }

        PropertyInfo[] properties = typeA.GetProperties(BindingFlags.Public | BindingFlags.Instance);
        foreach (PropertyInfo property in properties) {
          if (property.GetIndexParameters().Length == 0) {
            object propA;
            try {
              propA = property.GetValue(a, null);
            } catch (Exception exceptionA) {
              try {
                property.GetValue(b, null);
                replacedert.Fail("One property threw an exception where the other did not.");
                return;
              } catch (Exception exceptionB) {
                replacedert.That(exceptionA.GetType(), Is.EqualTo(exceptionB.GetType()), "Both properties threw exceptions but their types were different.");
                return;
              }
            }

            object propB = property.GetValue(b, null);

            replacedertObjectsEqual(propA, propB);
          }
        }
      }
    }

19 View Source File : ReflectionUtils.cs
License : MIT License
Project Creator : akaskela

private static void GetChildPrivateFields(IList<MemberInfo> initialFields, Type targetType, BindingFlags bindingAttr)
        {
            // fix weirdness with private FieldInfos only being returned for the current Type
            // find base type fields and add them to result
            if ((bindingAttr & BindingFlags.NonPublic) != 0)
            {
                // modify flags to not search for public fields
                BindingFlags nonPublicBindingAttr = bindingAttr.RemoveFlag(BindingFlags.Public);

                while ((targetType = targetType.BaseType()) != null)
                {
                    // filter out protected fields
                    IEnumerable<MemberInfo> childPrivateFields =
                        targetType.GetFields(nonPublicBindingAttr).Where(f => f.IsPrivate).Cast<MemberInfo>();

                    initialFields.AddRange(childPrivateFields);
                }
            }
        }

19 View Source File : PhotonPlayerProperty.cs
License : GNU General Public License v3.0
Project Creator : aelariane

private static void InitAllProperties()
    {
        List<string> tmp = new List<string>();
        List<string> rcTemp = new List<string>();
        List<string> vanillaTemp = new List<string>();
        List<string> anarchyTemp = new List<string>();
        List<string> modTemp = new List<string>();
        FieldInfo[] infos = typeof(PhotonPlayerProperty).GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.GetField);
        foreach (FieldInfo info in infos)
        {
            if (info.IsStatic && info.FieldType == typeof(string))
            {
                string value = info.GetValue(null).ToString();
                if (value.Length > 0)
                {
                    tmp.Add(value);
                }
                var rcAtr = info.GetCustomAttributes(typeof(RCPropertyAttribute), false);
                var anarchyAtr = info.GetCustomAttributes(typeof(AnarchyPropertyAttribute), false);
                var modAttr = info.GetCustomAttributes(typeof(ModProperty), false);
                if(modAttr.Length > 0)
                {
                    modTemp.Add(value);
                }
                else if (rcAtr.Length > 0)
                {
                    rcTemp.Add(value);
                }
                else if(anarchyAtr.Length > 0)
                {
                    anarchyTemp.Add(value);
                }
                else
                {
                    vanillaTemp.Add(value);
                }
            }
        }
        allProperties = tmp.ToArray();
        rcProperties = rcTemp.ToArray();
        anarchyProperties = anarchyTemp.ToArray();
        vanillaProperties = vanillaTemp.ToArray();
        modProperties = modTemp.ToArray();
    }

19 View Source File : Platform.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu

private static void replacedignImplementations(Type platformDependant, string implementationName)
		{
			Type platformImplementation = platformDependant.GetNestedType(implementationName, bindings);
			// if (platformImplementation == null) return;

			FieldInfo[] fields = platformDependant.GetFields(bindings);
			foreach (FieldInfo field in fields)
			{
				Type fieldType = field.FieldType;
				string delegateName = fieldType.Name;
				MethodInfo methodInfo__internal = null;
				FieldInfo fieldInfo__internal = null;

				// TODO: This is mapping sodium.crypto_box to sodium.crypto_box__Internal. Should we also map them to sodium.__Internal.crypto_box?
				if (implementationName == "__Internal")
				{
					if (delegateName.EndsWith("_delegate"))
					{
						// YOU now have
						// public static readonly crypto_box_delegate box = crypto_box;

						// YOU need
						// public static readonly crypto_box_delegate box = crypto_box__Internal;

						delegateName = delegateName.Substring(0, delegateName.Length - "_delegate".Length);
						if (delegateName.Length > 0)
						{
							methodInfo__internal = platformDependant.GetMethod(delegateName + "__Internal", bindings);
						}
					}
				}
				if (methodInfo__internal == null && platformImplementation != null)
				{
					if (delegateName.EndsWith("Delegate"))
					{
						// YOU now have
						// public static readonly UnmanagedLibrary LoadUnmanagedLibraryDelegate;

						// YOU need
						// public static readonly LoadUnmanagedLibraryDelegate LoadUnmanagedLibrary 
						//     = Platform.__Internal.LoadUnmanagedLibrary;

						delegateName = delegateName.Substring(0, delegateName.Length - "Delegate".Length);

						methodInfo__internal = platformImplementation.GetMethod(delegateName, bindings);
					}
					else
					{
						methodInfo__internal = platformImplementation.GetMethod(field.Name, bindings);
					}

					if (methodInfo__internal == null)
					{
						fieldInfo__internal = platformImplementation.GetField(field.Name, bindings);
					}
				}

				if (methodInfo__internal != null)
				{
					var delegat = Delegate.CreateDelegate(fieldType, methodInfo__internal);
					field.SetValue(null, delegat);
				}
				else if (fieldInfo__internal != null)
				{
					object value = fieldInfo__internal.GetValue(null);
					field.SetValue(null, value);
				}
				// else { field.SetValue(null, null); }
			}
		}

19 View Source File : ObjectTypeUtil.cs
License : MIT License
Project Creator : 404Lcc

public static void Draw(object obj, int indentLevel)
        {
            EditorGUILayout.BeginVertical();
            EditorGUI.indentLevel = indentLevel;
            string replacedemblyName = string.Empty;
            switch (Path.GetFileNameWithoutExtension(obj.GetType().replacedembly.ManifestModule.Name))
            {
                case "Unity.Model":
                    replacedemblyName = "Unity.Model";
                    break;
                case "Unity.Hotfix":
                    replacedemblyName = "Unity.Hotfix";
                    break;
                case "ILRuntime":
                    replacedemblyName = "Unity.Hotfix";
                    break;
            }
            if (replacedemblyName == "Unity.Model")
            {
                FieldInfo[] fieldInfos = obj.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
                foreach (FieldInfo item in fieldInfos)
                {
                    object value = item.GetValue(obj);
                    Type type = item.FieldType;
                    if (item.IsDefined(typeof(HideInInspector), false))
                    {
                        continue;
                    }
                    if (type.IsDefined(typeof(HideInInspector), false))
                    {
                        continue;
                    }
                    if (objectObjectTypes.ContainsKey((obj, item)))
                    {
                        ObjectObjectType objectObjectType = (ObjectObjectType)objectObjectTypes[(obj, item)];
                        objectObjectType.Draw(type, item.Name, value, null, indentLevel);
                        continue;
                    }
                    if ((item.IsDefined(typeof(SerializeField), false) || type.IsDefined(typeof(SerializeField), false)) && type.replacedembly.ManifestModule.Name == "Unity.Model.dll")
                    {
                        ObjectObjectType objectObjectType = new ObjectObjectType();
                        if (value == null)
                        {
                            object instance = Activator.CreateInstance(type);
                            objectObjectType.Draw(type, item.Name, instance, null, indentLevel);
                            item.SetValue(obj, instance);
                        }
                        else
                        {
                            objectObjectType.Draw(type, item.Name, value, null, indentLevel);
                        }
                        objectObjectTypes.Add((obj, item), objectObjectType);
                        continue;
                    }
                    if (listObjectTypes.ContainsKey((obj, item)))
                    {
                        ListObjectType listObjectType = (ListObjectType)listObjectTypes[(obj, item)];
                        listObjectType.Draw(type, item.Name, value, null, indentLevel);
                        continue;
                    }
                    if (type.GetInterface("IList") != null)
                    {
                        ListObjectType listObjectType = new ListObjectType();
                        if (value == null)
                        {
                            continue;
                        }
                        listObjectType.Draw(type, item.Name, value, null, indentLevel);
                        listObjectTypes.Add((obj, item), listObjectType);
                        continue;
                    }
                    foreach (IObjectType objectTypeItem in objectList)
                    {
                        if (!objectTypeItem.IsType(type))
                        {
                            continue;
                        }
                        string fieldName = item.Name;
                        if (fieldName.Contains("clrInstance") || fieldName.Contains("Boxed"))
                        {
                            continue;
                        }
                        if (fieldName.Length > 17 && fieldName.Contains("k__BackingField"))
                        {
                            fieldName = fieldName.Substring(1, fieldName.Length - 17);
                        }
                        value = objectTypeItem.Draw(type, fieldName, value, null);
                        item.SetValue(obj, value);
                    }
                }
            }
            else
            {
#if ILRuntime
                FieldInfo[] fieldInfos = ILRuntimeManager.Instance.appdomain.LoadedTypes[obj.ToString()].ReflectionType.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
                foreach (FieldInfo item in fieldInfos)
                {
                    object value = item.GetValue(obj);
                    if (item.FieldType is ILRuntimeWrapperType)
                    {
                        //基础类型绘制
                        Type type = ((ILRuntimeWrapperType)item.FieldType).RealType;
                        if (item.IsDefined(typeof(HideInInspector), false))
                        {
                            continue;
                        }
                        if (type.IsDefined(typeof(HideInInspector), false))
                        {
                            continue;
                        }
                        if (listObjectTypes.ContainsKey((obj, item)))
                        {
                            ListObjectType listObjectType = (ListObjectType)listObjectTypes[(obj, item)];
                            listObjectType.Draw(type, item.Name, value, null, indentLevel);
                            continue;
                        }
                        if (type.GetInterface("IList") != null)
                        {
                            ListObjectType listObjectType = new ListObjectType();
                            if (value == null)
                            {
                                continue;
                            }
                            listObjectType.Draw(type, item.Name, value, null, indentLevel);
                            listObjectTypes.Add((obj, item), listObjectType);
                            continue;
                        }
                        foreach (IObjectType objectTypeItem in objectList)
                        {
                            if (!objectTypeItem.IsType(type))
                            {
                                continue;
                            }
                            string fieldName = item.Name;
                            if (fieldName.Contains("clrInstance") || fieldName.Contains("Boxed"))
                            {
                                continue;
                            }
                            if (fieldName.Length > 17 && fieldName.Contains("k__BackingField"))
                            {
                                fieldName = fieldName.Substring(1, fieldName.Length - 17);
                            }
                            value = objectTypeItem.Draw(type, fieldName, value, null);
                            item.SetValue(obj, value);
                        }
                    }
                    else
                    {
                        //自定义类型绘制
                        Type type = item.FieldType;
                        if (item.IsDefined(typeof(HideInInspector), false))
                        {
                            continue;
                        }
                        if (type.IsDefined(typeof(HideInInspector), false))
                        {
                            continue;
                        }
                        if (objectObjectTypes.ContainsKey((obj, item)))
                        {
                            ObjectObjectType objectObjectType = (ObjectObjectType)objectObjectTypes[(obj, item)];
                            objectObjectType.Draw(type, item.Name, value, null, indentLevel);
                            continue;
                        }
                        if ((item.IsDefined(typeof(SerializeField), false) || type.IsDefined(typeof(SerializeField), false)) && type.replacedembly.ManifestModule.Name == "ILRuntime.dll")
                        {
                            ObjectObjectType objectObjectType = new ObjectObjectType();
                            if (value == null)
                            {
                                object instance = ILRuntimeManager.Instance.appdomain.Instantiate(type.ToString());
                                objectObjectType.Draw(type, item.Name, instance, null, indentLevel);
                                item.SetValue(obj, instance);
                            }
                            else
                            {
                                objectObjectType.Draw(type, item.Name, value, null, indentLevel);
                            }
                            objectObjectTypes.Add((obj, item), objectObjectType);
                            continue;
                        }
                    }
                }
#else
                FieldInfo[] fieldInfos = obj.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
                foreach (FieldInfo item in fieldInfos)
                {
                    object value = item.GetValue(obj);
                    Type type = item.FieldType;
                    if (item.IsDefined(typeof(HideInInspector), false))
                    {
                        continue;
                    }
                    if (type.IsDefined(typeof(HideInInspector), false))
                    {
                        continue;
                    }
                    if (objectObjectTypes.ContainsKey((obj, item)))
                    {
                        ObjectObjectType objectObjectType = (ObjectObjectType)objectObjectTypes[(obj, item)];
                        objectObjectType.Draw(type, item.Name, value, null, indentLevel);
                        continue;
                    }
                    if ((item.IsDefined(typeof(SerializeField), false) || type.IsDefined(typeof(SerializeField), false)) && type.replacedembly.ManifestModule.Name == "Unity.Hotfix.dll")
                    {
                        ObjectObjectType objectObjectType = new ObjectObjectType();
                        if (value == null)
                        {
                            object instance = Activator.CreateInstance(type);
                            objectObjectType.Draw(type, item.Name, instance, null, indentLevel);
                            item.SetValue(obj, instance);
                        }
                        else
                        {
                            objectObjectType.Draw(type, item.Name, value, null, indentLevel);
                        }
                        objectObjectTypes.Add((obj, item), objectObjectType);
                        continue;
                    }
                    if (listObjectTypes.ContainsKey((obj, item)))
                    {
                        ListObjectType listObjectType = (ListObjectType)listObjectTypes[(obj, item)];
                        listObjectType.Draw(type, item.Name, value, null, indentLevel);
                        continue;
                    }
                    if (type.GetInterface("IList") != null)
                    {
                        ListObjectType listObjectType = new ListObjectType();
                        if (value == null)
                        {
                            continue;
                        }
                        listObjectType.Draw(type, item.Name, value, null, indentLevel);
                        listObjectTypes.Add((obj, item), listObjectType);
                        continue;
                    }
                    foreach (IObjectType objectTypeItem in objectList)
                    {
                        if (!objectTypeItem.IsType(type))
                        {
                            continue;
                        }
                        string fieldName = item.Name;
                        if (fieldName.Contains("clrInstance") || fieldName.Contains("Boxed"))
                        {
                            continue;
                        }
                        if (fieldName.Length > 17 && fieldName.Contains("k__BackingField"))
                        {
                            fieldName = fieldName.Substring(1, fieldName.Length - 17);
                        }
                        value = objectTypeItem.Draw(type, fieldName, value, null);
                        item.SetValue(obj, value);
                    }
                }
#endif
                EditorGUI.indentLevel = indentLevel;
                EditorGUILayout.EndVertical();
            }
        }

19 View Source File : ZeroDiscover.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu

private void ReadEnreplacedy(TypeDoreplacedent typeDoreplacedent, Type type)
        {
            if (type == null || type.IsAutoClreplaced || !IsLetter(type.Name[0]) ||
                type.IsInterface || type.IsMarshalByRef || type.IsCOMObject ||
                type == typeof(object) || type == typeof(void) ||
                type == typeof(ValueType) || type == typeof(Type) || type == typeof(Enum) ||
                type.Namespace == "System" || type.Namespace?.Contains("System.") == true)
                return;
            if (typeDocs.TryGetValue(type, out var doc))
            {
                foreach (var field in doc.Fields)
                {
                    if (typeDoreplacedent.Fields.ContainsKey(field.Key))
                        typeDoreplacedent.Fields[field.Key] = field.Value;
                    else
                        typeDoreplacedent.Fields.Add(field.Key, field.Value);
                }
                return;
            }
            if (typeDocs2.TryGetValue(type, out var _))
            {
                ZeroTrace.WriteError("ReadEnreplacedy", "over flow", type.Name);

                return;
            }

            typeDocs2.Add(type, typeDoreplacedent);
            if (type.IsArray)
            {
                ReadEnreplacedy(typeDoreplacedent, type.replacedembly.GetType(type.FullName.Split('[')[0]));
                return;
            }
            if (type.IsGenericType && !type.IsValueType &&
                type.GetGenericTypeDefinition().GetInterface(typeof(IEnumerable<>).FullName) != null)
            {
                ReadEnreplacedy(typeDoreplacedent, type.GetGenericArguments().Last());
                return;
            }

            XmlMember.Find(type);
            if (type.IsEnum)
            {
                foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags.Public))
                {
                    if (field.IsSpecialName)
                    {
                        continue;
                    }
                    var info = CheckMember(typeDoreplacedent, type, field, field.FieldType, false, false, false);
                    if (info != null)
                    {
                        info.TypeName = "int";
                        info.Example = ((int)field.GetValue(null)).ToString();
                        info.JsonName = null;
                    }
                }
                typeDocs.Add(type, new TypeDoreplacedent
                {
                    fields = typeDoreplacedent.fields?.ToDictionary(p => p.Key, p => p.Value)
                });
                typeDoreplacedent.Copy(XmlMember.Find(type));
                return;
            }

            var dc = type.GetAttribute<DataContractAttribute>();
            var jo = type.GetAttribute<JsonObjectAttribute>();

            foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                if (property.IsSpecialName)
                {
                    continue;
                }
                CheckMember(typeDoreplacedent, type, property, property.PropertyType, jo != null, dc != null);
            }
            foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                if (!char.IsLetter(field.Name[0]) || field.IsSpecialName)
                {
                    continue;
                }
                CheckMember(typeDoreplacedent, type, field, field.FieldType, jo != null, dc != null);
            }

            typeDocs.Add(type, new TypeDoreplacedent
            {
                fields = typeDoreplacedent.fields?.ToDictionary(p => p.Key, p => p.Value)
            });
            typeDoreplacedent.Copy(XmlMember.Find(type));
        }

19 View Source File : WorldObject.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public string DebugOutputString(WorldObject obj)
        {
            var sb = new StringBuilder();

            sb.AppendLine("ACE Debug Output:");
            sb.AppendLine("ACE Clreplaced File: " + GetType().Name + ".cs");
            sb.AppendLine("Guid: " + obj.Guid.Full + " (0x" + obj.Guid.Full.ToString("X") + ")");

            sb.AppendLine("----- Private Fields -----");
            foreach (var prop in obj.GetType().GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).OrderBy(field => field.Name))
            {
                if (prop.GetValue(obj) == null)
                    continue;

                sb.AppendLine($"{prop.Name.Replace("<", "").Replace(">k__BackingField", "")} = {prop.GetValue(obj)}");
            }

            sb.AppendLine("----- Public Properties -----");
            foreach (var prop in obj.GetType().GetProperties().OrderBy(property => property.Name))
            {
                if (prop.GetValue(obj, null) == null)
                    continue;

                switch (prop.Name.ToLower())
                {
                    case "guid":
                        sb.AppendLine($"{prop.Name} = {obj.Guid.Full} (GuidType.{obj.Guid.Type.ToString()})");
                        break;
                    case "descriptionflags":
                        sb.AppendLine($"{prop.Name} = {ObjectDescriptionFlags.ToString()}" + " (" + (uint)ObjectDescriptionFlags + ")");
                        break;
                    case "weenieflags":
                        var weenieFlags = CalculateWeenieHeaderFlag();
                        sb.AppendLine($"{prop.Name} = {weenieFlags.ToString()}" + " (" + (uint)weenieFlags + ")");
                        break;
                    case "weenieflags2":
                        var weenieFlags2 = CalculateWeenieHeaderFlag2();
                        sb.AppendLine($"{prop.Name} = {weenieFlags2.ToString()}" + " (" + (uint)weenieFlags2 + ")");
                        break;
                    case "itemtype":
                        sb.AppendLine($"{prop.Name} = {obj.ItemType.ToString()}" + " (" + (uint)obj.ItemType + ")");
                        break;
                    case "creaturetype":
                        sb.AppendLine($"{prop.Name} = {obj.CreatureType.ToString()}" + " (" + (uint)obj.CreatureType + ")");
                        break;
                    case "containertype":
                        sb.AppendLine($"{prop.Name} = {obj.ContainerType.ToString()}" + " (" + (uint)obj.ContainerType + ")");
                        break;
                    case "usable":
                        sb.AppendLine($"{prop.Name} = {obj.ItemUseable.ToString()}" + " (" + (uint)obj.ItemUseable + ")");
                        break;
                    case "radarbehavior":
                        sb.AppendLine($"{prop.Name} = {obj.RadarBehavior.ToString()}" + " (" + (uint)obj.RadarBehavior + ")");
                        break;
                    case "physicsdescriptionflag":
                        var physicsDescriptionFlag = CalculatedPhysicsDescriptionFlag();
                        sb.AppendLine($"{prop.Name} = {physicsDescriptionFlag.ToString()}" + " (" + (uint)physicsDescriptionFlag + ")");
                        break;
                    case "physicsstate":
                        var physicsState = PhysicsObj.State;
                        sb.AppendLine($"{prop.Name} = {physicsState.ToString()}" + " (" + (uint)physicsState + ")");
                        break;
                    //case "propertiesspellid":
                    //    foreach (var item in obj.PropertiesSpellId)
                    //    {
                    //        sb.AppendLine($"PropertySpellId.{Enum.GetName(typeof(Spell), item.SpellId)} ({item.SpellId})");
                    //    }
                    //    break;
                    case "validlocations":
                        sb.AppendLine($"{prop.Name} = {obj.ValidLocations}" + " (" + (uint)obj.ValidLocations + ")");
                        break;
                    case "currentwieldedlocation":
                        sb.AppendLine($"{prop.Name} = {obj.CurrentWieldedLocation}" + " (" + (uint)obj.CurrentWieldedLocation + ")");
                        break;
                    case "priority":
                        sb.AppendLine($"{prop.Name} = {obj.ClothingPriority}" + " (" + (uint)obj.ClothingPriority + ")");
                        break;
                    case "radarcolor":
                        sb.AppendLine($"{prop.Name} = {obj.RadarColor}" + " (" + (uint)obj.RadarColor + ")");
                        break;
                    case "location":
                        sb.AppendLine($"{prop.Name} = {obj.Location.ToLOCString()}");
                        break;
                    case "destination":
                        sb.AppendLine($"{prop.Name} = {obj.Destination.ToLOCString()}");
                        break;
                    case "instantiation":
                        sb.AppendLine($"{prop.Name} = {obj.Instantiation.ToLOCString()}");
                        break;
                    case "sanctuary":
                        sb.AppendLine($"{prop.Name} = {obj.Sanctuary.ToLOCString()}");
                        break;
                    case "home":
                        sb.AppendLine($"{prop.Name} = {obj.Home.ToLOCString()}");
                        break;
                    case "portalsummonloc":
                        sb.AppendLine($"{prop.Name} = {obj.PortalSummonLoc.ToLOCString()}");
                        break;
                    case "houseboot":
                        sb.AppendLine($"{prop.Name} = {obj.HouseBoot.ToLOCString()}");
                        break;
                    case "lastoutsidedeath":
                        sb.AppendLine($"{prop.Name} = {obj.LastOutsideDeath.ToLOCString()}");
                        break;
                    case "linkedlifestone":
                        sb.AppendLine($"{prop.Name} = {obj.LinkedLifestone.ToLOCString()}");
                        break;                    
                    case "channelsactive":
                        sb.AppendLine($"{prop.Name} = {(Channel)obj.GetProperty(PropertyInt.ChannelsActive)}" + " (" + (uint)obj.GetProperty(PropertyInt.ChannelsActive) + ")");
                        break;
                    case "channelsallowed":
                        sb.AppendLine($"{prop.Name} = {(Channel)obj.GetProperty(PropertyInt.ChannelsAllowed)}" + " (" + (uint)obj.GetProperty(PropertyInt.ChannelsAllowed) + ")");
                        break;
                    case "playerkillerstatus":
                        sb.AppendLine($"{prop.Name} = {obj.PlayerKillerStatus}" + " (" + (uint)obj.PlayerKillerStatus + ")");
                        break;
                    default:
                        sb.AppendLine($"{prop.Name} = {prop.GetValue(obj, null)}");
                        break;
                }
            }

            sb.AppendLine("----- Property Dictionaries -----");

            foreach (var item in obj.GetAllPropertyBools())
                sb.AppendLine($"PropertyBool.{Enum.GetName(typeof(PropertyBool), item.Key)} ({(int)item.Key}) = {item.Value}");
            foreach (var item in obj.GetAllPropertyDataId())
                sb.AppendLine($"PropertyDataId.{Enum.GetName(typeof(PropertyDataId), item.Key)} ({(int)item.Key}) = {item.Value}");
            foreach (var item in obj.GetAllPropertyFloat())
                sb.AppendLine($"PropertyFloat.{Enum.GetName(typeof(PropertyFloat), item.Key)} ({(int)item.Key}) = {item.Value}");
            foreach (var item in obj.GetAllPropertyInstanceId())
                sb.AppendLine($"PropertyInstanceId.{Enum.GetName(typeof(PropertyInstanceId), item.Key)} ({(int)item.Key}) = {item.Value}");
            foreach (var item in obj.GetAllPropertyInt())
                sb.AppendLine($"PropertyInt.{Enum.GetName(typeof(PropertyInt), item.Key)} ({(int)item.Key}) = {item.Value}");
            foreach (var item in obj.GetAllPropertyInt64())
                sb.AppendLine($"PropertyInt64.{Enum.GetName(typeof(PropertyInt64), item.Key)} ({(int)item.Key}) = {item.Value}");
            foreach (var item in obj.GetAllPropertyString())
                sb.AppendLine($"PropertyString.{Enum.GetName(typeof(PropertyString), item.Key)} ({(int)item.Key}) = {item.Value}");

            sb.AppendLine("\n");

            return sb.ToString().Replace("\r", "");
        }

19 View Source File : Serialization.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static Dictionary<string, object> ToDictionary(object obj)
		{
			System.Diagnostics.Debug.replacedert(obj != null);
			Dictionary<string, object> dic = new Dictionary<string, object>();
			FieldInfo[] fields = obj.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
			foreach (FieldInfo f in fields)
				dic.Add(f.Name, f.GetValue(obj));
			PropertyInfo[] props = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
			foreach (PropertyInfo p in props)
				dic.Add(p.Name, p.GetValue(obj, null));
			return dic;
		}

19 View Source File : DataConverter.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static T Convert<T>(DataRow row)
			where T : new()
		{
			T result = new T();
			var fields = typeof(T).GetFields(BindingFlags.Instance | BindingFlags.Public);
			foreach (var f in fields)
			{
				var col = row.Table.Columns[f.Name];
				if (col != null)
					f.SetValue(result, ChangeType(row[col], f.FieldType));
			}
			var props = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public);
			foreach (var p in props)
			{
				var col = row.Table.Columns[p.Name];
				if (col != null)
					p.SetValue(result, ChangeType(row[col], p.PropertyType), null);
			}
			return result;
		}

19 View Source File : ParentTokenId.g.cs
License : MIT License
Project Creator : Actipro

private static FieldInfo[] GetFields() {
			#if WINRT
			return typeof(ParentTokenId).GetTypeInfo().DeclaredFields.Where(f => (f.IsPublic) && (f.IsStatic)).ToArray();
			#else
			return typeof(ParentTokenId).GetFields((BindingFlags.Public | BindingFlags.Static));
			#endif
        }

19 View Source File : ReflectionUtils.cs
License : MIT License
Project Creator : aillieo

public static IEnumerable<FieldInfo> GetNodeParamFields(Type nodeType)
        {
            return nodeType.GetFields(BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance)
                .Where(fi => fi.GetCustomAttribute<NodeParamAttribute>(false) != null);
        }

19 View Source File : Helpers.cs
License : MIT License
Project Creator : 404Lcc

internal static MemberInfo[] GetInstanceFieldsAndProperties(Type type, bool publicOnly)
        {
#if WINRT || PROFILE259
			System.Collections.Generic.List<MemberInfo> members = new System.Collections.Generic.List<MemberInfo>();
            foreach(FieldInfo field in type.GetRuntimeFields())
            {
                if(field.IsStatic) continue;
                if(field.IsPublic || !publicOnly) members.Add(field);
            }
            foreach(PropertyInfo prop in type.GetRuntimeProperties())
            {
                MethodInfo getter = Helpers.GetGetMethod(prop, true, true);
                if(getter == null || getter.IsStatic) continue;
                if(getter.IsPublic || !publicOnly) members.Add(prop);
            }
            return members.ToArray();
#else
            BindingFlags flags = publicOnly ? BindingFlags.Public | BindingFlags.Instance : BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic;
            PropertyInfo[] props = type.GetProperties(flags);
            FieldInfo[] fields = type.GetFields(flags);
            MemberInfo[] members = new MemberInfo[fields.Length + props.Length];
            props.CopyTo(members, 0);
            fields.CopyTo(members, props.Length);
            return members;
#endif
        }

19 View Source File : ConfigurationBase.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public Dictionary<string, object> GetConfigurations()
		{
			BindingFlags flag = BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic;
			lock (_root)
			{
				Dictionary<string, object> dic = new Dictionary<string, object>();
				FieldInfo[] fields = this.GetType().GetFields(flag);
				foreach (FieldInfo f in fields)
				{
					if (!f.IsPrivate)
						dic.Add(f.Name, f.GetValue(this));
				}
				PropertyInfo[] props = this.GetType().GetProperties(flag);
				foreach (PropertyInfo p in props)
					dic.Add(p.Name, p.GetValue(this, null));
				return dic;
			}
		}

19 View Source File : SimpleLexicalStateId.g.cs
License : MIT License
Project Creator : Actipro

public override String GetKey(Int32 id) {
            FieldInfo[] fields = typeof(SimpleLexicalStateId).GetFields((BindingFlags.Public | BindingFlags.Static));
            for (Int32 index = 0; (index < fields.Length); index = (index + 1)) {
                FieldInfo field = fields[index];
                if (id.Equals(field.GetValue(null))) {
                    return field.Name;
                }
            }
            return null;
        }

19 View Source File : DataConverter.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static T Convert<T>(DataRow row, ref T obj)
		{
			try
			{
				var fields = typeof(T).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetField);
				foreach (var f in fields)
				{
					var col = row.Table.Columns[f.Name];
					if (col != null)
						f.SetValue(obj, ChangeType(row[col], f.FieldType));
				}
				var props = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty);
				foreach (var p in props)
				{
					var col = row.Table.Columns[p.Name];
					if (col != null)
						p.SetValue(obj, ChangeType(row[col], p.PropertyType), null);
				}
			}
			catch (Exception ex) { TraceLogger.Instance.WriteException(ex); throw; }
			return obj;
		}

19 View Source File : DynamicProxyMeta.cs
License : MIT License
Project Creator : 2881099

public static void CopyData(Type sourceType, object source, object target)
        {
            if (source == null) return;
            if (target == null) return;
            _copyDataFunc.GetOrAdd(sourceType, type =>
            {
                var sourceParamExp = Expression.Parameter(typeof(object), "sourceObject");
                var targetParamExp = Expression.Parameter(typeof(object), "targetObject");
                var sourceExp = Expression.Variable(type, "source");
                var targetExp = Expression.Variable(type, "target");
                var copyExps = new List<Expression>();
                var sourceFields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                foreach (var field in sourceFields)
                    copyExps.Add(Expression.replacedign(Expression.MakeMemberAccess(targetExp, field), Expression.MakeMemberAccess(sourceExp, field)));

                if (copyExps.Any() == false) return _copyDataFuncEmpty;
                var bodyExp = Expression.Block(
                    new[] {
                            sourceExp, targetExp
                    },
                    new[] {
                            Expression.IfThen(
                                Expression.NotEqual(sourceParamExp, Expression.Constant(null)),
                                Expression.IfThen(
                                    Expression.NotEqual(targetParamExp, Expression.Constant(null)),
                                    Expression.Block(
                                        Expression.replacedign(sourceExp, Expression.TypeAs(sourceParamExp, sourceType)),
                                        Expression.replacedign(targetExp, Expression.TypeAs(targetParamExp, sourceType)),
                                        Expression.IfThen(
                                            Expression.NotEqual(sourceExp, Expression.Constant(null)),
                                            Expression.IfThen(
                                                Expression.NotEqual(sourceExp, Expression.Constant(null)),
                                                Expression.Block(
                                                    copyExps.ToArray()
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                    }
                );
                return Expression.Lambda<Action<object, object>>(bodyExp, sourceParamExp, targetParamExp).Compile();
            })(source, target);
        }

19 View Source File : DataConverter.cs
License : GNU General Public License v3.0
Project Creator : aiportal

private static object StructFromString(string str, Type type)
		{
			Debug.replacedert(!string.IsNullOrEmpty(str));
			Debug.replacedert(type.IsValueType);

			var flds = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (flds.Length > 0)
			{
				object result = System.Activator.CreateInstance(type);
				string[] vals = str.Split(FieldSeparator);
				for (int i = 0; i < flds.Length && i < vals.Length; ++i)
				{
					object v = ObjectFromString(vals[i], flds[i].FieldType);
					flds[i].SetValue(result, v);
				}
				return result;
			}
			else
			{
				return System.Convert.ChangeType(str, type);
			}
		}

19 View Source File : SimpleAstNodeId.g.cs
License : MIT License
Project Creator : Actipro

public override String GetKey(Int32 id) {
            FieldInfo[] fields = typeof(SimpleAstNodeId).GetFields((BindingFlags.Public | BindingFlags.Static));
            for (Int32 index = 0; (index < fields.Length); index = (index + 1)) {
                FieldInfo field = fields[index];
                if (id.Equals(field.GetValue(null))) {
                    return field.Name;
                }
            }
            return null;
        }

19 View Source File : DataConverter.cs
License : GNU General Public License v3.0
Project Creator : aiportal

private static object StructFromValues(object obj, GetValueCallback getValue, bool hasField, bool hasInternal)
		{
			Debug.replacedert(obj != null);
			try
			{
				// properties
				{
					var flags = BindingFlags.Instance | BindingFlags.Public | (hasInternal ? BindingFlags.NonPublic : 0);
					var props = obj.GetType().GetProperties(flags);
					foreach (var p in props)
					{
						if (hasInternal)
						{
							var m = p.GetSetMethod(true);
							if (m.IsPrivate || m.IsFamily)
								continue;
						}
						if (p.CanWrite)
						{
							var v = getValue(p.Name);
							if (v != null)
								p.SetValue(obj, ChangeType(v, p.PropertyType), null);
						}
					}
				}
				// fields
				if (hasField)
				{
					var flags = BindingFlags.Instance | BindingFlags.Public | (hasInternal ? BindingFlags.NonPublic : 0);
					var flds = obj.GetType().GetFields(flags);
					foreach (var f in flds)
					{
						if (f.IsPrivate || f.IsFamily || f.IsInitOnly)
							continue;
		
						var v = getValue(f.Name);
						if (v != null)
							f.SetValue(obj, ChangeType(v, f.FieldType));
					}
				}
			}
			catch (Exception ex) { TraceLog.WriteException(ex); throw; }
			return obj;
		}

19 View Source File : CommonUtils.cs
License : Apache License 2.0
Project Creator : AantCoder

static string Process(object obj, int level, string prefLine, Dictionary<object, int> forParentLink, HashSet<string> excludeTypes)
        {
            try
            {
                if (obj == null) return "";
                Type type = obj.GetType();
                if (excludeTypes.Contains(type.Name)) return "<skip>";
                if (type == typeof(DateTime))
                {
                    return ((DateTime)obj).ToString("g");
                }
                else if (type.IsValueType || type == typeof(string))
                {
                    return obj.ToString();
                }
                else if (type.IsArray || obj is IEnumerable)
                {
                    string elementType = null;
                    Array array = null;

                    if (type.IsArray)
                    {
                        var tt = Type.GetType(type.FullName.Replace("[]", string.Empty));
                        if (tt != null)
                        {
                            elementType = tt.ToString();
                            if (excludeTypes.Contains(tt.Name)) return "<skips>";
                        }
                        //else return "<EEEEEEE" + type.FullName;
                        array = obj as Array;
                    }
                    else
                    {
                        //как лучше узнать кол-во и тип?
                        int cnt = 0;
                        foreach (var o in obj as IEnumerable) cnt++;
                        array = Array.CreateInstance(typeof(object), cnt);
                        int i = 0;
                        foreach (var o in obj as IEnumerable)
                        {
                            if (elementType == null && o != null)
                            {
                                var tt = o.GetType();
                                if (excludeTypes.Contains(tt.Name)) return "<skips>";
                                elementType = tt.ToString();
                            }
                            array.SetValue(o, i++);
                        }
                    }

                    if (elementType == null) elementType = "Object";

                    if (excludeTypes.Contains(elementType)) return "<skips>";

                    var info = "<" + elementType + "[" + array.Length.ToString() + "]" + ">";

                    if (level == 0)
                    {
                        return info + "[...]";
                    }

                    if (array.Length > 0)
                    {
                        var ress = new string[array.Length];
                        var resl = 0;
                        for (int i = 0; i < array.Length; i++)
                        {
                            ress[i] = Process(array.GetValue(i), level - 1, prefLine + PrefLineTab, forParentLink, excludeTypes);
                            resl += ress[i].Length;
                        }

                        if (resl < LineLength)
                        {
                            var res = info + "[" + ress[0];
                            for (int i = 1; i < ress.Length; i++)
                            {
                                res += ", " + ress[i];
                            }
                            return res + "]";
                        }
                        else
                        {
                            var res = info + "["
                                + Environment.NewLine + prefLine + ress[0];
                            for (int i = 1; i < ress.Length; i++)
                            {
                                res += ", "
                                    + Environment.NewLine + prefLine + ress[i];
                            }
                            return res + Environment.NewLine + prefLine + "]";
                        }
                    }
                    return info + "[]";
                }
                else if (obj is Type) return "<Type>" + obj.ToString();
                else if (type.IsClreplaced)
                {
                    var info = "<" + type.Name + ">";

                    if (forParentLink.ContainsKey(obj))
                    {
                        if (forParentLink[obj] >= level)
                            return info + "{duplicate}";
                        else
                            forParentLink[obj] = level;
                    }
                    else
                        forParentLink.Add(obj, level);

                    if (level == 0)
                    {
                        return info + "{...}";
                    }

                    FieldInfo[] fields = type.GetFields(BindingFlags.Public |
                                BindingFlags.NonPublic | BindingFlags.Instance);

                    if (fields.Length > 0)
                    {
                        var ress = new string[fields.Length];
                        var resl = 0;
                        for (int i = 0; i < fields.Length; i++)
                        {
                            object fieldValue = fields[i].GetValue(obj);
                            ress[i] = fieldValue == null
                                ? fields[i].Name + ": null"
                                : fields[i].Name + ": " + Process(fieldValue, level - 1, prefLine + PrefLineTab, forParentLink, excludeTypes);
                            resl += ress[i].Length;
                        }

                        if (resl < LineLength)
                        {
                            var res = info + "{" + ress[0];
                            for (int i = 1; i < ress.Length; i++)
                            {
                                res += ", " + ress[i];
                            }
                            return res + "}";
                        }
                        else
                        {
                            var res = info + "{"
                                + Environment.NewLine + prefLine + ress[0];
                            for (int i = 1; i < ress.Length; i++)
                            {
                                res += ", "
                                    + Environment.NewLine + prefLine + ress[i];
                            }
                            return res + Environment.NewLine + prefLine + "}";
                        }
                    }
                    return info + "{}";
                }
                else
                    throw new ArgumentException("Unknown type");
            }
            catch
            {
                return "<exception>";
            }
        }

19 View Source File : DataConverter.cs
License : GNU General Public License v3.0
Project Creator : aiportal

private static void StructToValues(object obj, SetValueCallback setValue, bool hasField, bool hasInternal)
		{
			Debug.replacedert(obj != null);
			try
			{
				// properties
				{
					var flags = BindingFlags.Instance | BindingFlags.Public | (hasInternal ? BindingFlags.NonPublic : 0);
					var props = obj.GetType().GetProperties(flags);
					foreach (var p in props)
					{
						if (hasInternal)
						{
							var m = p.GetSetMethod(true);
							if (m == null)
								continue;
							if (m.IsPrivate || m.IsFamily)
								continue;
						}
						if (p.CanRead)
						{
							setValue(p.Name, p.GetValue(obj, null));
						}
					}
				}
				// fields
				if (hasField)
				{
					var flags = BindingFlags.Instance | BindingFlags.Public | (hasInternal ? BindingFlags.NonPublic : 0);
					var flds = obj.GetType().GetFields(flags);
					foreach (var f in flds)
					{
						if (f.IsPrivate || f.IsFamily || f.IsInitOnly)
							continue;
						setValue(f.Name, f.GetValue(obj));
					}
				}
			}
			catch (Exception ex) { TraceLog.WriteException(ex); throw; }
		}

19 View Source File : SimpleTokenId.g.cs
License : MIT License
Project Creator : Actipro

public override String GetKey(Int32 id) {
            FieldInfo[] fields = typeof(SimpleTokenId).GetFields((BindingFlags.Public | BindingFlags.Static));
            for (Int32 index = 0; (index < fields.Length); index = (index + 1)) {
                FieldInfo field = fields[index];
                if (id.Equals(field.GetValue(null))) {
                    return field.Name;
                }
            }
            return null;
        }

19 View Source File : SteamVR_Camera.cs
License : MIT License
Project Creator : ajayyy

public void ForceLast()
	{
		if (values != null)
		{
			// Restore values on new instance
			foreach (DictionaryEntry entry in values)
			{
				var f = entry.Key as FieldInfo;
				f.SetValue(this, entry.Value);
			}
			values = null;
		}
		else
		{
			// Make sure it's the last component
			var components = GetComponents<Component>();

			// But first make sure there aren't any other SteamVR_Cameras on this object.
			for (int i = 0; i < components.Length; i++)
			{
				var c = components[i] as SteamVR_Camera;
				if (c != null && c != this)
				{
					DestroyImmediate(c);
				}
			}

			components = GetComponents<Component>();

			if (this != components[components.Length - 1])
			{
				// Store off values to be restored on new instance
				values = new Hashtable();
				var fields = GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
				foreach (var f in fields)
					if (f.IsPublic || f.IsDefined(typeof(SerializeField), true))
						values[f] = f.GetValue(this);

				var go = gameObject;
				DestroyImmediate(this);
				go.AddComponent<SteamVR_Camera>().ForceLast();
			}
		}
	}

19 View Source File : TypeUtils.cs
License : MIT License
Project Creator : 1996v

public static IEnumerable<KeyValuePair<string, object>> GetPublicMembersWithDynamicObject(this object value)
        {
            DEBUG.replacedert(value != null);
            Type t = value.GetType();
            foreach (FieldInfo p in t.GetFields(BindingFlags.Public | BindingFlags.Instance))
            {
                yield return new KeyValuePair<string, object>(p.Name, p.GetValue(value));
            }
            foreach (PropertyInfo p in t.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                if (p.GetIndexParameters().Length == 0 && p.CanRead && p.CanWrite)
                {
                    yield return new KeyValuePair<string, object>(p.Name, p.GetValue(value));
                }
            }
        }

19 View Source File : ReflectionUtils.cs
License : MIT License
Project Creator : akaskela

public static IEnumerable<FieldInfo> GetFields(Type targetType, BindingFlags bindingAttr)
        {
            ValidationUtils.ArgumentNotNull(targetType, nameof(targetType));

            List<MemberInfo> fieldInfos = new List<MemberInfo>(targetType.GetFields(bindingAttr));
#if !PORTABLE
            // Type.GetFields doesn't return inherited private fields
            // manually find private fields from base clreplaced
            GetChildPrivateFields(fieldInfos, targetType, bindingAttr);
#endif

            return fieldInfos.Cast<FieldInfo>();
        }

19 View Source File : GenericExtensions.cs
License : MIT License
Project Creator : adrenak

public static T GetCopyOf<T>(this Component comp, T other) where T : Component {
            Type type = comp.GetType();
            if (type != other.GetType()) return null; // type mis-match
            BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Default | BindingFlags.DeclaredOnly;
            PropertyInfo[] pinfos = type.GetProperties(flags);
            foreach (var pinfo in pinfos) {
                if (pinfo.CanWrite) {
                    try {
                        pinfo.SetValue(comp, pinfo.GetValue(other, null), null);
                    }
                    catch { } // In case of NotImplementedException being thrown. For some reason specifying that exception didn't seem to catch it, so I didn't catch anything specific.
                }
            }
            FieldInfo[] finfos = type.GetFields(flags);
            foreach (var finfo in finfos)
                finfo.SetValue(comp, finfo.GetValue(other));
            return comp as T;
        }

19 View Source File : SceneInfoUtils.cs
License : Apache License 2.0
Project Creator : abist-co-ltd

private static void RefreshCachedTypes()
        {
            if (EditorApplication.isCompiling || BuildPipeline.isBuildingPlayer)
            {   // Don't refresh cached types if we're in the middle of something important
                return;
            }

            cachedComponentTypes.Clear();

            foreach (replacedembly replacedembly in AppDomain.CurrentDomain.Getreplacedemblies())
            {
                foreach (Type t in replacedembly.GetTypes().Where(t => t.IsSubclreplacedOf(typeof(Component))))
                {
                    foreach (FieldInfo f in t.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
                    {
                        if (fieldTypesToSearch.Contains(f.FieldType))
                        {
                            cachedComponentTypes.Add(new Tuple<Type, FieldInfo>(t, f));
                        }
                    }
                }
            }
        }

19 View Source File : SequenceLevel.cs
License : MIT License
Project Creator : 0xC0000054

private static IReadOnlyDictionary<byte, SequenceLevel> CreateSequenceLevelMap()
            {
                FieldInfo[] fieldInfos = typeof(SequenceLevel).GetFields(BindingFlags.Public | BindingFlags.Static);

                Dictionary<byte, SequenceLevel> map = new Dictionary<byte, SequenceLevel>(fieldInfos.Length);

                for (int i = 0; i < fieldInfos.Length; i++)
                {
                    FieldInfo fieldInfo = fieldInfos[i];
                    if (fieldInfo.FieldType == typeof(SequenceLevel))
                    {
                        SequenceLevel item = (SequenceLevel)fieldInfo.GetValue(null);

                        map.Add(item.Value, item);
                    }
                }

                return map;
            }

19 View Source File : TypeUtils.cs
License : MIT License
Project Creator : 1996v

public static IEnumerable<FieldInfo> GetAllFields(this Type type, BindingFlags bind)
        {
            if (type.BaseType != null)
            {
                foreach (var item in GetAllFields(type.BaseType, bind | BindingFlags.DeclaredOnly))
                {
                    yield return item;
                }
            }

            foreach (var item in type.GetFields(bind | BindingFlags.DeclaredOnly))
            {
                yield return item;
            }
        }

19 View Source File : AObjectBase.cs
License : MIT License
Project Creator : 404Lcc

public void AutoReference(Transform transform)
        {
            Dictionary<string, FieldInfo> fieldInfoDict = new Dictionary<string, FieldInfo>();
            FieldInfo[] fieldInfos = GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            Type objectType = typeof(Object);
            foreach (FieldInfo item in fieldInfos)
            {
                if (item.FieldType.IsSubclreplacedOf(objectType))
                {
                    fieldInfoDict[item.Name.ToLower()] = item;
                }
            }
            if (fieldInfoDict.Count > 0)
            {
                AutoReference(transform, fieldInfoDict);
            }
        }

19 View Source File : ParentLexicalStateId.g.cs
License : MIT License
Project Creator : Actipro

private static FieldInfo[] GetFields() {
			#if WINRT
			return typeof(ParentLexicalStateId).GetTypeInfo().DeclaredFields.Where(f => (f.IsPublic) && (f.IsStatic)).ToArray();
			#else
			return typeof(ParentLexicalStateId).GetFields((BindingFlags.Public | BindingFlags.Static));
			#endif
        }

19 View Source File : ConfigurationBase.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public Dictionary<string, object> GetConfigurations()
		{
			lock (_root)
			{
				Dictionary<string, object> dic = new Dictionary<string, object>();
				FieldInfo[] fields = this.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
				foreach (FieldInfo f in fields)
					dic.Add(f.Name, f.GetValue(this));
				PropertyInfo[] props = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
				foreach (PropertyInfo p in props)
					dic.Add(p.Name, p.GetValue(this, null));
				return dic;
			}
		}

See More Examples