예제 #1
0
        public static IEnumerable<Type> GetTypes(object obj)
        {
            if (obj.GetType().GetTypeInfo().IsPrimitive)
            {
                return new List<Type>() { obj.GetType() };
            }

            TypeDetector td = new TypeDetector(obj);
            td.myTypes = new List<Type>() { obj.GetType() };
            td.FindTypes(obj.GetType());
            return td.myTypes;
        }
예제 #2
0
        public static IEnumerable <Type> GetTypes(object obj)
        {
            if (obj.GetType().GetTypeInfo().IsPrimitive)
            {
                return(new List <Type>()
                {
                    obj.GetType()
                });
            }

            TypeDetector td = new TypeDetector(obj);

            td.myTypes = new List <Type>()
            {
                obj.GetType()
            };
            td.FindTypes(obj.GetType());
            return(td.myTypes);
        }
예제 #3
0
        // ''' <summary>
        // ''' Erstellt eine vollständige Kopie (deep clone) dieser Instanz.
        // ''' </summary>
        // ''' <typeparam name="bbType"></typeparam>
        // ''' <returns></returns>
        // ''' <remarks></remarks>
        public bbType DeepClone <bbType>()
        {
            MemoryStream memStream    = new MemoryStream();
            var          js           = new System.Runtime.Serialization.Json.DataContractJsonSerializer(this.GetType(), TypeDetector.GetTypes(this));
            bbType       clonedObject = default(bbType);

            //Als JSon in den Speicher serialisieren
            try
            {
                js.WriteObject(memStream, this);
            }
            catch
            {
                throw;
            }

            //Die Kopie wieder zurückserialisieren.
            try
            {
                memStream.Seek(0, SeekOrigin.Begin);
                clonedObject = (bbType)js.ReadObject(memStream);
            }
            catch
            {
                throw;
            }

            return(clonedObject);
        }