static Container DeepClone(Container original, bool notLateToLate)
        {
            var tm1 = TypeModel.Create();
            var tm2 = TypeModel.Create();

            tm1.SkipForcedLateReference = true;
            tm2.SkipForcedLateReference = true;

            ValueMember f = tm2.Add(typeof(Referenced), true)[1];

            f.SetSettings(x => x.V.Format = ValueFormat.Reference);

            if (notLateToLate)
            {
                var tmTemp = tm1;
                tm1 = tm2;
                tm2 = tmTemp;
            }

            Container copy;

            using (var ms = new MemoryStream())
            {
                tm1.Serialize(ms, original);

                ms.Position = 0;

                copy = tm2.Deserialize <Container>(ms);
            }
            return(copy);
        }
Ejemplo n.º 2
0
        public TupleSerializer(RuntimeTypeModel model, ConstructorInfo ctor, MemberInfo[] members, Type[] kv)
        {
            if (ctor == null)
            {
                throw new ArgumentNullException("ctor");
            }
            if (members == null)
            {
                throw new ArgumentNullException("members");
            }
            this.ctor    = ctor;
            this.members = members;
            this.tails   = new IProtoSerializer[members.Length];

            ParameterInfo[] parameters = ctor.GetParameters();
            for (int i = 0; i < members.Length; i++)
            {
                WireType wireType;
                Type     finalType = parameters[i].ParameterType;

                Type itemType = null, defaultType = null;

                MetaType.ResolveListTypes(model, finalType, ref itemType, ref defaultType);
                Type tmp = itemType == null ? finalType : itemType;

                bool asReference = false;
                int  typeIndex   = model.FindOrAddAuto(tmp, false, true, false);
                if (typeIndex >= 0)
                {
                    asReference = model[tmp].AsReferenceDefault;
                }
                if (tmp.FullName == "ILRuntime.Runtime.Intepreter.ILTypeInstance")
                {
                    tmp = kv [i];
                }
                IProtoSerializer tail = ValueMember.TryGetCoreSerializer(model, DataFormat.Default, tmp, out wireType, asReference, false, false, true), serializer;
                if (tail == null)
                {
                    throw new InvalidOperationException("No serializer defined for type: " + tmp.FullName);
                }

                tail = new TagDecorator(i + 1, wireType, false, tail);
                if (itemType == null)
                {
                    serializer = tail;
                }
                else
                {
                    if (finalType.IsArray)
                    {
                        serializer = new ArrayDecorator(model, tail, i + 1, false, wireType, finalType, false, false);
                    }
                    else
                    {
                        serializer = ListDecorator.Create(model, finalType, defaultType, tail, i + 1, false, wireType, true, false, false);
                    }
                }
                tails[i] = serializer;
            }
        }
Ejemplo n.º 3
0
        static RuntimeTypeModel CreateDefaultRefModel(bool aFirst, bool comp)
        {
            ProtoCompatibilitySettingsValue fullComp = ProtoCompatibilitySettingsValue.FullCompatibility;

            fullComp.SuppressValueEnhancedFormat = false;
            var model = TypeModel.Create(false, comp ? fullComp : ProtoCompatibilitySettingsValue.Incompatible);

            if (comp)
            {
                model.SkipForcedLateReference = true;
            }
            // otherwise will not be compatible
            model.SkipForcedAdvancedVersioning = true;
            if (aFirst)
            {
                model.Add(typeof(A_WithDefaultRef), true);
                model.Add(typeof(B_WithDefaultRef), true);
            }
            else
            {
                model.Add(typeof(B_WithDefaultRef), true);
                model.Add(typeof(A_WithDefaultRef), true);
            }

            ValueMember f = model[typeof(B_WithDefaultRef)][2];
            MemberLevelSettingsValue s = f.GetSettingsCopy(0);

            Assert.That(s.Format, Is.EqualTo(ValueFormat.NotSpecified));
            s.Format = ValueFormat.Compact;
            f.SetSettings(s);

            model.AutoCompile = false;

            return(model);
        }
Ejemplo n.º 4
0
        public override bool Equals(object obj)
        {
            DbLookupAttribute o = obj as DbLookupAttribute;

            if (o != null)
            {
                return(DisplayMember.Equals(o.DisplayMember) && ValueMember.Equals(o.ValueMember));
            }
            return(false);
        }
Ejemplo n.º 5
0
		public void prepare(bool ignoreCase, bool publicOnly, bool readableOnly, bool writeableOnly) {
			_Case = _h.FindValueMember(_t, "Case", ignoreCase, publicOnly, readableOnly, writeableOnly);
			_CaSe = _h.FindValueMember(_t, "CaSe", ignoreCase, publicOnly, readableOnly, writeableOnly);
			_Name = _h.FindValueMember(_t, "Name", ignoreCase, publicOnly, readableOnly, writeableOnly);
			_name = _h.FindValueMember(_t, "name", ignoreCase, publicOnly, readableOnly, writeableOnly);
			_IName = _h.FindValueMember(_t, "IName", ignoreCase, publicOnly, readableOnly, writeableOnly);
			_iname = _h.FindValueMember(_t, "iname", ignoreCase, publicOnly, readableOnly, writeableOnly);
			_Ro = _h.FindValueMember(_t, "Ro", ignoreCase, publicOnly, readableOnly, writeableOnly);
			_Wo = _h.FindValueMember(_t, "Wo", ignoreCase, publicOnly, readableOnly, writeableOnly);
			_Er = _h.FindValueMember(_t, "Er", ignoreCase, publicOnly, readableOnly, writeableOnly);
		}
