public void Test(NonGeneric c)
 {
     foreach (object?item in c)
     {
         Console.WriteLine(item);
     }
 }
Exemple #2
0
            /// <summary>
            /// Deserialize object of unknown types from in input stream.
            /// </summary>
            /// <param name="source">The input stream.</param>
            /// <param name="style">The prefix style used to encode the lengths.</param>
            /// <param name="typeReader">The caller must provide a mechanism to resolve a Type from
            /// the tags encountered in the stream. If the delegate returns null, then the instance
            /// is skipped - otherwise, the object is deserialized according to type.</param>
            /// <param name="item">The deserialized instance, or null if the stream terminated.</param>
            /// <returns>True if an object was idenfified; false if the stream terminated. Note
            /// that unexpected types are skipped.</returns>
            public static bool TryDeserializeWithLengthPrefix(Stream source, PrefixStyle style,
                                                              Getter <int, Type> typeReader, out object item)
            {
                uint len;
                Type itemType = null;
                Getter <int, bool> processField = null;

                if (typeReader != null)
                {
                    processField = delegate(int checkTag)
                    {
                        itemType = typeReader(checkTag);
                        return(itemType != null);
                    }
                }
                ;
                if (!Serializer.TryReadPrefixLength(source, style, 1, out len, processField))
                {
                    item = null;
                    return(false);
                }

                if (len == uint.MaxValue)
                {
                    item = NonGeneric.Deserialize(itemType, source);
                }
                else
                {
                    using (SubStream subStream = new SubStream(source, len, false))
                    {
                        item = NonGeneric.Deserialize(itemType, subStream);
                    }
                }
                return(true);
            }
 public static void Main(string[] args)
 {
     var obj = new NonGeneric();
     var mi = typeof(INonGeneric).GetMethod("InstanceMethod");
     mi.Invoke(obj, new object[] { });
     var action = (Action)Delegate.CreateDelegate(typeof(Action), obj, mi);
     action();
 }
Exemple #4
0
 public Constructors(
     int capacity,
     NonGeneric nonGeneric,
     SimpleGeneric <List <int> > simple,
     MultipleGenerics <int, string, Guid> multiple,
     T complex)
 {
 }
Exemple #5
0
 public object Deserialize(Stream input, Type objectType)
 {
     if (_useCompression)
     {
         return(NonGeneric.Deserialize(objectType, input, _formatterResolver));
     }
     return(NonGeneric.Deserialize(objectType, input, _formatterResolver));
 }
    public static void Main(string[] args)
    {
        var obj = new NonGeneric();
        var mi  = typeof(INonGeneric).GetMethod("InstanceMethod");

        mi.Invoke(obj, new object[] { });
        var action = (Action)Delegate.CreateDelegate(typeof(Action), obj, mi);

        action();
    }
Exemple #7
0
 public void Serialize(object data, Stream output)
 {
     if (_useCompression)
     {
         NonGeneric.Serialize(data.GetType(), output, data, _formatterResolver);
     }
     else
     {
         NonGeneric.Serialize(data.GetType(), output, data, _formatterResolver);
     }
 }
 //[MethodImpl(MethodImplOptions.AggressiveInlining)]
 public bool TryRead <T>(ref T t, uint from)
 {
     if (typeof(T) == typeof(A))
     {
         return(NonGeneric.TryRead(ref Unsafe.As <T, A>(ref t), from));
     }
     else if (typeof(T) == typeof(B))
     {
         return(NonGeneric.TryRead(ref Unsafe.As <T, B>(ref t), from));
     }
     else
     {
         throw new InvalidCastException();
     }
 }
Exemple #9
0
        public static void Run()
        {
            if (Gen2 <string> .GetFromClassParam() != "Hello")
            {
                throw new Exception();
            }

            if (Gen2 <string> .GetFromMethodParam() != "World")
            {
                throw new Exception();
            }

            if (NonGeneric.Get <object>(new object[0]) != "Hi there")
            {
                throw new Exception();
            }
        }
        public byte[] Serialize(object obj)
        {
            if (obj == null)
            {
                return(null);
            }
            using (MemoryStream ms = new MemoryStream())
            {
                //ProtoBuf.Serializer.Serialize<T>(ms, obj);
                NonGeneric.Serialize(ms, obj);
                byte[] result = new byte[ms.Length];

                ms.Position = 0;
                //将流中的内容读取到二进制数组中
                ms.Read(result, 0, result.Length);
                return(result);
            }
        }
Exemple #11
0
 public Generic <int> GenericMethod_LocalTypeNestedInRuntimeType()
 {
     return(NonGeneric.GenericReturnNestedLocal <int>());
 }
Exemple #12
0
 public T GenericMethod_TypeDefinedByTestMethod <T>(T value)
 {
     return(NonGeneric.GenericReturn(value));
 }
Exemple #13
0
 public int GenericMethod_TypeDefinedByArgument()
 {
     return(NonGeneric.GenericReturn(5));
 }
