Reflection access for a oneof, allowing clear and "get case" actions.
Esempio n. 1
0
 private OneofAccessor CreateAccessor(string clrName)
 {
     // We won't have a CLR name if this is from a dynamically-loaded FileDescriptor.
     // TODO: Support dynamic messages.
     if (clrName == null)
     {
         return(null);
     }
     if (IsSynthetic)
     {
         return(OneofAccessor.ForSyntheticOneof(this));
     }
     else
     {
         var caseProperty = containingType.ClrType.GetProperty(clrName + "Case");
         if (caseProperty == null)
         {
             throw new DescriptorValidationException(this, $"Property {clrName}Case not found in {containingType.ClrType}");
         }
         if (!caseProperty.CanRead)
         {
             throw new ArgumentException($"Cannot read from property {clrName}Case in {containingType.ClrType}");
         }
         var clearMethod = containingType.ClrType.GetMethod("Clear" + clrName);
         if (clearMethod == null)
         {
             throw new DescriptorValidationException(this, $"Method Clear{clrName} not found in {containingType.ClrType}");
         }
         return(OneofAccessor.ForRegularOneof(this, caseProperty, clearMethod));
     }
 }
Esempio n. 2
0
        internal OneofDescriptor(OneofDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, string clrName) : base(file, file.ComputeFullName(parent, proto.Name), index)
        {
            while (true)
            {
IL_63:
                uint arg_47_0 = 2329051274u;
                while (true)
                {
                    uint num;
                    switch ((num = (arg_47_0 ^ 3026981471u)) % 4u)
                    {
                    case 0u:
                        goto IL_63;

                    case 1u:
                        this.proto = proto;
                        arg_47_0   = (num * 378117375u ^ 1534672859u);
                        continue;

                    case 3u:
                        this.containingType = parent;
                        arg_47_0            = (num * 4267417022u ^ 3727843631u);
                        continue;
                    }
                    goto Block_1;
                }
            }
Block_1:
            file.DescriptorPool.AddSymbol(this);
            this.accessor = this.CreateAccessor(clrName);
        }
Esempio n. 3
0
        internal OneofDescriptor(OneofDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, string clrName)
            : base(file, file.ComputeFullName(parent, proto.Name), index)
        {
            this.proto     = proto;
            containingType = parent;

            file.DescriptorPool.AddSymbol(this);
            accessor = CreateAccessor(clrName);
        }
Esempio n. 4
0
        internal OneofDescriptor(OneofDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, string clrName)
            : base(file, file.ComputeFullName(parent, proto.Name), index)
        {
            this.proto = proto;
            containingType = parent;

            file.DescriptorPool.AddSymbol(this);
            accessor = CreateAccessor(clrName);
        }
Esempio n. 5
0
 internal OneofAccessor(PropertyInfo caseProperty, MethodInfo clearMethod, OneofDescriptor descriptor)
 {
     if (!OneofAccessor.smethod_0(caseProperty))
     {
         throw OneofAccessor.smethod_1(Module.smethod_33 <string>(966859498u));
     }
     this.descriptor    = descriptor;
     this.caseDelegate  = ReflectionUtil.CreateFuncIMessageT <int>(caseProperty.GetGetMethod());
     this.descriptor    = descriptor;
     this.clearDelegate = ReflectionUtil.CreateActionIMessage(clearMethod);
 }
Esempio n. 6
0
        internal OneofDescriptor(OneofDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, string clrName)
            : base(file, file.ComputeFullName(parent, proto.Name), index)
        {
            this.Proto     = proto;
            containingType = parent;
            file.DescriptorPool.AddSymbol(this);

            // It's useful to determine whether or not this is a synthetic oneof before cross-linking. That means
            // diving into the proto directly rather than using FieldDescriptor, but that's okay.
            var firstFieldInOneof = parent.Proto.Field.FirstOrDefault(fieldProto => fieldProto.HasOneofIndex && fieldProto.OneofIndex == index);

            IsSynthetic = firstFieldInOneof?.Proto3Optional ?? false;

            accessor = CreateAccessor(clrName);
        }