Ejemplo n.º 6
0
        public override int GetHashCode()
        {
            int multiplier = 23;

            if (hashCode == 0)
            {
                int code = 133;
                code     = multiplier * code + DisplayMember.GetHashCode();
                code     = multiplier * code + ValueMember.GetHashCode();
                hashCode = code;
            }
            return(hashCode);
        }
        public TupleSerializer(RuntimeTypeModel model, ConstructorInfo ctor, MemberInfo[] members)
        {
            WireType         wireType;
            IProtoSerializer arrayDecorator;

            if (ctor == null)
            {
                throw new ArgumentNullException("ctor");
            }
            if (members == null)
            {
                throw new ArgumentNullException("members");
            }
            this.ctor    = ctor;
            this.members = members;
            this.tails   = new IProtoSerializer[(int)members.Length];
            ParameterInfo[] parameters = ctor.GetParameters();
            for (int i = 0; i < (int)members.Length; i++)
            {
                Type parameterType = parameters[i].ParameterType;
                Type type          = null;
                Type type1         = null;
                MetaType.ResolveListTypes(model, parameterType, ref type, ref type1);
                Type type2 = (type == null ? parameterType : type);
                bool asReferenceDefault = false;
                if (model.FindOrAddAuto(type2, false, true, false) >= 0)
                {
                    asReferenceDefault = model[type2].AsReferenceDefault;
                }
                IProtoSerializer tagDecorator = ValueMember.TryGetCoreSerializer(model, DataFormat.Default, type2, out wireType, asReferenceDefault, false, false, true);
                if (tagDecorator == null)
                {
                    throw new InvalidOperationException(string.Concat("No serializer defined for type: ", type2.FullName));
                }
                tagDecorator = new TagDecorator(i + 1, wireType, false, tagDecorator);
                if (type == null)
                {
                    arrayDecorator = tagDecorator;
                }
                else if (!parameterType.IsArray)
                {
                    arrayDecorator = ListDecorator.Create(model, parameterType, type1, tagDecorator, i + 1, false, wireType, true, false, false);
                }
                else
                {
                    arrayDecorator = new ArrayDecorator(model, tagDecorator, i + 1, false, wireType, parameterType, false, false);
                }
                this.tails[i] = arrayDecorator;
            }
        }
Ejemplo n.º 8
0
 public TupleSerializer(RuntimeTypeModel model, ConstructorInfo ctor, MemberInfo[] members)
 {
     if (ctor == null)
     {
         throw new ArgumentNullException("ctor");
     }
     if (members == null)
     {
         throw new ArgumentNullException("members");
     }
     this.ctor    = ctor;
     this.members = members;
     this.tails   = new IProtoSerializer[members.Length];
     ParameterInfo[] parameters = ctor.GetParameters();
     for (int i = 0; i < members.Length; i++)
     {
         Type parameterType = parameters[i].get_ParameterType();
         Type type          = null;
         Type concreteType  = null;
         MetaType.ResolveListTypes(model, parameterType, ref type, ref concreteType);
         Type type2       = (type != null) ? type : parameterType;
         bool asReference = false;
         int  num         = model.FindOrAddAuto(type2, false, true, false);
         if (num >= 0)
         {
             asReference = model[type2].AsReferenceDefault;
         }
         WireType         wireType;
         IProtoSerializer protoSerializer = ValueMember.TryGetCoreSerializer(model, DataFormat.Default, type2, out wireType, asReference, false, false, true);
         if (protoSerializer == null)
         {
             throw new InvalidOperationException("No serializer defined for type: " + type2.get_FullName());
         }
         protoSerializer = new TagDecorator(i + 1, wireType, false, protoSerializer);
         IProtoSerializer protoSerializer2;
         if (type == null)
         {
             protoSerializer2 = protoSerializer;
         }
         else if (parameterType.get_IsArray())
         {
             protoSerializer2 = new ArrayDecorator(model, protoSerializer, i + 1, false, wireType, parameterType, false, false);
         }
         else
         {
             protoSerializer2 = ListDecorator.Create(model, parameterType, concreteType, protoSerializer, i + 1, false, wireType, true, false, false);
         }
         this.tails[i] = protoSerializer2;
     }
 }
Ejemplo n.º 9
0
        public TupleSerializer(RuntimeTypeModel model, ConstructorInfo ctor, MemberInfo[] members)
        {
            if (ctor == null)
            {
                throw new ArgumentNullException("ctor");
            }
            if (members == null)
            {
                throw new ArgumentNullException("members");
            }
            this.ctor    = ctor;
            this.members = members;
            this.tails   = new IProtoSerializer[members.Length];

            ParameterInfo[] parameters = ctor.GetParameters();
            for (int i = 0; i < members.Length; i++)
            {
                WireType wireType;
                Type     finalType = parameters[i].ParameterType;

                Type itemType = null, defaultType = null;

                MetaType.ResolveListTypes(finalType, ref itemType, ref defaultType);
                Type             tmp = itemType == null ? finalType : itemType;
                IProtoSerializer tail = ValueMember.TryGetCoreSerializer(model, DataFormat.Default, tmp, out wireType, false, false, false), serializer;
                if (tail == null)
                {
                    throw new InvalidOperationException("No serializer defined for type: " + tmp.FullName);
                }

                tail = new TagDecorator(i + 1, wireType, false, tail);
                if (itemType == null)
                {
                    serializer = tail;
                }
                else
                {
                    if (finalType.IsArray)
                    {
                        serializer = new ArrayDecorator(tail, i + 1, false, wireType, finalType, false, false);
                    }
                    else
                    {
                        serializer = new ListDecorator(finalType, defaultType, tail, i + 1, false, wireType, true, false, false);
                    }
                }
                tails[i] = serializer;
            }
        }