Exemple #14
0
 public void GenericVoidMethod_RuntimeType()
 {
     NonGeneric.GenericVoid <int>();
 }
Exemple #15
0
 public static void Main(string[] args)
 {
     NonGeneric dummy = new NonGeneric <string> ();
 }
Exemple #16
0
	public static void Main (string[] args)
	{
		NonGeneric dummy = new NonGeneric<string> ();
	}
    public static void Main(string[] args)
    {
        Console.WriteLine(Class1.GetGenericMethodInfo() == Class2.GetGenericMethodInfo() ? "true" : "false");

        var mi = typeof(Program).GetMethod("StaticGenericMethod").MakeGenericMethod(new[] { typeof(string) });

        mi.Invoke(null, new object[] { "TestString4" });
        var actionStr = (Action <string>)Delegate.CreateDelegate(typeof(Action <string>), null, mi);

        actionStr("TestString5");

        mi = typeof(Program).GetMethod("StaticGenericMethod").MakeGenericMethod(new[] { typeof(int) });
        mi.Invoke(null, new object[] { 6 });
        var actionInt = (Action <int>)Delegate.CreateDelegate(typeof(Action <int>), null, mi);

        actionInt(7);

        object obj = new NonGeneric();

        mi = typeof(NonGeneric).GetMethod("InstanceGenericMethod").MakeGenericMethod(new[] { typeof(string) });
        mi.Invoke(obj, new object[] { "TestString1" });
        actionStr = (Action <string>)Delegate.CreateDelegate(typeof(Action <string>), obj, mi);
        actionStr("TestString2");

        mi = typeof(NonGeneric).GetMethod("InstanceGenericMethod").MakeGenericMethod(new[] { typeof(int) });
        mi.Invoke(obj, new object[] { 3 });
        actionInt = (Action <int>)Delegate.CreateDelegate(typeof(Action <int>), obj, mi);
        actionInt(4);

        obj = new Generic <int>();
        mi  = typeof(Generic <int>).GetMethod("InstanceGenericMethod").MakeGenericMethod(new[] { typeof(string) });
        mi.Invoke(obj, new object[] { "TestString8" });
        actionStr = (Action <string>)Delegate.CreateDelegate(typeof(Action <string>), obj, mi);
        actionStr("TestString9");

        mi = typeof(Generic <int>).GetMethod("InstanceGenericMethod").MakeGenericMethod(new[] { typeof(int) });
        mi.Invoke(obj, new object[] { 10 });
        actionInt = (Action <int>)Delegate.CreateDelegate(typeof(Action <int>), obj, mi);
        actionInt(11);

        obj = new NonGeneric();
        mi  = typeof(INonGeneric).GetMethod("InstanceGenericMethod").MakeGenericMethod(new[] { typeof(string) });
        mi.Invoke(obj, new object[] { "TestString12" });
        actionStr = (Action <string>)Delegate.CreateDelegate(typeof(Action <string>), obj, mi);
        actionStr("TestString13");

        mi = typeof(INonGeneric).GetMethod("InstanceGenericMethod").MakeGenericMethod(new[] { typeof(int) });
        mi.Invoke(obj, new object[] { 14 });
        actionInt = (Action <int>)Delegate.CreateDelegate(typeof(Action <int>), obj, mi);
        actionInt(15);

        obj = new Generic <string>();
        mi  = typeof(INonGeneric).GetMethod("InstanceGenericMethod").MakeGenericMethod(new[] { typeof(string) });
        mi.Invoke(obj, new object[] { "TestString16" });
        actionStr = (Action <string>)Delegate.CreateDelegate(typeof(Action <string>), obj, mi);
        actionStr("TestString17");

        mi = typeof(INonGeneric).GetMethod("InstanceGenericMethod").MakeGenericMethod(new[] { typeof(int) });
        mi.Invoke(obj, new object[] { 18 });
        actionInt = (Action <int>)Delegate.CreateDelegate(typeof(Action <int>), obj, mi);
        actionInt(19);

        mi = typeof(IGeneric <string>).GetMethod("InstanceGenericMethod").MakeGenericMethod(new[] { typeof(string) });
        mi.Invoke(obj, new object[] { "TestString20" });
        actionStr = (Action <string>)Delegate.CreateDelegate(typeof(Action <string>), obj, mi);
        actionStr("TestString21");

        mi = typeof(IGeneric <string>).GetMethod("InstanceGenericMethod").MakeGenericMethod(new[] { typeof(int) });
        mi.Invoke(obj, new object[] { 22 });
        actionInt = (Action <int>)Delegate.CreateDelegate(typeof(Action <int>), obj, mi);
        actionInt(23);
    }
 /// <summary>
 /// Precompiles the serializer for a given type.
 /// </summary>
 public static void PrepareSerializer <T>()
 {
     NonGeneric.PrepareSerializer(typeof(T));
 }
Exemple #19
0
 public void GenericVoidMethod_LocalType()
 {
     NonGeneric.GenericVoid <LocalClass>();
 }