From 65765431c9cf036bf070c287211583909bae884b Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Tue, 13 Nov 2018 12:34:01 +0100 Subject: [PATCH] Added NET 3.5 version of FatturaElettronica.Core --- src/Core(3.5)/Compatibily/CompilerServices.cs | 18 +++ src/Core(3.5)/Compatibily/Reflection.cs | 42 +++++++ src/Core(3.5)/Compatibily/TypeInfo.cs | 107 ++++++++++++++++++ .../FatturaElettronica.Core(3.5).csproj | 76 +++++++++++++ src/Core(3.5)/Properties/AssemblyInfo.cs | 36 ++++++ src/Core(3.5)/packages.config | 4 + src/Core/BaseClassSerializable.cs | 4 +- src/FatturaElettronica.Core.sln | 24 +++- src/Test(3.5)/Compatibility/NUnit.cs | 8 ++ src/Test(3.5)/Properties/AssemblyInfo.cs | 36 ++++++ src/Test(3.5)/Test(3.5).csproj | 69 +++++++++++ src/Test(3.5)/packages.config | 6 + src/Test/JsonTest.cs | 4 + src/Test/Test.csproj | 2 +- src/Test/XmlTest.cs | 4 + 15 files changed, 436 insertions(+), 4 deletions(-) create mode 100644 src/Core(3.5)/Compatibily/CompilerServices.cs create mode 100644 src/Core(3.5)/Compatibily/Reflection.cs create mode 100644 src/Core(3.5)/Compatibily/TypeInfo.cs create mode 100644 src/Core(3.5)/FatturaElettronica.Core(3.5).csproj create mode 100644 src/Core(3.5)/Properties/AssemblyInfo.cs create mode 100644 src/Core(3.5)/packages.config create mode 100644 src/Test(3.5)/Compatibility/NUnit.cs create mode 100644 src/Test(3.5)/Properties/AssemblyInfo.cs create mode 100644 src/Test(3.5)/Test(3.5).csproj create mode 100644 src/Test(3.5)/packages.config diff --git a/src/Core(3.5)/Compatibily/CompilerServices.cs b/src/Core(3.5)/Compatibily/CompilerServices.cs new file mode 100644 index 0000000..d291be2 --- /dev/null +++ b/src/Core(3.5)/Compatibily/CompilerServices.cs @@ -0,0 +1,18 @@ +namespace System.Runtime.CompilerServices +{ + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] + public sealed class CallerMemberNameAttribute : Attribute + { + public CallerMemberNameAttribute() + { + } + } + + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] + public sealed class CallerLineNumberAttribute : Attribute + { + public CallerLineNumberAttribute() + { + } + } +} \ No newline at end of file diff --git a/src/Core(3.5)/Compatibily/Reflection.cs b/src/Core(3.5)/Compatibily/Reflection.cs new file mode 100644 index 0000000..ef69de2 --- /dev/null +++ b/src/Core(3.5)/Compatibily/Reflection.cs @@ -0,0 +1,42 @@ +using System; +using System.Linq; +using System.Collections.Generic; +using System.Globalization; + +namespace System.Reflection +{ + + static class ReflectionExtensions + { + public static TypeInfo GetTypeInfo(this Type source) + { + return new TypeInfo(source); + } + + readonly static object[] EmptyArray = new object[0]; + + public static PropertyInfo[] GetRuntimeProperties(this Type type) + { + return type.GetProperties(); + } + + public static IEnumerable GetCustomAttributes(this MemberInfo member, bool inherit = false) + where T : Attribute + { + return (member.GetCustomAttributes(typeof(T), false) ?? EmptyArray) + .OfType(); + } + + public static T GetCustomAttribute(this MemberInfo member, bool inherit = false) + where T : Attribute + { + return (member.GetCustomAttributes(typeof(T), false) ?? EmptyArray).OfType().Single(); + } + + public static IEnumerable GetRuntimeMethods(this Type type) + { + return type.GetMethods(); + } + } + +} diff --git a/src/Core(3.5)/Compatibily/TypeInfo.cs b/src/Core(3.5)/Compatibily/TypeInfo.cs new file mode 100644 index 0000000..df5e5b4 --- /dev/null +++ b/src/Core(3.5)/Compatibily/TypeInfo.cs @@ -0,0 +1,107 @@ +using System.Collections.Generic; +using System.Globalization; +using System.Reflection; + +namespace System +{ + public class TypeInfo : Type + { + readonly Type type; + readonly static MethodInfo MethodGetAttributeFlagsImpl = + typeof(Type).GetMethod(nameof(GetAttributeFlagsImpl), BindingFlags.Instance | BindingFlags.NonPublic); + readonly static MethodInfo MethodGetConstructorImpl = + typeof(Type).GetMethod(nameof(GetConstructorImpl), BindingFlags.Instance | BindingFlags.NonPublic); + readonly static MethodInfo MethodGetMethodImpl = + typeof(Type).GetMethod(nameof(GetMethodImpl), BindingFlags.Instance | BindingFlags.NonPublic); + readonly static MethodInfo MethodGetPropertyImpl = + typeof(Type).GetMethod(nameof(GetPropertyImpl), BindingFlags.Instance | BindingFlags.NonPublic); + readonly static MethodInfo MethodHasElementTypeImpl = + typeof(Type).GetMethod(nameof(HasElementTypeImpl), BindingFlags.Instance | BindingFlags.NonPublic); + readonly static MethodInfo MethodIsArrayImpl = + typeof(Type).GetMethod(nameof(IsArrayImpl), BindingFlags.Instance | BindingFlags.NonPublic); + readonly static MethodInfo MethodIsByRefImpl = + typeof(Type).GetMethod(nameof(IsByRefImpl), BindingFlags.Instance | BindingFlags.NonPublic); + readonly static MethodInfo MethodIsCOMObjectImpl = + typeof(Type).GetMethod(nameof(IsCOMObjectImpl), BindingFlags.Instance | BindingFlags.NonPublic); + readonly static MethodInfo MethodIsPointerImpl = + typeof(Type).GetMethod(nameof(IsPointerImpl), BindingFlags.Instance | BindingFlags.NonPublic); + readonly static MethodInfo MethodIsPrimitiveImpl = + typeof(Type).GetMethod(nameof(IsPrimitiveImpl), BindingFlags.Instance | BindingFlags.NonPublic); + + internal TypeInfo(Type type) => this.type = type; + + public override Guid GUID => type.GUID; + + public override Module Module => type.Module; + + public override Assembly Assembly => type.Assembly; + + public override string FullName => type.FullName; + + public override string Namespace => type.Namespace; + + public override string AssemblyQualifiedName => type.AssemblyQualifiedName; + + public override Type BaseType => type.BaseType; + + public override Type UnderlyingSystemType => type.UnderlyingSystemType; + + public override string Name => type.Name; + + public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr) => type.GetConstructors(bindingAttr); + + public override object[] GetCustomAttributes(bool inherit) => type.GetCustomAttributes(inherit); + + public override object[] GetCustomAttributes(Type attributeType, bool inherit) => type.GetCustomAttributes(attributeType, inherit); + + public override Type GetElementType() => type.GetElementType(); + + public override EventInfo GetEvent(string name, BindingFlags bindingAttr) => type.GetEvent(name, bindingAttr); + + public override EventInfo[] GetEvents(BindingFlags bindingAttr) => type.GetEvents(bindingAttr); + + public override FieldInfo GetField(string name, BindingFlags bindingAttr) => GetField(name, bindingAttr); + + public override FieldInfo[] GetFields(BindingFlags bindingAttr) => GetFields(bindingAttr); + + public override Type GetInterface(string name, bool ignoreCase) => type.GetInterface(name, ignoreCase); + + public override Type[] GetInterfaces() => type.GetInterfaces(); + + public override MemberInfo[] GetMembers(BindingFlags bindingAttr) => type.GetMembers(bindingAttr); + + public override MethodInfo[] GetMethods(BindingFlags bindingAttr) => type.GetMethods(bindingAttr); + + public override Type GetNestedType(string name, BindingFlags bindingAttr) => type.GetNestedType(name, bindingAttr); + + public override Type[] GetNestedTypes(BindingFlags bindingAttr) => type.GetNestedTypes(bindingAttr); + + public override PropertyInfo[] GetProperties(BindingFlags bindingAttr) => GetProperties(bindingAttr); + + public override object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters) => type.InvokeMember(name, invokeAttr, binder, target, args); + + public override bool IsDefined(Type attributeType, bool inherit) => type.IsDefined(attributeType, inherit); + + protected override TypeAttributes GetAttributeFlagsImpl() => (TypeAttributes)MethodGetAttributeFlagsImpl.Invoke(type, null); + + protected override ConstructorInfo GetConstructorImpl(BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) => (ConstructorInfo)MethodGetConstructorImpl.Invoke(type, new object[] { bindingAttr, binder, callConvention, type, modifiers }); + + protected override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) => (MethodInfo)MethodGetMethodImpl.Invoke(type, new object[] { name, bindingAttr, binder, callConvention, type, modifiers }); + + protected override PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) => (PropertyInfo)MethodGetPropertyImpl.Invoke(type, new object[] { name, bindingAttr, binder, returnType, type, modifiers }); + + protected override bool HasElementTypeImpl() => (bool)MethodHasElementTypeImpl.Invoke(type, null); + + protected override bool IsArrayImpl() => (bool)MethodIsArrayImpl.Invoke(type, null); + + protected override bool IsByRefImpl() => (bool)MethodIsByRefImpl.Invoke(type, null); + + protected override bool IsCOMObjectImpl() => (bool)MethodIsCOMObjectImpl.Invoke(type, null); + + protected override bool IsPointerImpl() => (bool)MethodIsPointerImpl.Invoke(type, null); + + protected override bool IsPrimitiveImpl() => (bool)MethodIsPrimitiveImpl.Invoke(type, null); + + public IEnumerable GenericTypeArguments => type.GetGenericArguments(); + } +} diff --git a/src/Core(3.5)/FatturaElettronica.Core(3.5).csproj b/src/Core(3.5)/FatturaElettronica.Core(3.5).csproj new file mode 100644 index 0000000..60029e7 --- /dev/null +++ b/src/Core(3.5)/FatturaElettronica.Core(3.5).csproj @@ -0,0 +1,76 @@ + + + + + Debug + AnyCPU + {555A2179-AEB8-4B3D-AA3F-92EE3DC9FE62} + Library + Properties + FatturaElettronica.Core + FatturaElettronica.Core + v3.5 + 512 + true + + + true + full + false + bin\Debug\ + TRACE;DEBUG;NET35 + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Newtonsoft.Json.11.0.2\lib\net35\Newtonsoft.Json.dll + + + + + + + + + BaseClass.cs + + + BaseClassSerializable.cs + + + DataPropertyAttribute.cs + + + IgnoreXmlDateFormat.cs + + + JsonOptions.cs + + + JsonParseException.cs + + + TypeExtensions.cs + + + XmlOptions.cs + + + + + + + + + + + \ No newline at end of file diff --git a/src/Core(3.5)/Properties/AssemblyInfo.cs b/src/Core(3.5)/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..cf7037f --- /dev/null +++ b/src/Core(3.5)/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("FatturaElettronica.NET")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("CIR 2000")] +[assembly: AssemblyProduct("FatturaElettronica.NET")] +[assembly: AssemblyCopyright("Copyright © CIR2000 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("555a2179-aeb8-4b3d-aa3f-92ee3dc9fe62")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Core(3.5)/packages.config b/src/Core(3.5)/packages.config new file mode 100644 index 0000000..9eecb30 --- /dev/null +++ b/src/Core(3.5)/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/Core/BaseClassSerializable.cs b/src/Core/BaseClassSerializable.cs index d86784d..442c8f2 100644 --- a/src/Core/BaseClassSerializable.cs +++ b/src/Core/BaseClassSerializable.cs @@ -257,7 +257,7 @@ public virtual string ToJson() public virtual string ToJson(JsonOptions jsonOptions) { var json = JsonConvert.SerializeObject( - this, (jsonOptions == JsonOptions.Indented) ? Formatting.Indented : Formatting.None, + this, (jsonOptions == JsonOptions.Indented) ? Newtonsoft.Json.Formatting.Indented : Newtonsoft.Json.Formatting.None, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Serialize, DefaultValueHandling = DefaultValueHandling.Ignore }); return json; } @@ -443,7 +443,7 @@ private static void ReadXmlList(object propertyValue, Type propertyType, string // list items are expected to be of BusinessObject type. var bo = Activator.CreateInstance(argumentType); ((BaseClassSerializable)bo).ReadXml(r); - add.Invoke(propertyValue, new[] { bo }); + add.Invoke(propertyValue, new object [] { bo }); continue; } diff --git a/src/FatturaElettronica.Core.sln b/src/FatturaElettronica.Core.sln index f94ecd5..b453f04 100644 --- a/src/FatturaElettronica.Core.sln +++ b/src/FatturaElettronica.Core.sln @@ -5,7 +5,15 @@ VisualStudioVersion = 15.0.26730.10 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FatturaElettronica.Core", "Core\FatturaElettronica.Core.csproj", "{157BF9FE-D002-4129-91A9-E4D1C74BE861}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{778645B6-7E1F-4BAD-8488-8C110A91620C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "Test\Test.csproj", "{778645B6-7E1F-4BAD-8488-8C110A91620C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FatturaElettronica.Core(3.5)", "Core(3.5)\FatturaElettronica.Core(3.5).csproj", "{555A2179-AEB8-4B3D-AA3F-92EE3DC9FE62}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NetStandard", "NetStandard", "{092D6860-DF60-48E2-BBF5-291B6B507480}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NET35", "NET35", "{494A9D17-FD4F-40CC-8B6F-01D7DFC935CB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test(3.5)", "Test(3.5)\Test(3.5).csproj", "{2AFBF850-0A3F-4265-9A3F-066A2D731E61}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -21,10 +29,24 @@ Global {778645B6-7E1F-4BAD-8488-8C110A91620C}.Debug|Any CPU.Build.0 = Debug|Any CPU {778645B6-7E1F-4BAD-8488-8C110A91620C}.Release|Any CPU.ActiveCfg = Release|Any CPU {778645B6-7E1F-4BAD-8488-8C110A91620C}.Release|Any CPU.Build.0 = Release|Any CPU + {555A2179-AEB8-4B3D-AA3F-92EE3DC9FE62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {555A2179-AEB8-4B3D-AA3F-92EE3DC9FE62}.Debug|Any CPU.Build.0 = Debug|Any CPU + {555A2179-AEB8-4B3D-AA3F-92EE3DC9FE62}.Release|Any CPU.ActiveCfg = Release|Any CPU + {555A2179-AEB8-4B3D-AA3F-92EE3DC9FE62}.Release|Any CPU.Build.0 = Release|Any CPU + {2AFBF850-0A3F-4265-9A3F-066A2D731E61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2AFBF850-0A3F-4265-9A3F-066A2D731E61}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2AFBF850-0A3F-4265-9A3F-066A2D731E61}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2AFBF850-0A3F-4265-9A3F-066A2D731E61}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {157BF9FE-D002-4129-91A9-E4D1C74BE861} = {092D6860-DF60-48E2-BBF5-291B6B507480} + {778645B6-7E1F-4BAD-8488-8C110A91620C} = {092D6860-DF60-48E2-BBF5-291B6B507480} + {555A2179-AEB8-4B3D-AA3F-92EE3DC9FE62} = {494A9D17-FD4F-40CC-8B6F-01D7DFC935CB} + {2AFBF850-0A3F-4265-9A3F-066A2D731E61} = {494A9D17-FD4F-40CC-8B6F-01D7DFC935CB} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {EFA5152C-5656-48BA-B46F-226DE0764CD1} EndGlobalSection diff --git a/src/Test(3.5)/Compatibility/NUnit.cs b/src/Test(3.5)/Compatibility/NUnit.cs new file mode 100644 index 0000000..647854b --- /dev/null +++ b/src/Test(3.5)/Compatibility/NUnit.cs @@ -0,0 +1,8 @@ +namespace NUnit.Framework +{ + + public class TestClass : TestFixtureAttribute { } + + public class TestMethod : TestAttribute { } + +} diff --git a/src/Test(3.5)/Properties/AssemblyInfo.cs b/src/Test(3.5)/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..599a238 --- /dev/null +++ b/src/Test(3.5)/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Test(3.5)")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Test(3.5)")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("2afbf850-0a3f-4265-9a3f-066a2d731e61")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Test(3.5)/Test(3.5).csproj b/src/Test(3.5)/Test(3.5).csproj new file mode 100644 index 0000000..2dfa158 --- /dev/null +++ b/src/Test(3.5)/Test(3.5).csproj @@ -0,0 +1,69 @@ + + + + + Debug + AnyCPU + {2AFBF850-0A3F-4265-9A3F-066A2D731E61} + Library + Properties + Test + Test + v3.5 + 512 + true + + + true + full + false + bin\Debug\ + TRACE;DEBUG;NET35 + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE;NET35 + prompt + 4 + + + + ..\packages\Newtonsoft.Json.11.0.2\lib\net35\Newtonsoft.Json.dll + + + ..\packages\NUnit.2.7.0\lib\nunit.framework.dll + + + + + + + + + JsonTest.cs + + + TestMe.cs + + + XmlTest.cs + + + + + + + {555a2179-aeb8-4b3d-aa3f-92ee3dc9fe62} + FatturaElettronica.Core%283.5%29 + + + + + + + + \ No newline at end of file diff --git a/src/Test(3.5)/packages.config b/src/Test(3.5)/packages.config new file mode 100644 index 0000000..1e52e39 --- /dev/null +++ b/src/Test(3.5)/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Test/JsonTest.cs b/src/Test/JsonTest.cs index 8cf12fc..af4d74c 100644 --- a/src/Test/JsonTest.cs +++ b/src/Test/JsonTest.cs @@ -1,7 +1,11 @@ using System; using System.IO; using System.Xml; +#if NET35 +using NUnit.Framework; +#else using Microsoft.VisualStudio.TestTools.UnitTesting; +#endif using Newtonsoft.Json; namespace Test diff --git a/src/Test/Test.csproj b/src/Test/Test.csproj index 5ddbf1e..458b850 100644 --- a/src/Test/Test.csproj +++ b/src/Test/Test.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/Test/XmlTest.cs b/src/Test/XmlTest.cs index 42de190..f51f8cd 100644 --- a/src/Test/XmlTest.cs +++ b/src/Test/XmlTest.cs @@ -1,6 +1,10 @@ using System; using System.Xml; +#if NET35 +using NUnit.Framework; +#else using Microsoft.VisualStudio.TestTools.UnitTesting; +#endif namespace Test {