Ejemplo n.º 10
0
 public TupleSerializer(RuntimeTypeModel model, ConstructorInfo ctor, MemberInfo[] members)
 {
     if (ctor == null)
     {
         throw new ArgumentNullException("ctor");
     }
     if (members == null)
     {
         throw new ArgumentNullException("members");
     }
     this.ctor    = ctor;
     this.members = members;
     this.tails   = new IProtoSerializer[members.Length];
     ParameterInfo[] parameters = ctor.GetParameters();
     for (int i = 0; i < members.Length; i++)
     {
         WireType         type;
         IProtoSerializer serializer2;
         Type             parameterType = parameters[i].ParameterType;
         Type             itemType      = null;
         Type             defaultType   = null;
         MetaType.ResolveListTypes(model, parameterType, ref itemType, ref defaultType);
         Type type5       = (itemType == null) ? parameterType : itemType;
         bool asReference = false;
         if (model.FindOrAddAuto(type5, false, true, false) >= 0)
         {
             asReference = model[type5].AsReferenceDefault;
         }
         IProtoSerializer tail = ValueMember.TryGetCoreSerializer(model, DataFormat.Default, type5, out type, asReference, false, false, true);
         if (tail == null)
         {
             throw new InvalidOperationException("No serializer defined for type: " + type5.FullName);
         }
         tail = new TagDecorator(i + 1, type, false, tail);
         if (itemType == null)
         {
             serializer2 = tail;
         }
         else if (parameterType.IsArray)
         {
             serializer2 = new ArrayDecorator(model, tail, i + 1, false, type, parameterType, false, false);
         }
         else
         {
             serializer2 = new ListDecorator(model, parameterType, defaultType, tail, i + 1, false, type, true, false, false);
         }
         this.tails[i] = serializer2;
     }
 }
Ejemplo n.º 11
0
        public static ValueMember AddFieldCopy(this MetaType metaType, ValueMember originalValueMember)
        {
            var valueMember = metaType.AddField(originalValueMember.FieldNumber, originalValueMember.Name, originalValueMember.ItemType, originalValueMember.DefaultType);

            valueMember.AsReference  = originalValueMember.AsReference;
            valueMember.DataFormat   = originalValueMember.DataFormat;
            valueMember.DefaultValue = originalValueMember.DefaultValue;
            valueMember.DynamicType  = originalValueMember.DynamicType;
            valueMember.IsPacked     = originalValueMember.IsPacked;
            valueMember.IsRequired   = originalValueMember.IsRequired;
            valueMember.IsStrict     = originalValueMember.IsStrict;
            valueMember.SupportNull  = originalValueMember.SupportNull;

            return(valueMember);
        }
Ejemplo n.º 12
0
        public void TestValueTypeTC()
        {
            string name  = "OrbServices_TestValueType";
            string repId = "IDL:Ch/Elca/Iiop/Tests/" + name + ":1.0";

            ValueMember m1 = new ValueMember("M1", m_orb.create_long_tc(), 0);

            omg.org.CORBA.TypeCode tc =
                m_orb.create_value_tc(repId, name, 0, m_orb.create_null_tc(),
                                      new ValueMember[] { m1 });
            Assert.AreEqual(repId, tc.id(), "id");
            Assert.AreEqual(TCKind.tk_value, tc.kind(), "king");
            Assert.AreEqual(1, tc.member_count(), "nr of members");
            Assert.AreEqual(m1.name, tc.member_name(0), "member m1 name");
            Assert.AreEqual(m1.type.kind(), tc.member_type(0).kind(), "member m1 type");
        }
Ejemplo n.º 13
0
            private static Action <TContainer, TMember>?BuildSetter(ValueMember member)
            {
                switch (member.Member)
                {
                case PropertyInfo property:
                    var method = property.GetSetMethod(nonPublic: true);
                    return(method != null ? (Action <TContainer, TMember>)Delegate.CreateDelegate(typeof(Action <TContainer, TMember>), method) : null);

                case FieldInfo field:
                    // we want to avoid run-time code generation in contract assemblies but field setter delegates cannot be created without that,
                    // so we resort to reflection as public fields are uncommon in DTOs anyway
                    return(!field.IsInitOnly ? (container, value) => field.SetValueDirect(__makeref(container), value) : (Action <TContainer, TMember>?)null);

                default:
                    throw new ArgumentException(null, nameof(member));
                }
            }
