Exemplo n.º 1
0
    public static void Main()
    {
        test_is();

        DerivedType derivedObj = new DerivedType();
        BaseType baseObj1 = new BaseType();
        BaseType baseObj2 = derivedObj;

        DerivedType derivedObj2 = baseObj2 as DerivedType;
        if( derivedObj2 != null ) {
            Console.WriteLine( "Conversion Succeeded" );
        } else {
            Console.WriteLine( "Conversion Failed" );
        }

        derivedObj2 = baseObj1 as DerivedType;
        if( derivedObj2 != null ) {
            Console.WriteLine( "Conversion Succeeded" );
        } else {
            Console.WriteLine( "Conversion Failed" );
        }

        BaseType baseObj3 = derivedObj as BaseType;
        if( baseObj3 != null ) {
            Console.WriteLine( "Conversion Succeeded" );
        } else {
            Console.WriteLine( "Conversion Failed" );
        }

        System.Console.WriteLine("Press any key to continue...");
        System.Console.ReadKey();
    }
        public void Should_allow_hierarchy_conversion_for_parameter()
        {
            var func  = CreateFunc <DerivedType, BaseType>(Expr.Return(Expr.Parameter(0, typeof(BaseType))));
            var value = new DerivedType();

            Assert.That(func(value), Is.SameAs(value));
        }
Exemplo n.º 3
0
        public virtual List <string> GetFields()
        {
            List <string> fields = new List <string>();

            PropertyInfo[] propertyArray = DerivedType.GetProperties();

            if (StartFromProperty < 0 || StartFromProperty > propertyArray.Count())
            {
                Log.LogError("startFrom is not in range.");
                return(fields);
            }

            if (EndToProperty < 0)
            {
                EndToProperty = propertyArray.Count();
            }

            if (EndToProperty > propertyArray.Count())
            {
                Log.LogError("endTo is not in range.");
                return(fields);
            }

            for (int i = StartFromProperty; i < EndToProperty; i++)
            {
                PropertyInfo property = propertyArray[i];
                fields.Add(property.Name);
            }

            return(fields);
        }
        public void Should_cast_to_derived_type()
        {
            BaseType    baseType = new DerivedType();
            DerivedType casted   = CreateConvertFunc <BaseType, DerivedType>().Invoke(baseType);

            Assert.That(casted, Is.SameAs(baseType));
        }
        public void ToHashSet_NullSelector_Exception()
        {
            IEnumerable <DerivedType> a        = new DerivedType[0];
            Func <DerivedType, int>   selector = null;

            Assert.That(() => a.ToHashSet(selector), Throws.InstanceOf <ArgumentNullException>());
        }
Exemplo n.º 6
0
        public void PolymorphicRoot([Values] RecorderMode mode)
        {
            BaseType root         = new DerivedType();
            var      deserialized = DoRecorderRoundTrip(root, mode);

            Assert.AreEqual(root.GetType(), deserialized.GetType());
        }
        public void Should_allow_comparison_of_the_same_class_hierarchy()
        {
            var val = new DerivedType();

            Assert.That(IsEqual <BaseType, DerivedType>(val, val), Is.EqualTo(true));
            Assert.That(IsEqual(new BaseType(), new DerivedType()), Is.EqualTo(false));
        }
        public void Should_cast_to_base_type()
        {
            var      derivedType = new DerivedType();
            BaseType casted      = CreateConvertFunc <DerivedType, BaseType>().Invoke(derivedType);

            Assert.That(casted, Is.SameAs(derivedType));
        }
        public void TestContainsKey_PropertyInherited_ReturnsTrue()
        {
            BaseType           b          = new DerivedType();
            PropertyDictionary dictionary = new PropertyDictionary(b);
            bool result = dictionary.ContainsKey("Inherited");

            Assert.IsTrue(result, "The property name was not found.");
        }
Exemplo n.º 10
0
            public void OfType_WhenAssignable_ReturnsSomeOfAssignedType()
            {
                Option <DerivedType> derived = new DerivedType();

                var result = derived.OfType <SuperType>();

                result.Should().BeOfType <Some <SuperType> >();
            }
Exemplo n.º 11
0
 public static void TestDCast_isinst()
 {
     BaseType TestDerivedType = new DerivedType();
     for (int x = 0; x < Iterations; x++)
     {
         (TestDerivedType as DerivedType).TestDerivedMethod();
     }
 }
Exemplo n.º 12
0
            public void InitializesNewInstanceForDerivedInstanceMember()
            {
                var derived = new DerivedType();

                var sut = new InstanceMember(info, derived);

                Assert.Same(info, sut.Info);
                Assert.Same(derived, sut.Instance);
            }
Exemplo n.º 13
0
            public void Equals_SomesWithDifferentTypes_AreUnequal()
            {
                var derived = new DerivedType();
                Option <SuperType>   superSome   = derived;
                Option <DerivedType> derivedSome = derived;

                superSome.Should().NotBeEquivalentTo(derivedSome);
                derivedSome.Should().NotBeEquivalentTo(superSome);
            }
