Ejemplo n.º 1
0
        static DynamicAssembly()
        {
            AssBuilder =
                VersionDifferences.DefineDynamicAssembly(
                    new AssemblyName(AssName),
                    Access);

            ModBuilder = AssBuilder.DefineDynamicModule(
                AssName);
        }
        public static void SerializeObject <T>(T value, TextWriter textWriter, JsonFormatterOptions options)
        {
            using (var jsonSerializer = CreateJsonSerializer(options))
            {
                ValueInterface <T> .WriteValue((IValueWriter)jsonSerializer, value);

                VersionDifferences.WriteChars(
                    textWriter,
                    jsonSerializer.hGlobal.GetPointer(),
                    jsonSerializer.StringLength);
            }
        }
Ejemplo n.º 3
0
        public static async Task SerializeObjectAsync <T>(T value, TextWriter textWriter, JsonFormatterOptions options)
        {
            using (var jsonSerializer = CreateJsonSerializer(options))
            {
                ValueInterface <T> .WriteValue((IValueWriter)jsonSerializer, value);

                await VersionDifferences.WriteCharsAsync(
                    textWriter,
                    jsonSerializer.hGlobal.Address,
                    jsonSerializer.StringLength);
            }
        }
Ejemplo n.º 4
0
        static MethodHelper()
        {
            var AssName = new AssemblyName(nameof(MethodHelper));

            AssBuilder = VersionDifferences.DefineDynamicAssembly(AssName,
                                                                  AssemblyBuilderAccess.Run);

            ModBuilder = AssBuilder.DefineDynamicModule(nameof(MethodHelper));

            DelegateTypesCache     = new Dictionary <MethodSign, Type>();
            DelegateTypesCacheLock = new object();

            FuncInterfaces = new Type[] {
                typeof(IFunc <>),
                typeof(IFunc <,>),
                typeof(IFunc <, ,>),
                typeof(IFunc <, , ,>),
                typeof(IFunc <, , , ,>),
                typeof(IFunc <, , , , ,>),
                typeof(IFunc <, , , , , ,>),
                typeof(IFunc <, , , , , , ,>),
                typeof(IFunc <, , , , , , , ,>),
                typeof(IFunc <, , , , , , , , ,>),
                typeof(IFunc <, , , , , , , , , ,>),
                typeof(IFunc <, , , , , , , , , , ,>),
                typeof(IFunc <, , , , , , , , , , , ,>),
                typeof(IFunc <, , , , , , , , , , , , ,>),
                typeof(IFunc <, , , , , , , , , , , , , ,>),
                typeof(IFunc <, , , , , , , , , , , , , , ,>),
                typeof(IFunc <, , , , , , , , , , , , , , , ,>)
            };

            ActionInterfaces = new Type[] {
                typeof(IAction),
                typeof(IAction <>),
                typeof(IAction <,>),
                typeof(IAction <, ,>),
                typeof(IAction <, , ,>),
                typeof(IAction <, , , ,>),
                typeof(IAction <, , , , ,>),
                typeof(IAction <, , , , , ,>),
                typeof(IAction <, , , , , , ,>),
                typeof(IAction <, , , , , , , ,>),
                typeof(IAction <, , , , , , , , ,>),
                typeof(IAction <, , , , , , , , , ,>),
                typeof(IAction <, , , , , , , , , , ,>),
                typeof(IAction <, , , , , , , , , , , ,>),
                typeof(IAction <, , , , , , , , , , , , ,>),
                typeof(IAction <, , , , , , , , , , , , , ,>)
            };

            DelegatePointerOffset = 0;
        }
        public static void SerializeObject <T>(T value, TextWriter textWriter)
        {
            using (var jsonSerializer = new JsonDefaultSerializer(DefaultMaxDepth)
            {
                textWriter = textWriter
            })
            {
                ValueInterface <T> .WriteValue(jsonSerializer, value);

                VersionDifferences.WriteChars(
                    textWriter,
                    jsonSerializer.hGlobal.GetPointer(),
                    jsonSerializer.StringLength);
            }
        }
        private void InternalExpand(int expandMinSize)
        {
            if (hGlobal.Capacity == HGlobal.MaxSize && stream != null && offset != 0)
            {
                VersionDifferences.WriteBytes(stream, hGlobal.GetPointer(), offset);

                offset = 0;

                Expand(expandMinSize);
            }
            else
            {
                hGlobal.Expand(expandMinSize);
            }
        }