Ejemplo n.º 14
0
        public TupleSerializer(RuntimeTypeModel model, ConstructorInfo ctor, MemberInfo[] members)
        {
            if (ctor == null)
            {
                throw new ArgumentNullException("ctor");
            }
            if (members == null)
            {
                throw new ArgumentNullException("members");
            }
            this.ctor    = ctor;
            this.members = members;
            tails        = new IProtoSerializer[members.Length];
            ParameterInfo[] parameters = ctor.GetParameters();
            int             num        = 0;
            Type            type;

            while (true)
            {
                if (num < members.Length)
                {
                    Type parameterType = parameters[num].ParameterType;
                    Type itemType      = null;
                    Type defaultType   = null;
                    MetaType.ResolveListTypes(model, parameterType, ref itemType, ref defaultType);
                    type = ((itemType == null) ? parameterType : itemType);
                    bool asReference = false;
                    if (model.FindOrAddAuto(type, demand: false, addWithContractOnly: true, addEvenIfAutoDisabled: false) >= 0)
                    {
                        asReference = model[type].AsReferenceDefault;
                    }
                    IProtoSerializer protoSerializer = ValueMember.TryGetCoreSerializer(model, DataFormat.Default, type, out WireType defaultWireType, asReference, dynamicType: false, overwriteList: false, allowComplexTypes: true);
                    if (protoSerializer == null)
                    {
                        break;
                    }
                    protoSerializer = new TagDecorator(num + 1, defaultWireType, strict: false, protoSerializer);
                    IProtoSerializer protoSerializer2 = (itemType != null) ? ((!parameterType.IsArray) ? ((ProtoDecoratorBase)ListDecorator.Create(model, parameterType, defaultType, protoSerializer, num + 1, writePacked: false, defaultWireType, returnList: true, overwriteList: false, supportNull: false)) : ((ProtoDecoratorBase) new ArrayDecorator(model, protoSerializer, num + 1, writePacked: false, defaultWireType, parameterType, overwriteList: false, supportNull: false))) : protoSerializer;
                    tails[num] = protoSerializer2;
                    num++;
                    continue;
                }
                return;
            }
            throw new InvalidOperationException("No serializer defined for type: " + type.FullName);
        }
Ejemplo n.º 15
0
        public TupleSerializer(RuntimeTypeModel model, ConstructorInfo ctor, MemberInfo[] members)
        {
            if (ctor == (ConstructorInfo)null)
            {
                throw new ArgumentNullException("ctor");
            }
            if (members == null)
            {
                throw new ArgumentNullException("members");
            }
            this.ctor    = ctor;
            this.members = members;
            tails        = new IProtoSerializer[members.Length];
            ParameterInfo[] parameters = ctor.GetParameters();
            int             num        = 0;
            Type            type2;

            while (true)
            {
                if (num < members.Length)
                {
                    Type parameterType = parameters[num].ParameterType;
                    Type type          = null;
                    Type concreteType  = null;
                    MetaType.ResolveListTypes(model, parameterType, ref type, ref concreteType);
                    type2 = ((type == (Type)null) ? parameterType : type);
                    bool asReference = false;
                    if (model.FindOrAddAuto(type2, false, true, false) >= 0)
                    {
                        asReference = model[type2].AsReferenceDefault;
                    }
                    IProtoSerializer protoSerializer = ValueMember.TryGetCoreSerializer(model, DataFormat.Default, type2, out WireType wireType, asReference, false, false, true);
                    if (protoSerializer != null)
                    {
                        protoSerializer = new TagDecorator(num + 1, wireType, false, protoSerializer);
                        IProtoSerializer protoSerializer2 = (!(type == (Type)null)) ? ((!parameterType.IsArray) ? ((ProtoDecoratorBase)ListDecorator.Create(model, parameterType, concreteType, protoSerializer, num + 1, false, wireType, true, false, false)) : ((ProtoDecoratorBase) new ArrayDecorator(model, protoSerializer, num + 1, false, wireType, parameterType, false, false))) : protoSerializer;
                        tails[num] = protoSerializer2;
                        num++;
                        continue;
                    }
                    break;
                }
                return;
            }
            throw new InvalidOperationException("No serializer defined for type: " + type2.FullName);
        }
Ejemplo n.º 16
0
        public TupleSerializer(RuntimeTypeModel model, ConstructorInfo ctor, MemberInfo[] members, SerializerFeatures features, CompatibilityLevel compatibilityLevel)
        {
            this.ctor    = ctor ?? throw new ArgumentNullException(nameof(ctor));
            this.members = members ?? throw new ArgumentNullException(nameof(members));
            this.tails   = new IRuntimeProtoSerializerNode[members.Length];

            Features = features;
            ParameterInfo[] parameters = ctor.GetParameters();
            for (int i = 0; i < members.Length; i++)
            {
                Type finalType = parameters[i].ParameterType;

                var  repeated = model.TryGetRepeatedProvider(finalType);
                Type tmp      = repeated?.ItemType ?? finalType;

                bool asReference = false;
                int  typeIndex   = model.FindOrAddAuto(tmp, false, true, false, compatibilityLevel);
                if (typeIndex >= 0)
                {
                    asReference = model[tmp].AsReferenceDefault;
                }
                IRuntimeProtoSerializerNode tail = ValueMember.TryGetCoreSerializer(model, DataFormat.Default, compatibilityLevel, tmp, out WireType wireType, asReference, false, false, true), serializer;
                if (tail == null)
                {
                    throw new InvalidOperationException("No serializer defined for type: " + tmp.FullName);
                }

                if (repeated == null)
                {
                    serializer = new TagDecorator(i + 1, wireType, false, tail);
                }
                else if (repeated.IsMap)
                {
                    serializer = ValueMember.CreateMap(repeated, model, DataFormat.Default, compatibilityLevel, DataFormat.Default, DataFormat.Default, asReference, false, true, false, i + 1);
                }
                else
                {
                    SerializerFeatures listFeatures = wireType.AsFeatures() | SerializerFeatures.OptionPackedDisabled;
                    serializer = RepeatedDecorator.Create(repeated, i + 1, listFeatures, compatibilityLevel, DataFormat.Default);
                }
                tails[i] = serializer;
            }
        }
