Thema: Delphi from C# to delphi

Einzelnen Beitrag anzeigen

sdean

Registriert seit: 5. Dez 2009
64 Beiträge
 
#13

AW: from C# to delphi

  Alt 6. Jan 2023, 10:18
so many thanks for all your great help ,
What about this please :

Code:
internal static IObject ReadObject(uint constructorNb = 0)
      {
         var myDef = type.GetCustomAttribute<MYDefAttribute>();
         var obj = Activator.CreateInstance(type, true);
         IEnumerable<FieldInfo> fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public);
         if (myDef.inheritBefore) fields = fields.GroupBy(f => f.DeclaringType).Reverse().SelectMany(g => g);
         ulong myflags = 0;
         boolFlagAttribute boolFlag;
         foreach (var field in fields)
         {
            if (((boolFlag = field.GetCustomAttribute<boolFlagAttribute>()) != null) && (myflags & (1UL << boolFlag.Bit)) == 0) continue;
            object value = field.FieldType;
            field.SetValue(obj, value);
            if (field.FieldType.IsEnum)
               if (field.Name == "myflags") myflags = (uint)value;
               else if (field.Name == "myflags2") myflags |= (ulong)(uint)value << 32;            
         }
         return (IObject)obj;
      }
  Mit Zitat antworten Zitat