Ejemplo n.º 7
0
        public static async Task SerializeObjectAsync <T>(T value, TextWriter textWriter)
        {
            using (var jsonSerializer = new JsonDefaultSerializer(DefaultMaxDepth)
            {
                textWriter = textWriter
            })
            {
                ValueInterface <T> .WriteValue(jsonSerializer, value);

                await VersionDifferences.WriteCharsAsync(
                    textWriter,
                    jsonSerializer.hGlobal.Address,
                    jsonSerializer.StringLength);
            }
        }
Ejemplo n.º 8
0
        private void InternalExpand(int expandMinSize)
        {
            if (hGlobal.Count == HGlobalCache <char> .MaxSize && textWriter != null && offset != 0)
            {
                VersionDifferences.WriteChars(textWriter, hGlobal.GetPointer(), offset);

                offset = 0;

                Expand(expandMinSize);
            }
            else
            {
                hGlobal.Expand(expandMinSize);
            }
        }
Ejemplo n.º 9
0
        public void Serialize <T>(T value, TextWriter textWriter)
        {
            using (var jsonSerializer = CreateJsonSerializer())
            {
                if (id != 0)
                {
                    jsonSerializer.jsonFormatter = this;
                }

                ValueInterface <T> .WriteValue((IValueWriter)jsonSerializer, value);

                VersionDifferences.WriteChars(
                    textWriter,
                    jsonSerializer.hGlobal.GetPointer(),
                    jsonSerializer.StringLength);
            }
        }
Ejemplo n.º 10
0
        public async Task SerializeAsync <T>(T value, TextWriter textWriter)
        {
            using (var jsonSerializer = CreateJsonSerializer())
            {
                if (id != 0)
                {
                    jsonSerializer.jsonFormatter = this;
                }

                ValueInterface <T> .WriteValue((IValueWriter)jsonSerializer, value);

                await VersionDifferences.WriteCharsAsync(
                    textWriter,
                    jsonSerializer.hGlobal.Address,
                    jsonSerializer.StringLength);
            }
        }
Ejemplo n.º 11
0
        private static void Reset()
        {
            if (!HaveDefinedType)
            {
                return;
            }

            lock (Lock)
            {
                if (!HaveDefinedType)
                {
                    return;
                }

                AssBuilder =
                    VersionDifferences.DefineDynamicAssembly(
                        new AssemblyName(AssName),
                        Access
#if Save
                        | AssemblyBuilderAccess.Save
#endif
                        );

                AssBuilders.Add(AssBuilder);

                ModBuilder = AssBuilder.DefineDynamicModule(
                    AssName
#if Save
                    , $"{AssName}.dll"
#endif
                    );

                HaveDefinedType = false;

                var assemblies = IgnoresAccessChecksToDic.Keys.ToArray();

                IgnoresAccessChecksToDic.Clear();

                foreach (var assembly in assemblies)
                {
                    IgnoresAccessChecksTo(assembly);
                }
            }
        }