Ejemplo n.º 17
0
        public void TestGenerate()
        {
            string      name     = "TestGenForTypeCodeType";
            string      typeName = "Ch.Elca.Iiop.Tests." + name;
            string      repId    = "IDL:Ch/Elca/Iiop/Tests/TestGenForTypeCodeType:1.0";
            ValueMember m1       = new ValueMember("M1", new LongTC(), 0);
            ValueTypeTC vt       = new ValueTypeTC(repId,
                                                   name, new ValueMember[] { m1 },
                                                   new NullTC(), 0);

            Type res = m_gen.CreateOrGetType(typeName, vt);

            Assert.NotNull(res);
            Assert.AreEqual(typeName, res.FullName, "type name");
            Assert.AreEqual(repId, Repository.GetRepositoryID(res), "rep id");
            Assert.NotNull(res.GetField(m1.name,
                                        BindingFlags.Public | BindingFlags.Instance), "field M1");
            Assert.IsTrue(res.IsSerializable, "Serializable");
        }
Ejemplo n.º 18
0
        public object MapToIdlConcreateValueType(Type clsType)
        {
            omg.org.CORBA.TypeCode baseTypeCode;
            if (clsType.BaseType.Equals(ReflectionHelper.ObjectType) ||
                clsType.BaseType.Equals(typeof(System.ComponentModel.MarshalByValueComponent)))
            {
                baseTypeCode = new NullTC();
            }
            else
            {
                baseTypeCode = CreateOrGetTypeCodeForType(clsType.BaseType,
                                                          AttributeExtCollection.EmptyCollection);
            }
            ValueTypeTC result = new ValueTypeTC();

            RegisterCreatedTypeCodeForType(clsType, AttributeExtCollection.EmptyCollection,
                                           result);

            // create the TypeCodes for the members
            FieldInfo[]   members      = ReflectionHelper.GetAllDeclaredInstanceFieldsOrdered(clsType);
            ValueMember[] valueMembers = new ValueMember[members.Length];
            for (int i = 0; i < members.Length; i++)
            {
                omg.org.CORBA.TypeCode memberType = CreateOrGetTypeCodeForType(members[i].FieldType,
                                                                               ReflectionHelper.GetCustomAttriutesForField(members[i],
                                                                                                                           true));
                short visibility;
                if (members[i].IsPrivate)
                {
                    visibility = VISIBILITY_PRIVATE;
                }
                else
                {
                    visibility = VISIBILITY_PUBLIC;
                }
                valueMembers[i] = new ValueMember(members[i].Name, memberType, visibility);
            }
            result.Initalize(Repository.GetRepositoryID(clsType),
                             IdlNaming.ReverseIdlToClsNameMapping(clsType.Name),
                             valueMembers, baseTypeCode, CONCRETE_VALUE_MOD);
            return(result);
        }
Ejemplo n.º 19
0
		public void ValueMember_Can_CheckPrivacy() {
			var private_name_with_check = new ValueMember(_t.GetField("iname", BindingFlags.NonPublic | BindingFlags.Instance),
			                                              true);
			Assert.False(private_name_with_check.CanBeAssigned);
			Assert.False(private_name_with_check.CanBeRetrieved);
			var private_name_with_no_check = new ValueMember(
				_t.GetField("iname", BindingFlags.NonPublic | BindingFlags.Instance), false);
			Assert.True(private_name_with_no_check.CanBeAssigned);
			Assert.True(private_name_with_no_check.CanBeRetrieved);

			var PubRPrivW_with_check = new ValueMember(_t.GetProperty("PubRPrivW", BindingFlags.Public | BindingFlags.Instance),
			                                           true);
			Assert.False(PubRPrivW_with_check.CanBeAssigned);
			Assert.True(PubRPrivW_with_check.CanBeRetrieved);

			var PubRPrivW_with_no_check =
				new ValueMember(_t.GetProperty("PubRPrivW", BindingFlags.Public | BindingFlags.Instance), false);
			Assert.True(PubRPrivW_with_no_check.CanBeAssigned);
			Assert.True(PubRPrivW_with_no_check.CanBeRetrieved);
		}
Ejemplo n.º 20
0
        private int FindMyItemByValue(string value)
        {
            if (ItemStrings == null)
            {
                return(-1);
            }
            Object o;
            MyItem it;
            string s;

            int fk = m_MyItemFieldList.IndexOf(ValueMember.ToLower());

            if (fk == -1)
            {
                return(-1);
            }

            for (int i = 0; i < Items.Count; i++)
            {
                o = Items[i];
                if (o == null)
                {
                    continue;
                }
                it = o as MyItem;
                if (it == null)
                {
                    continue;
                }
                s = it.GetValue(fk);
                if (s == null)
                {
                    continue;
                }
                if (string.Compare(value, s, true) == 0)
                {
                    return(i);
                }
            }
            return(-1);
        }
Ejemplo n.º 21
0
 static void AddField(MetaType mt, ValueMember field)
 {
     try
     {
         var newField = mt.AddField(field.FieldNumber,
                                    field.Member?.Name ?? field.Name,
                                    field.ItemType,
                                    field.DefaultType);
         newField.DataFormat     = field.DataFormat;
         newField.IsMap          = field.IsMap;
         newField.IsPacked       = field.IsPacked;
         newField.IsRequired     = field.IsRequired;
         newField.IsStrict       = field.IsStrict;
         newField.DefaultValue   = field.DefaultValue;
         newField.MapKeyFormat   = field.MapKeyFormat;
         newField.MapValueFormat = field.MapValueFormat;
         newField.Name           = field.Name;
         newField.OverwriteList  = field.OverwriteList;
         // newField.SupportNull = field.SupportNull;
     } catch (Exception ex)
     {
         throw new InvalidOperationException($"Error adding field {field.Member?.Name}: {ex.Message}", ex);
     }
 }