Exemplo n.º 14
0
    public static void TestDCast_castclass()
    {
        BaseType TestDerivedType = new DerivedType();

        for (int x = 0; x < Iterations; x++)
        {
            ((DerivedType)TestDerivedType).TestDerivedMethod();
        }
    }
Exemplo n.º 15
0
        private void CastClass()
        {
            DerivedType derivedType1_1 = new DerivedType();
            BaseType    base1          = derivedType1_1;
            DerivedType derivedType1_2 = (DerivedType)base1;

            DerivedType2 derivedType2_1 = new DerivedType2();
            BaseType     base2          = derivedType2_1;
            DerivedType2 derivedType2_2 = (DerivedType2)base2;
        }
Exemplo n.º 16
0
 public static void TestMuliCast_3x()
 {
     BaseType TestBaseType = new DerivedType();
     for (int x = 0; x < Iterations; x++)
     {
         ((DerivedType)TestBaseType).TestDerivedMethod();
         ((DerivedType)TestBaseType).TestDerivedMethod2();
         ((DerivedType)TestBaseType).TestDerivedMethod3();
     }
 }
Exemplo n.º 17
0
 public static void TestSingleCast_3x()
 {
     BaseType TestBaseType = new DerivedType();
     for (int x = 0; x < Iterations; x++)
     {
         DerivedType TestDerivedType = (DerivedType)TestBaseType;
         TestDerivedType.TestDerivedMethod();
         TestDerivedType.TestDerivedMethod2();
         TestDerivedType.TestDerivedMethod3();
     }
 }
            public override object CreateResource(string containerName, string fullTypeName)
            {
                if (containerName == "Entities")
                {
                    if (fullTypeName == DerivedTypeName)
                    {
                        var instance = new DerivedType();
                        return(this.CreateToken(instance));
                    }
                }

                return(base.CreateResource(containerName, fullTypeName));
            }
Exemplo n.º 19
0
        protected override void ProcessRecord()
        {
            if (this.MyInvocation.BoundParameters.ContainsKey("InputObject"))
            {
                BaseType = InputObject is Type type
                    ? type.FullName
                    : InputObject.GetType().FullName;
            }

            IEnumerable <Type> derivedTypes = DerivedType.GetDerivedTypes(BaseType, asses, Recurse.ToBool());

            WriteObject(derivedTypes, true);
        }
Exemplo n.º 20
0
 public static void TestMuliCast_30x()
 {
     BaseType TestBaseType = new DerivedType();
     for (int x = 0; x < Iterations; x++)
     {
         //Simulate 3 x 10 method calls while casting
         for (int y = 0; y < 10; y++) {
             ((DerivedType)TestBaseType).TestDerivedMethod();
             ((DerivedType)TestBaseType).TestDerivedMethod2();
             ((DerivedType)TestBaseType).TestDerivedMethod3();
         }
     }
 }
Exemplo n.º 21
0
        public void DerivedConverterTest([ValuesExcept(RecorderMode.Validation)] RecorderMode mode)
        {
            Dec.Config.TestParameters = new Dec.Config.UnitTestParameters {
                explicitConverters = new Type[] { typeof(DerivedConverter) }
            };

            // we're only doing this to kick off the converter init
            new Dec.Parser().Finish();

            BaseType root         = new DerivedType();
            var      deserialized = DoRecorderRoundTrip(root, mode);

            Assert.AreEqual(root.GetType(), deserialized.GetType());
        }
Exemplo n.º 22
0
 public static void TestSingleCast_30x()
 {
     BaseType TestBaseType = new DerivedType();
     for (int x = 0; x < Iterations; x++)
     {
         DerivedType TestDerivedType = (DerivedType)TestBaseType;
         
         //Simulate 3 x 10 method calls on already-cast object
         for (int y = 0; y < 10; y++)
         {
             TestDerivedType.TestDerivedMethod();
             TestDerivedType.TestDerivedMethod2();
             TestDerivedType.TestDerivedMethod3();
         }
     }
 }
Exemplo n.º 23
0
        public void IncomingParameterMatchesOverridenParameter_ThatDoesNotHasAttribute()
        {
            // Test for https://github.com/dotnet/aspnetcore/issues/13162
            // Arrange
            var parameters = new ParameterViewBuilder
            {
                { nameof(DerivedType.VirtualProp), 123 },
            }.Build();
            var target = new DerivedType();

            // Act
            parameters.SetParameterProperties(target);

            // Assert
            Assert.Equal(123, target.VirtualProp);
        }
Exemplo n.º 24
0
 private void AddDerived(string originalId, ReqTable.RequirementRow row, DerivedType type)
 {
     if (!derivedRequirements.ContainsKey(originalId))
     {
         DerivedRequirement originalReq
             = new DerivedRequirement(originalId, CoveredStatus.Unverified);
         originalReq.AddDerivedRequirement(row.REQ_ID, type);
         derivedRequirements.Add(originalId, originalReq);
     }
     else
     {
         if (!derivedRequirements[originalId].DerivedReqs.ContainsKey(row.REQ_ID))
         {
             DerivedRequirement originalReq = derivedRequirements[originalId];
             originalReq.AddDerivedRequirement(row.REQ_ID, type);
             derivedRequirements[originalId] = originalReq;
         }
     }
 }