Ejemplo n.º 12
0
        public void TypeTest()
        {
            AreEqual(TypeHelper.CanBeGenericParameter(typeof(TypedReference)), false);
            AreEqual(TypeHelper.CanBeGenericParameter(typeof(void *)), false);
            AreEqual(TypeHelper.CanBeGenericParameter(typeof(int).MakeByRefType()), false);
            AreEqual(TypeHelper.CanBeGenericParameter(typeof(TypeHelper)), false);
            AreEqual(TypeHelper.CanBeGenericParameter(typeof(int)), true);
            AreEqual(TypeHelper.CanBeGenericParameter(typeof(Tester_Struct)), true);
            AreEqual(TypeHelper.CanBeGenericParameter(typeof(Tester)), true);
            AreEqual(TypeHelper.CanBeGenericParameter(typeof(IntPtr)), true);

            AreEqual(VersionDifferences.IsByRefLike(typeof(TypedReference)), true);
            AreEqual(VersionDifferences.IsByRefLike(typeof(int)), false);
            AreEqual(VersionDifferences.IsByRefLike(typeof(IntPtr)), false);
            AreEqual(VersionDifferences.IsByRefLike(typeof(void *)), false);
            AreEqual(VersionDifferences.IsByRefLike(typeof(int).MakeByRefType()), false);

            AreEqual(TypeHelper.GetDefaultValue(typeof(IntPtr)), default(IntPtr));
            AreEqual(TypeHelper.GetDefaultValue(typeof(string)), default(string));
            AreEqual(TypeHelper.GetDefaultValue(typeof(string)), default(string));
            AreEqual(TypeHelper.GetDefaultValue(typeof(int)), default(int));
            AreEqual(TypeHelper.GetDefaultValue(typeof(Tester_Struct)), default(Tester_Struct));

            AreEqual(TypeHelper.IsEmptyValue(default(IntPtr)), true);
            AreEqual(TypeHelper.IsEmptyValue(default(Tester_Struct)), true);
            AreEqual(TypeHelper.IsEmptyValue(default(string)), true);
            AreEqual(TypeHelper.IsEmptyValue(""), false);
            AreEqual(TypeHelper.IsEmptyValue(Guid.NewGuid()), false);

            AreEqual(TypeHelper.IsEmptyValue((object)default(IntPtr)), true);
            AreEqual(TypeHelper.IsEmptyValue((object)default(Tester_Struct)), true);
            AreEqual(TypeHelper.IsEmptyValue((object)default(string)), true);
            AreEqual(TypeHelper.IsEmptyValue((object)""), false);
            AreEqual(TypeHelper.IsEmptyValue((object)Guid.NewGuid()), false);

            AreEqual(TypeHelper.IsAutoProperty(typeof(Tester).GetProperty(nameof(Tester.auto_property)), out var fieldInfo), true);
            IsNotNull(fieldInfo);
            AreEqual(TypeHelper.IsAutoProperty(typeof(Tester).GetProperty(nameof(Tester.non_auto_property)), out var _), false);

            AreEqual(TypeHelper.IsAutoProperty(typeof(Tester_Struct).GetProperty(nameof(Tester_Struct.auto_property)), out fieldInfo), true);
            IsNotNull(fieldInfo);
            AreEqual(TypeHelper.IsAutoProperty(typeof(Tester_Struct).GetProperty(nameof(Tester_Struct.non_auto_property)), out var _), false);
        }
Ejemplo n.º 13
0
        public void Expand(int expandMinSize)
        {
Loop:
            if (hGlobal.count - offset < expandMinSize)
            {
                if (hGlobal.count == HGlobalCache.MaxSize && textWriter != null && offset != 0)
                {
                    VersionDifferences.WriteChars(textWriter, hGlobal.chars, offset);

                    offset = 0;

                    goto Loop;
                }
                else
                {
                    hGlobal.Expand(expandMinSize);
                }
            }
        }
Ejemplo n.º 14
0
 public static IntPtr GetTypeHandle(object obj)
 {
     return(VersionDifferences.GetTypeHandle(obj));
 }
Ejemplo n.º 15
0
 public void WriteTo(TextWriter textWriter)
 {
     VersionDifferences.WriteChars(textWriter, hGlobal.chars, offset - 1);
 }