Ejemplo n.º 22
0
        private void DataSourcedComboBox_TextChanged(object sender, EventArgs e)
        {
            if (!_detectinput)
            {
                return;
            }
            if (DataSource != null)
            {
                if (!string.IsNullOrEmpty(DisplayMember.RLTrim()))
                {
                    if (DataSource.Columns.Contains(DisplayMember))
                    {
                        DataTable _viewtable = DataSource.DefaultView.ToTable();
                        DataRow[] rws        = _viewtable.Select("CONVERT([" + DisplayMember + "], System.String) LIKE '" + Text.ToSqlValidString(true) + "'");
                        if (rws.Length > 0)
                        {
                            if (!string.IsNullOrEmpty(ValueMember.RLTrim()))
                            {
                                if (DataSource.Columns.Contains(ValueMember))
                                {
                                    C1FlexGrid _grid  = _dropdown.Grid;
                                    int        _index = _grid.FindRow(rws[0][ValueMember], _grid.Rows.Fixed, _grid.Cols.Fixed, false) - 1;
                                    _selectedindex = (_index < 0 ? -1 : _index);
                                    OnSelectedIndexChanged(new EventArgs());
                                    _selectedvalue = rws[0][ValueMember];
                                    OnSelectedValueChanged(new EventArgs());
                                }
                                else
                                {
                                    bool _changed = false;
                                    _changed       = (_selectedindex != -1);
                                    _selectedindex = -1;
                                    if (_changed)
                                    {
                                        OnSelectedIndexChanged(new EventArgs());
                                    }

                                    _changed       = (_selectedvalue != null);
                                    _selectedvalue = null;
                                    if (_changed)
                                    {
                                        OnSelectedValueChanged(new EventArgs());
                                    }
                                }
                            }
                            else
                            {
                                bool _changed = false;
                                _changed       = (_selectedindex != -1);
                                _selectedindex = -1;
                                if (_changed)
                                {
                                    OnSelectedIndexChanged(new EventArgs());
                                }

                                _changed       = (_selectedvalue != null);
                                _selectedvalue = null;
                                if (_changed)
                                {
                                    OnSelectedValueChanged(new EventArgs());
                                }
                            }
                        }
                        else
                        {
                            bool _changed = false;
                            _changed       = (_selectedindex != -1);
                            _selectedindex = -1;
                            if (_changed)
                            {
                                OnSelectedIndexChanged(new EventArgs());
                            }

                            _changed       = (_selectedvalue != null);
                            _selectedvalue = null;
                            if (_changed)
                            {
                                OnSelectedValueChanged(new EventArgs());
                            }
                        }
                        _viewtable.Dispose(); _viewtable = null;
                        Materia.RefreshAndManageCurrentProcess();
                    }
                    else
                    {
                        bool _changed = false;
                        _changed       = (_selectedindex != -1);
                        _selectedindex = -1;
                        if (_changed)
                        {
                            OnSelectedIndexChanged(new EventArgs());
                        }

                        _changed       = (_selectedvalue != null);
                        _selectedvalue = null;
                        if (_changed)
                        {
                            OnSelectedValueChanged(new EventArgs());
                        }
                    }
                }
                else
                {
                    bool _changed = false;
                    _changed       = (_selectedindex != -1);
                    _selectedindex = -1;
                    if (_changed)
                    {
                        OnSelectedIndexChanged(new EventArgs());
                    }

                    _changed       = (_selectedvalue != null);
                    _selectedvalue = null;
                    if (_changed)
                    {
                        OnSelectedValueChanged(new EventArgs());
                    }
                }
            }
            else
            {
                bool _changed = false;
                _changed       = (_selectedindex != -1);
                _selectedindex = -1;
                if (_changed)
                {
                    OnSelectedIndexChanged(new EventArgs());
                }

                _changed       = (_selectedvalue != null);
                _selectedvalue = null;
                if (_changed)
                {
                    OnSelectedValueChanged(new EventArgs());
                }
            }
        }