Exemplo n.º 25
0
 /// <summary>
 /// Add child requirement.
 /// </summary>
 /// <param name="reqID">The requirement ID.</param>
 /// <param name="type">The derived requirement type.</param>
 public void AddDerivedRequirement(string reqID, DerivedType type)
 {
     //self loop
     if (reqID == this.id)
     {
         throw new InvalidOperationException("Found loop in the derived requirements: " + reqID + " is derived from itself.");
     }
     if (!derivedReqs.ContainsKey(reqID))
     {
         derivedReqs.Add(reqID, type);
     }
     else
     {
         if (ReportingLog.Log != null)
         {
             ReportingLog.Log.TraceWarning(
                 string.Format("Found duplicate derived requirement {0} in requirement {1}.", reqID, id));
         }
         derivedReqs[reqID] = type;
     }
 }
Exemplo n.º 26
0
    static void Main()
    {
        DerivedType derivedObj = new DerivedType();
        BaseType    baseObj1   = new BaseType();
        BaseType    baseObj2   = derivedObj;

        DerivedType derivedObj2 = baseObj2 as DerivedType;

        if (derivedObj2 != null)
        {
            Console.WriteLine("Conversion Succeeded");
        }
        else
        {
            Console.WriteLine("Conversion Failed");
        }

        derivedObj2 = baseObj1 as DerivedType;
        if (derivedObj2 != null)
        {
            Console.WriteLine("Conversion Succeeded");
        }
        else
        {
            Console.WriteLine("Conversion Failed");
        }

        BaseType baseObj3 = derivedObj as BaseType;

        if (baseObj3 != null)
        {
            Console.WriteLine("Conversion Succeeded");
        }
        else
        {
            Console.WriteLine("Conversion Failed");
        }
    }
Exemplo n.º 27
0
 public DerivedType EchoDerivedType([FromUri] DerivedType input)
 {
     return(input);
 }
    static void Main(string[] args)
    {
        DerivedType d = new DerivedType();

        d = d.Save();
    }
Exemplo n.º 29
0
 public DerivedType EchoDerivedType(DerivedType param_DerivedType)
 {
     return param_DerivedType;
 }
 public static int[] SomeArray(DerivedType type)
 {
     return(SomeDict[type]);
 }
Exemplo n.º 31
0
 public DerivedValue(DerivedType type)
 {
     Type           = type;
     AddressRecords = new List <AddressRecord>();
 }
Exemplo n.º 32
0
 private void AddDerived(string originalId, ReqTable.RequirementRow row, DerivedType type)
 {
     if (!derivedRequirements.ContainsKey(originalId))
     {
         DerivedRequirement originalReq
             = new DerivedRequirement(originalId, CoveredStatus.Unverified);
         originalReq.AddDerivedRequirement(row.REQ_ID, type);
         derivedRequirements.Add(originalId, originalReq);
     }
     else
     {
         if (!derivedRequirements[originalId].DerivedReqs.ContainsKey(row.REQ_ID))
         {
             DerivedRequirement originalReq = derivedRequirements[originalId];
             originalReq.AddDerivedRequirement(row.REQ_ID, type);
             derivedRequirements[originalId] = originalReq;
         }
     }
 }
Exemplo n.º 33
0
 public static void Main (string[] args) {
     var t = new DerivedType();
     Console.WriteLine(t.Prop);
 }
Exemplo n.º 34
0
 public void Bad2(string x, DerivedType y)
 {
     Console.WriteLine("Base: {0}, {1}", x, y);
 }
Exemplo n.º 35
0
 bool Equals(DerivedType other) => string.Equals(TypeName, other.TypeName) && string.Equals(ParameterName, other.ParameterName) && string.Equals(EnumMember, other.EnumMember);
 /// <summary>
 /// Add child requirement.
 /// </summary>
 /// <param name="reqID">The requirement ID.</param>
 /// <param name="type">The derived requirement type.</param>
 public void AddDerivedRequirement(string reqID, DerivedType type)
 {
     //self loop
     if (reqID == this.id)
     {
         throw new InvalidOperationException("Found loop in the derived requirements: " + reqID + " is derived from itself.");
     }
     if (!derivedReqs.ContainsKey(reqID))
     {
         derivedReqs.Add(reqID, type);
     }
     else
     {
         if (ReportingLog.Log != null)
         {
             ReportingLog.Log.TraceWarning(
                 string.Format("Found duplicate derived requirement {0} in requirement {1}.", reqID, id));
         }
         derivedReqs[reqID] = type;
     }
 }
 public DerivedType[] ReverseDerivedTypeArray(DerivedType[] param_DerivedType)
 {
     if (param_DerivedType == null)
     {
         return null;
     }
     return param_DerivedType.Reverse().ToArray();
 }