Ejemplo n.º 23
0
        internal string GetSchemaTypeName(Type effectiveType, DataFormat dataFormat, bool asReference, bool dynamicType, ref bool requiresBclImport)
        {
            Type tmp = Helpers.GetUnderlyingType(effectiveType);

            if (tmp != null)
            {
                effectiveType = tmp;
            }
            if (effectiveType == base.MapType(typeof(byte[])))
            {
                return("bytes");
            }
            WireType         wireType;
            IProtoSerializer ser = ValueMember.TryGetCoreSerializer(this, dataFormat, effectiveType, out wireType, false, false, false, false);

            if (ser == null)
            {
                if (asReference || dynamicType)
                {
                    requiresBclImport = true;
                    return("bcl.NetObjectProxy");
                }
                return(this[effectiveType].GetSurrogateOrBaseOrSelf(true).GetSchemaTypeName());
            }
            else
            {
                if (!(ser is ParseableSerializer))
                {
                    ProtoTypeCode typeCode = Helpers.GetTypeCode(effectiveType);
                    switch (typeCode)
                    {
                    case ProtoTypeCode.Boolean:
                        return("bool");

                    case ProtoTypeCode.Char:
                    case ProtoTypeCode.Byte:
                    case ProtoTypeCode.UInt16:
                    case ProtoTypeCode.UInt32:
                        if (dataFormat == DataFormat.FixedSize)
                        {
                            return("fixed32");
                        }
                        return("uint32");

                    case ProtoTypeCode.SByte:
                    case ProtoTypeCode.Int16:
                    case ProtoTypeCode.Int32:
                        switch (dataFormat)
                        {
                        case DataFormat.ZigZag:
                            return("sint32");

                        case DataFormat.FixedSize:
                            return("sfixed32");
                        }
                        return("int32");

                    case ProtoTypeCode.Int64:
                        switch (dataFormat)
                        {
                        case DataFormat.ZigZag:
                            return("sint64");

                        case DataFormat.FixedSize:
                            return("sfixed64");
                        }
                        return("int64");

                    case ProtoTypeCode.UInt64:
                        if (dataFormat == DataFormat.FixedSize)
                        {
                            return("fixed64");
                        }
                        return("uint64");

                    case ProtoTypeCode.Single:
                        return("float");

                    case ProtoTypeCode.Double:
                        return("double");

                    case ProtoTypeCode.Decimal:
                        requiresBclImport = true;
                        return("bcl.Decimal");

                    case ProtoTypeCode.DateTime:
                        requiresBclImport = true;
                        return("bcl.DateTime");

                    case (ProtoTypeCode)17:
                        break;

                    case ProtoTypeCode.String:
                        if (asReference)
                        {
                            requiresBclImport = true;
                        }
                        if (!asReference)
                        {
                            return("string");
                        }
                        return("bcl.NetObjectProxy");

                    default:
                        switch (typeCode)
                        {
                        case ProtoTypeCode.TimeSpan:
                            requiresBclImport = true;
                            return("bcl.TimeSpan");

                        case ProtoTypeCode.Guid:
                            requiresBclImport = true;
                            return("bcl.Guid");
                        }
                        break;
                    }
                    throw new NotSupportedException("No .proto map found for: " + effectiveType.FullName);
                }
                if (asReference)
                {
                    requiresBclImport = true;
                }
                if (!asReference)
                {
                    return("string");
                }
                return("bcl.NetObjectProxy");
            }
        }
Ejemplo n.º 24
0
 public CommandParameterInfo(string ParameterName, ValueMember Accessor)
 {
     this.ParameterName = ParameterName;
     this.Accessor      = Accessor;
 }
Ejemplo n.º 25
0
        public override string GetSchema(Type type)
        {
            BasicList requiredTypes = new BasicList();
            MetaType  primaryType   = null;
            bool      isInbuiltType = false;

            if (type == null)
            {
                BasicList.NodeEnumerator enumerator = this.types.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    MetaType meta = (MetaType)enumerator.Current;
                    MetaType tmp  = meta.GetSurrogateOrBaseOrSelf(false);
                    if (!requiredTypes.Contains(tmp))
                    {
                        requiredTypes.Add(tmp);
                        this.CascadeDependents(requiredTypes, tmp);
                    }
                }
            }
            else
            {
                Type tmp2 = Helpers.GetUnderlyingType(type);
                if (tmp2 != null)
                {
                    type = tmp2;
                }
                WireType defaultWireType;
                isInbuiltType = (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type, out defaultWireType, false, false, false, false) != null);
                if (!isInbuiltType)
                {
                    int index = this.FindOrAddAuto(type, false, false, false);
                    if (index < 0)
                    {
                        throw new ArgumentException("The type specified is not a contract-type", "type");
                    }
                    primaryType = ((MetaType)this.types[index]).GetSurrogateOrBaseOrSelf(false);
                    requiredTypes.Add(primaryType);
                    this.CascadeDependents(requiredTypes, primaryType);
                }
            }
            StringBuilder headerBuilder = new StringBuilder();
            string        package       = null;

            if (!isInbuiltType)
            {
                IEnumerable typesForNamespace = (primaryType == null) ? this.types : requiredTypes;
                foreach (MetaType meta2 in typesForNamespace)
                {
                    if (!meta2.IsList)
                    {
                        string tmp3 = meta2.Type.Namespace;
                        if (!Helpers.IsNullOrEmpty(tmp3) && !tmp3.StartsWith("System."))
                        {
                            if (package == null)
                            {
                                package = tmp3;
                            }
                            else
                            {
                                if (!(package == tmp3))
                                {
                                    package = null;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            if (!Helpers.IsNullOrEmpty(package))
            {
                headerBuilder.Append("package ").Append(package).Append(';');
                Helpers.AppendLine(headerBuilder);
            }
            bool          requiresBclImport = false;
            StringBuilder bodyBuilder       = new StringBuilder();

            MetaType[] metaTypesArr = new MetaType[requiredTypes.Count];
            requiredTypes.CopyTo(metaTypesArr, 0);
            Array.Sort <MetaType>(metaTypesArr, MetaType.Comparer.Default);
            if (isInbuiltType)
            {
                Helpers.AppendLine(bodyBuilder).Append("message ").Append(type.Name).Append(" {");
                MetaType.NewLine(bodyBuilder, 1).Append("optional ").Append(this.GetSchemaTypeName(type, DataFormat.Default, false, false, ref requiresBclImport)).Append(" value = 1;");
                Helpers.AppendLine(bodyBuilder).Append('}');
            }
            else
            {
                for (int i = 0; i < metaTypesArr.Length; i++)
                {
                    MetaType tmp4 = metaTypesArr[i];
                    if (!tmp4.IsList || tmp4 == primaryType)
                    {
                        tmp4.WriteSchema(bodyBuilder, 0, ref requiresBclImport);
                    }
                }
            }
            if (requiresBclImport)
            {
                headerBuilder.Append("import \"bcl.proto\"; // schema for protobuf-net's handling of core .NET types");
                Helpers.AppendLine(headerBuilder);
            }
            return(Helpers.AppendLine(headerBuilder.Append(bodyBuilder)).ToString());
        }
Ejemplo n.º 26
0
        internal IProtoSerializer TryGetBasicTypeSerializer(Type type)
        {
            int idx = this.basicTypes.IndexOf(RuntimeTypeModel.BasicTypeFinder, type);

            if (idx >= 0)
            {
                return(((RuntimeTypeModel.BasicType) this.basicTypes[idx]).Serializer);
            }
            IProtoSerializer result;

            lock (this.basicTypes)
            {
                idx = this.basicTypes.IndexOf(RuntimeTypeModel.BasicTypeFinder, type);
                if (idx >= 0)
                {
                    result = ((RuntimeTypeModel.BasicType) this.basicTypes[idx]).Serializer;
                }
                else
                {
                    MetaType.AttributeFamily family = MetaType.GetContractFamily(this, type, null);
                    WireType         defaultWireType;
                    IProtoSerializer ser = (family == MetaType.AttributeFamily.None) ? ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type, out defaultWireType, false, false, false, false) : null;
                    if (ser != null)
                    {
                        this.basicTypes.Add(new RuntimeTypeModel.BasicType(type, ser));
                    }
                    result = ser;
                }
            }
            return(result);
        }
Ejemplo n.º 27
0
 public static MemberHelper <TContainer> Create(ValueMember member) => (MemberHelper <TContainer>)(
     typeof(TContainer).IsValueType ?
     Activator.CreateInstance(typeof(StructMemberHelper <,>).MakeGenericType(typeof(TContainer), member.MemberType), member) :
     Activator.CreateInstance(typeof(ClassMemberHelper <,>).MakeGenericType(typeof(TContainer), member.MemberType), member));
Ejemplo n.º 28
0
 public static ValueMember MakeDynamicType(this ValueMember member)
 {
     member.DynamicType = true;
     return(member);
 }
Ejemplo n.º 29
0
 public StructMemberHelper(ValueMember member)
 {
     _getter = BuildGetter(member);
     _setter = BuildSetter(member);
 }
Ejemplo n.º 30
0
 private void CascadeDependents(BasicList list, MetaType metaType)
 {
     if (metaType.IsList)
     {
         Type     itemType = TypeModel.GetListItemType(this, metaType.Type);
         WireType defaultWireType;
         if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, itemType, out defaultWireType, false, false, false, false) == null)
         {
             int index = this.FindOrAddAuto(itemType, false, false, false);
             if (index >= 0)
             {
                 MetaType tmp = ((MetaType)this.types[index]).GetSurrogateOrBaseOrSelf(false);
                 if (!list.Contains(tmp))
                 {
                     list.Add(tmp);
                     this.CascadeDependents(list, tmp);
                     return;
                 }
             }
         }
     }
     else
     {
         MetaType tmp;
         if (metaType.IsAutoTuple)
         {
             MemberInfo[] mapping;
             if (MetaType.ResolveTupleConstructor(metaType.Type, out mapping) != null)
             {
                 for (int i = 0; i < mapping.Length; i++)
                 {
                     Type type = null;
                     if (mapping[i] is PropertyInfo)
                     {
                         type = ((PropertyInfo)mapping[i]).PropertyType;
                     }
                     else
                     {
                         if (mapping[i] is FieldInfo)
                         {
                             type = ((FieldInfo)mapping[i]).FieldType;
                         }
                     }
                     WireType defaultWireType2;
                     if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type, out defaultWireType2, false, false, false, false) == null)
                     {
                         int index2 = this.FindOrAddAuto(type, false, false, false);
                         if (index2 >= 0)
                         {
                             tmp = ((MetaType)this.types[index2]).GetSurrogateOrBaseOrSelf(false);
                             if (!list.Contains(tmp))
                             {
                                 list.Add(tmp);
                                 this.CascadeDependents(list, tmp);
                             }
                         }
                     }
                 }
             }
         }
         else
         {
             foreach (ValueMember member in metaType.Fields)
             {
                 Type type2 = member.ItemType;
                 if (type2 == null)
                 {
                     type2 = member.MemberType;
                 }
                 WireType defaultWireType3;
                 if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type2, out defaultWireType3, false, false, false, false) == null)
                 {
                     int index3 = this.FindOrAddAuto(type2, false, false, false);
                     if (index3 >= 0)
                     {
                         tmp = ((MetaType)this.types[index3]).GetSurrogateOrBaseOrSelf(false);
                         if (!list.Contains(tmp))
                         {
                             list.Add(tmp);
                             this.CascadeDependents(list, tmp);
                         }
                     }
                 }
             }
         }
         if (metaType.HasSubtypes)
         {
             SubType[] subtypes = metaType.GetSubtypes();
             for (int j = 0; j < subtypes.Length; j++)
             {
                 SubType subType = subtypes[j];
                 tmp = subType.DerivedType.GetSurrogateOrSelf();
                 if (!list.Contains(tmp))
                 {
                     list.Add(tmp);
                     this.CascadeDependents(list, tmp);
                 }
             }
         }
         tmp = metaType.BaseType;
         if (tmp != null)
         {
             tmp = tmp.GetSurrogateOrSelf();
         }
         if (tmp != null && !list.Contains(tmp))
         {
             list.Add(tmp);
             this.CascadeDependents(list, tmp);
         }
     }
 }