├── .gitignore
├── .idea
└── .idea.Simple1C
│ ├── .idea
│ ├── .name
│ ├── modules.xml
│ └── vcs.xml
│ └── riderModule.iml
├── Assemblies
└── Metadata1C.dll
├── Generator
├── CsProjectFileUpdater.cs
├── EntryPoint.cs
├── Generator.csproj
└── Properties
│ └── AssemblyInfo.cs
├── LICENSE.txt
├── Simple1C.sln
├── Simple1C.sln.DotSettings
├── Simple1C
├── DataContextFactory.cs
├── Impl
│ ├── Call.cs
│ ├── Com
│ │ ├── ComHelpers.cs
│ │ └── DispatchObject.cs
│ ├── ComDataContext.cs
│ ├── ComObjectMapper.cs
│ ├── ComValueSource.cs
│ ├── ConfigurationName.cs
│ ├── EntityController.cs
│ ├── EntityHelpers.cs
│ ├── EnumMapItem.cs
│ ├── Generation
│ │ ├── ConfigurationItem.cs
│ │ ├── ConfigurationItemDescriptor.cs
│ │ ├── GenerationContext.cs
│ │ ├── ObjectModelGenerator.cs
│ │ └── Rendering
│ │ │ ├── ClassFileModel.cs
│ │ │ ├── ClassFileTemplate.cs
│ │ │ ├── ClassFileTemplate.tt
│ │ │ ├── ClassModel.cs
│ │ │ ├── ConstantFileModel.cs
│ │ │ ├── ConstantFileTemplate.cs
│ │ │ ├── ConstantFileTemplate.tt
│ │ │ ├── EnumFileModel.cs
│ │ │ ├── EnumFileTemplate.cs
│ │ │ ├── EnumFileTemplate.tt
│ │ │ ├── EnumItemModel.cs
│ │ │ ├── GenerateHelpers.cs
│ │ │ └── PropertyModel.cs
│ ├── GlobalContext.cs
│ ├── Helpers
│ │ ├── AttributesCache.cs
│ │ ├── ByteArrayHelpers.cs
│ │ ├── DictionaryExtensions.cs
│ │ ├── EnumAttributesCache.cs
│ │ ├── EnumerableExtensions.cs
│ │ ├── Evaluator.cs
│ │ ├── ListFactory.cs
│ │ ├── LogHelpers.cs
│ │ ├── MemberAccessor
│ │ │ ├── BoxingCaster.cs
│ │ │ ├── Caster.cs
│ │ │ ├── FieldAccessorFactory.cs
│ │ │ ├── IAccessMember.cs
│ │ │ ├── IMemberAccessor.cs
│ │ │ ├── MappingMemberAccessor.cs
│ │ │ ├── MemberAccessor.cs
│ │ │ ├── MemberAccessorFactory.cs
│ │ │ ├── PropertyAccessorFactory.cs
│ │ │ ├── TypeMismatchException.cs
│ │ │ ├── UnboxingCaster.cs
│ │ │ └── UntypedMemberAccessor.cs
│ │ ├── NameValueCollectionHelpers.cs
│ │ ├── PathHelpers.cs
│ │ ├── ReflectionHelpers.cs
│ │ ├── RelinqHelpers.cs
│ │ └── StringHelpers.cs
│ ├── IValueSource.cs
│ ├── InMemoryDataContext.cs
│ ├── MappingSource.cs
│ ├── Metadata.cs
│ ├── MetadataAccessor.cs
│ ├── MetadataHelpers.cs
│ ├── MetadataRequisite.cs
│ ├── ObservedValue.cs
│ ├── ParametersConverter.cs
│ ├── ProjectionMapperFactory.cs
│ ├── Queriables
│ │ ├── BuiltQuery.cs
│ │ ├── ConvertEnumCmd.cs
│ │ ├── ConvertUniqueIdentifierCmd.cs
│ │ ├── FilterPredicateAnalyzer.cs
│ │ ├── IConvertParameterCmd.cs
│ │ ├── IRelinqQueryable.cs
│ │ ├── MemberAccessBuilder.cs
│ │ ├── Ordering.cs
│ │ ├── ParameterizingExpressionVisitor.cs
│ │ ├── Projection.cs
│ │ ├── PropertiesExtractingVisitor.cs
│ │ ├── QueryBuilder.cs
│ │ ├── QueryField.cs
│ │ ├── QueryModelVisitor.cs
│ │ ├── RelinqQueryExecutor.cs
│ │ ├── RelinqQueryProvider.cs
│ │ ├── RelinqQueryable.cs
│ │ ├── SelectedProperty.cs
│ │ └── SelectedPropertyItem.cs
│ ├── Queries
│ │ ├── QueryResult.cs
│ │ ├── QueryResultSelection.cs
│ │ ├── ValueTable.cs
│ │ ├── ValueTableColumn.cs
│ │ ├── ValueTableColumnCollection.cs
│ │ └── ValueTableRow.cs
│ ├── SimpleTypeInfo.cs
│ ├── Sql
│ │ ├── MsSqlBulkCopyWriter.cs
│ │ ├── SchemaMapping
│ │ │ ├── EnumMapping.cs
│ │ │ ├── IMappingSource.cs
│ │ │ ├── PostgreeSqlSchemaStore.cs
│ │ │ ├── PropertyLauout.cs
│ │ │ ├── PropertyMapping.cs
│ │ │ ├── PropertyNames.cs
│ │ │ ├── Simple1cSchemaCreator.cs
│ │ │ ├── SingleLayout.cs
│ │ │ ├── TableMapping.cs
│ │ │ ├── TableType.cs
│ │ │ └── UnionLayout.cs
│ │ ├── SqlAccess
│ │ │ ├── AbstractSqlDatabase.cs
│ │ │ ├── DatabaseHelpers.cs
│ │ │ ├── InMemoryDataReader.cs
│ │ │ ├── MssqlDatabase.cs
│ │ │ ├── Parsing
│ │ │ │ ├── ColumnReferenceTableNameResolver.cs
│ │ │ │ ├── ElementsHolder.cs
│ │ │ │ ├── Identifier.cs
│ │ │ │ ├── ParseHelpers.cs
│ │ │ │ ├── QueryGrammar.cs
│ │ │ │ └── QueryParser.cs
│ │ │ ├── PostgreeSqlDatabase.cs
│ │ │ └── Syntax
│ │ │ │ ├── AggregateFunctionExpression.cs
│ │ │ │ ├── AggregationFunction.cs
│ │ │ │ ├── AndExpression.cs
│ │ │ │ ├── BinaryExpression.cs
│ │ │ │ ├── CaseElement.cs
│ │ │ │ ├── CaseExpression.cs
│ │ │ │ ├── CastExpression.cs
│ │ │ │ ├── ColumnReferenceExpression.cs
│ │ │ │ ├── DatePart.cs
│ │ │ │ ├── EqualityExpression.cs
│ │ │ │ ├── GroupByClause.cs
│ │ │ │ ├── IColumnSource.cs
│ │ │ │ ├── ISqlElement.cs
│ │ │ │ ├── InExpression.cs
│ │ │ │ ├── IsNullExpression.cs
│ │ │ │ ├── IsReferenceExpression.cs
│ │ │ │ ├── JoinClause.cs
│ │ │ │ ├── JoinKind.cs
│ │ │ │ ├── KnownQueryFunction.cs
│ │ │ │ ├── ListExpression.cs
│ │ │ │ ├── LiteralExpression.cs
│ │ │ │ ├── OperatorPrecedenceAttribute.cs
│ │ │ │ ├── OperatorSynonymsAttribute.cs
│ │ │ │ ├── OrderByClause.cs
│ │ │ │ ├── ParameterExpression.cs
│ │ │ │ ├── QueryFunctionExpression.cs
│ │ │ │ ├── SelectClause.cs
│ │ │ │ ├── SelectFieldExpression.cs
│ │ │ │ ├── SqlBinaryOperator.cs
│ │ │ │ ├── SqlQuery.cs
│ │ │ │ ├── SqlType.cs
│ │ │ │ ├── SubqueryClause.cs
│ │ │ │ ├── SubqueryTable.cs
│ │ │ │ ├── TableDeclarationClause.cs
│ │ │ │ ├── UnaryExpression.cs
│ │ │ │ ├── UnaryOperator.cs
│ │ │ │ ├── UnionClause.cs
│ │ │ │ ├── UnionType.cs
│ │ │ │ └── ValueLiteralExpression.cs
│ │ └── Translation
│ │ │ ├── QueryEntities
│ │ │ ├── EnumSqlBuilder.cs
│ │ │ ├── NameGenerator.cs
│ │ │ ├── QueryEntity.cs
│ │ │ ├── QueryEntityProperty.cs
│ │ │ ├── QueryEntityRegistry.cs
│ │ │ ├── QueryEntityTree.cs
│ │ │ ├── QueryField.cs
│ │ │ ├── QueryRoot.cs
│ │ │ └── SelectPart.cs
│ │ │ ├── QueryToSqlTranslator.cs
│ │ │ ├── SqlFormatter.cs
│ │ │ ├── SqlHelpers.cs
│ │ │ ├── SqlVisitor.cs
│ │ │ └── Visitors
│ │ │ ├── AddAreaToJoinConditionVisitor.cs
│ │ │ ├── ColumnReferenceRewriter.cs
│ │ │ ├── DeduceEntityTypeFromIsReferenceExpressionVisitor.cs
│ │ │ ├── GenericVisitor.cs
│ │ │ ├── IsReferenceExpressionRewriter.cs
│ │ │ ├── ObjectNameCheckingVisitor.cs
│ │ │ ├── QueryFunctionRewriter.cs
│ │ │ ├── SubqueryVisitor.cs
│ │ │ ├── TableDeclarationRewriter.cs
│ │ │ ├── TableDeclarationVisitor.cs
│ │ │ └── ValueLiteralRewriter.cs
│ ├── SyncList.cs
│ ├── TypeInfo.cs
│ └── TypeRegistry.cs
├── Interface
│ ├── ConfigurationScope.cs
│ ├── Connection1CType.cs
│ ├── ConnectionStringBuilder.cs
│ ├── DataContextExtensions.cs
│ ├── GlobalContextFactory.cs
│ ├── IDataContext.cs
│ ├── ObjectModel
│ │ ├── Abstract1CEntity.cs
│ │ ├── ConfigurationScopeAttribute.cs
│ │ ├── Constant.cs
│ │ ├── MaxLengthAttribute.cs
│ │ ├── ObjectPresentationAttribute.cs
│ │ ├── Requisite.cs
│ │ └── SynonymAttribute.cs
│ ├── ObjectPresentation.cs
│ ├── Sql
│ │ ├── IWriter.cs
│ │ ├── QuerySource.cs
│ │ └── RowAccessor.cs
│ ├── Synonym.cs
│ └── Функции.cs
├── Properties
│ └── AssemblyInfo.cs
├── Simple1C.csproj
├── Sql.cs
└── packages.config
├── Tests
├── Class1.cs
├── CsProjectFileUpdaterTest.cs
├── Helpers
│ ├── ProcessesHelpers.cs
│ ├── Robocopy.cs
│ ├── TestBase.cs
│ └── Testing1CConnector.cs
├── InMemoryDataContextTest.cs
├── Integration
│ ├── COMDataContextTest.cs
│ ├── COMDataContextTestBase.cs
│ ├── CharacteristicsTest.cs
│ ├── ConstantsTest.cs
│ ├── DataContextManagementTest.cs
│ ├── InformationRegisterTest.cs
│ ├── ProjectionTest.cs
│ ├── SaveTest.cs
│ ├── SaveValidationsIntegrationTest.cs
│ ├── TableSectionsTest.cs
│ └── UniqueIdentifierTest.cs
├── Properties
│ └── AssemblyInfo.cs
├── QueryBuilderTest.cs
├── Sql
│ ├── BasicTest.cs
│ ├── EnumsTest.cs
│ ├── FunctionReplacementTest.cs
│ ├── LiteralsTest.cs
│ ├── NestedPropertiesTest.cs
│ ├── ParserTest.cs
│ ├── SubqueryTest.cs
│ └── TranslationTestBase.cs
├── SynonymTest.cs
├── TestEntities
│ ├── AccountingDocument.cs
│ ├── AdvanceWay.cs
│ ├── Bank.cs
│ ├── BankAccount.cs
│ ├── Banks.cs
│ ├── Counterpart.cs
│ ├── CounterpartContractKind.cs
│ ├── CounterpartyContract.cs
│ ├── EnumConverter.cs
│ ├── IncomingOperationKind.cs
│ ├── LegalForm.cs
│ ├── NdsRate.cs
│ ├── NomenclatureItem.cs
│ └── TestObjectsManager.cs
├── Tests.csproj
├── packages.config
└── ФункцииTest.cs
├── build.cmd
├── generate.cmd
├── nuget
├── publish.cmd
└── simple1C.nuspec
├── readme.md
└── todo
/.gitignore:
--------------------------------------------------------------------------------
1 | *.user
2 | *.suo
3 | *.mdb
4 | *.userprefs
5 | bin/
6 | bin.tests/
7 | obj/
8 | packages/
9 | *.nupkg
10 | *.designer.cs
11 | *.Designer.cs
12 |
13 | #rider user-local files (according to https://intellij-support.jetbrains.com/hc/en-us/articles/206544839-How-to-manage-projects-under-Version-Control-Systems)
14 | **/.idea/workspace.xml
15 | **/.idea/tasks.xml
16 |
--------------------------------------------------------------------------------
/.idea/.idea.Simple1C/.idea/.name:
--------------------------------------------------------------------------------
1 | Simple1C
--------------------------------------------------------------------------------
/.idea/.idea.Simple1C/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/.idea.Simple1C/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/.idea.Simple1C/riderModule.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Assemblies/Metadata1C.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ivan816/simple-1c/f2e5ce78b98f70f30039fd3de79308a59d432fc2/Assemblies/Metadata1C.dll
--------------------------------------------------------------------------------
/Generator/Generator.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {20486119-897F-44BA-893D-A0E4A0649FD9}
8 | Exe
9 | Properties
10 | Generator
11 | Generator
12 | v4.5
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | ..\bin\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 |
26 |
27 | pdbonly
28 | true
29 | ..\bin\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | {bb1a4406-ad17-4089-9d6b-33d4452fde4c}
50 | Simple1C
51 |
52 |
53 |
54 |
61 |
--------------------------------------------------------------------------------
/Generator/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Generator")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Generator")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("c354c5da-c534-44f9-89a6-d2fd9f8b3abf")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Gusev Petr, Ivan Medvedev
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/Simple1C.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.21005.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Simple1C", "Simple1C\Simple1C.csproj", "{BB1A4406-AD17-4089-9D6B-33D4452FDE4C}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{49A6C3B8-E307-4C44-B4B9-F33FD4FB9216}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Generator", "Generator\Generator.csproj", "{20486119-897F-44BA-893D-A0E4A0649FD9}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {BB1A4406-AD17-4089-9D6B-33D4452FDE4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {BB1A4406-AD17-4089-9D6B-33D4452FDE4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {BB1A4406-AD17-4089-9D6B-33D4452FDE4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {BB1A4406-AD17-4089-9D6B-33D4452FDE4C}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {49A6C3B8-E307-4C44-B4B9-F33FD4FB9216}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {49A6C3B8-E307-4C44-B4B9-F33FD4FB9216}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {49A6C3B8-E307-4C44-B4B9-F33FD4FB9216}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {49A6C3B8-E307-4C44-B4B9-F33FD4FB9216}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {20486119-897F-44BA-893D-A0E4A0649FD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {20486119-897F-44BA-893D-A0E4A0649FD9}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {20486119-897F-44BA-893D-A0E4A0649FD9}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {20486119-897F-44BA-893D-A0E4A0649FD9}.Release|Any CPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | EndGlobal
35 |
--------------------------------------------------------------------------------
/Simple1C.sln.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | True
3 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
4 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
5 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
--------------------------------------------------------------------------------
/Simple1C/DataContextFactory.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using Simple1C.Impl;
3 | using Simple1C.Interface;
4 |
5 | namespace Simple1C
6 | {
7 | public static class DataContextFactory
8 | {
9 | public static IDataContext CreateCOM(object globalContext, Assembly mappingsAssembly)
10 | {
11 | return new ComDataContext(globalContext, mappingsAssembly);
12 | }
13 |
14 | public static IDataContext CreateInMemory(Assembly mappingsAssembly)
15 | {
16 | return new InMemoryDataContext(mappingsAssembly);
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Call.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Simple1C.Impl.Com;
3 |
4 | namespace Simple1C.Impl
5 | {
6 | internal static class Call
7 | {
8 | public static string ПолноеИмя(object comObject)
9 | {
10 | return Convert.ToString(ComHelpers.Invoke(comObject, "ПолноеИмя"));
11 | }
12 |
13 | public static string Имя(object comObject)
14 | {
15 | return StringProp(comObject, "Имя");
16 | }
17 |
18 | public static string Синоним(object comObject)
19 | {
20 | return StringProp(comObject, "Синоним");
21 | }
22 |
23 | public static object Получить(object comObject, int index)
24 | {
25 | return ComHelpers.Invoke(comObject, "Получить", index);
26 | }
27 |
28 | public static int Количество(object comObject)
29 | {
30 | return Convert.ToInt32(ComHelpers.Invoke(comObject, "Количество"));
31 | }
32 |
33 | public static int IntProp(object comObject, string name)
34 | {
35 | return Convert.ToInt32(ComHelpers.GetProperty(comObject, name));
36 | }
37 |
38 | public static string StringProp(object comObject, string name)
39 | {
40 | return Convert.ToString(ComHelpers.GetProperty(comObject, name));
41 | }
42 |
43 | public static bool IsEmpty(object comObject)
44 | {
45 | return (bool) ComHelpers.Invoke(comObject, "IsEmpty");
46 | }
47 |
48 | public static object НайтиПоТипу(object metadata, object typeObject)
49 | {
50 | return ComHelpers.Invoke(metadata, "НайтиПоТипу", typeObject);
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Com/DispatchObject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace Simple1C.Impl.Com
5 | {
6 | internal class DispatchObject
7 | {
8 | private readonly object comObject;
9 |
10 | protected DispatchObject(object comObject)
11 | {
12 | this.comObject = comObject;
13 | }
14 |
15 | protected string GetString(string property)
16 | {
17 | var value = Get(property);
18 | return Convert.IsDBNull(value) ? null : Convert.ToString(value);
19 | }
20 |
21 | protected object Get(string property)
22 | {
23 | return ComHelpers.GetProperty(comObject, property);
24 | }
25 |
26 | protected void Set(string property, object value)
27 | {
28 | ComHelpers.SetProperty(comObject, property, value);
29 | }
30 |
31 | protected object Invoke(string name, params object[] args)
32 | {
33 | return ComHelpers.Invoke(comObject, name, args);
34 | }
35 |
36 | protected object ComObject()
37 | {
38 | return comObject;
39 | }
40 |
41 | protected void Dispose()
42 | {
43 | Marshal.FinalReleaseComObject(comObject);
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/ComValueSource.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Simple1C.Impl.Com;
3 |
4 | namespace Simple1C.Impl
5 | {
6 | internal class ComValueSource : IValueSource
7 | {
8 | private readonly ComObjectMapper comObjectMapper;
9 | private readonly object comObject;
10 |
11 | internal ComValueSource(object comObject, ComObjectMapper comObjectMapper, bool writable)
12 | {
13 | this.comObjectMapper = comObjectMapper;
14 | this.comObject = comObject;
15 | Writable = writable;
16 | }
17 |
18 | public object GetBackingStorage()
19 | {
20 | return comObject;
21 | }
22 |
23 | public bool Writable { get; private set; }
24 |
25 | bool IValueSource.TryLoadValue(string name, Type type, out object result)
26 | {
27 | var isUniqueIdentifier = name == EntityHelpers.idPropertyName && type == typeof(Guid?);
28 | var propertyValue = isUniqueIdentifier
29 | ? ComHelpers.Invoke(comObject, name)
30 | : ComHelpers.GetProperty(comObject, name);
31 | result = comObjectMapper.MapFrom1C(propertyValue, type);
32 | return true;
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/EntityHelpers.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Simple1C.Interface.ObjectModel;
3 |
4 | namespace Simple1C.Impl
5 | {
6 | internal static class EntityHelpers
7 | {
8 | public const string idPropertyName = "УникальныйИдентификатор";
9 |
10 | public static bool IsTableSection(Type type)
11 | {
12 | return type.Name.StartsWith("ТабличнаяЧасть");
13 | }
14 |
15 | public static bool IsConstant(Type type)
16 | {
17 | return type.BaseType != null &&
18 | type.BaseType.IsGenericType &&
19 | type.BaseType.GetGenericTypeDefinition() == typeof(Constant<>);
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/EnumMapItem.cs:
--------------------------------------------------------------------------------
1 | namespace Simple1C.Impl
2 | {
3 | internal class EnumMapItem
4 | {
5 | public object value;
6 | public int index;
7 | }
8 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Generation/ConfigurationItem.cs:
--------------------------------------------------------------------------------
1 | namespace Simple1C.Impl.Generation
2 | {
3 | internal class ConfigurationItem
4 | {
5 | public ConfigurationItem(ConfigurationName name, object comObject)
6 | {
7 | Name = name;
8 | ComObject = comObject;
9 | }
10 |
11 | public ConfigurationName Name { get; private set; }
12 | public object ComObject { get; private set; }
13 | }
14 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Generation/ConfigurationItemDescriptor.cs:
--------------------------------------------------------------------------------
1 | namespace Simple1C.Impl.Generation
2 | {
3 | internal class ConfigurationItemDescriptor
4 | {
5 | public string[] AttributePropertyNames { get; set; }
6 | public bool HasTableSections { get; set; }
7 | public bool HasStandardTableSections { get; set; }
8 | }
9 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Generation/GenerationContext.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.IO;
3 | using Simple1C.Impl.Helpers;
4 |
5 | namespace Simple1C.Impl.Generation
6 | {
7 | internal class GenerationContext
8 | {
9 | private readonly string rootDirectoryFullPath;
10 | private readonly HashSet seen = new HashSet();
11 | private readonly List writtenFiles = new List();
12 |
13 | public GenerationContext(string rootDirectoryFullPath)
14 | {
15 | this.rootDirectoryFullPath = rootDirectoryFullPath;
16 | ItemsToProcess = new Queue();
17 | }
18 |
19 | public Queue ItemsToProcess { get; private set; }
20 |
21 | public void Write(ConfigurationName name, string content)
22 | {
23 | var fileFullPath = Path.Combine(rootDirectoryFullPath, name.Scope.ToString(), name.Name) + ".cs";
24 | var directoryFullPath = PathHelpers.GetDirectoryName(fileFullPath);
25 | if (!Directory.Exists(directoryFullPath))
26 | Directory.CreateDirectory(directoryFullPath);
27 | File.WriteAllText(fileFullPath, content);
28 | writtenFiles.Add(fileFullPath);
29 | }
30 |
31 | public IEnumerable GetWrittenFiles()
32 | {
33 | return writtenFiles;
34 | }
35 |
36 | public void EnqueueIfNeeded(ConfigurationItem item)
37 | {
38 | if (seen.Add(item.Name))
39 | ItemsToProcess.Enqueue(item);
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Generation/Rendering/ClassFileModel.cs:
--------------------------------------------------------------------------------
1 | namespace Simple1C.Impl.Generation.Rendering
2 | {
3 | internal class ClassFileModel
4 | {
5 | public string Namespace { get; set; }
6 | public ClassModel MainClass { get; set; }
7 | }
8 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Generation/Rendering/ClassFileTemplate.tt:
--------------------------------------------------------------------------------
1 | <#@ template language="C#" visibility="internal" #>
2 | <#@ assembly name="System.Core" #>
3 | <#@ import namespace="System.Linq" #>
4 | <#@ import namespace="System.Text" #>
5 | <#@ import namespace="System.Collections.Generic" #>
6 | using System;
7 | using System.Collections.Generic;
8 | using Simple1C.Interface;
9 | using Simple1C.Interface.ObjectModel;
10 |
11 | namespace <#=Model.Namespace#>
12 | {
13 | <#
14 | PushIndent("\t");
15 | RenderClass(Model.MainClass);
16 | PopIndent();
17 | #>
18 | }
19 | <#+
20 | public ClassFileModel Model { get; set; }
21 |
22 | private void RenderClass(ClassModel model)
23 | {
24 | #>
25 | <#+if(model.ConfigurationScope.HasValue)
26 | {#>
27 | [ConfigurationScope(ConfigurationScope.<#=model.ConfigurationScope.Value.ToString()#>)]
28 | <#+}#>
29 | <#+if(model.Synonym != null)
30 | {#>
31 | [Synonym("<#=model.Synonym#>")]
32 | <#+}#>
33 | <#+if(model.ObjectPresentation != null)
34 | {#>
35 | [ObjectPresentation("<#=model.ObjectPresentation#>")]
36 | <#+}#>
37 | public partial class <#=model.Name#> : Abstract1CEntity
38 | {
39 | <#+for(var i = 0; i < model.Properties.Count; i++)
40 | {
41 | var prop = model.Properties[i];
42 | if(i != 0)
43 | Write("\r\n");
44 | #> private Requisite<<#=prop.Type#>> <#=prop.FieldName#>;
45 | <#+if(prop.MaxLength.HasValue) {#> [MaxLength(<#=prop.MaxLength.Value#>)]
46 | <#+}#> public <#=prop.Type#> <#=prop.PropertyName#>
47 | {
48 | get { return Controller.GetValue(ref <#=prop.FieldName#>, "<#=prop.PropertyName#>"); }
49 | set { Controller.SetValue(ref <#=prop.FieldName#>, "<#=prop.PropertyName#>", value); }
50 | }
51 | <#+}#><#+if(model.NestedClasses != null)
52 | foreach(var nestedClass in model.NestedClasses)
53 | {
54 | Write("\r\n");
55 | PushIndent("\t");
56 | RenderClass(nestedClass);
57 | PopIndent();
58 | }#>
59 | }
60 | <#+}#>
--------------------------------------------------------------------------------
/Simple1C/Impl/Generation/Rendering/ClassModel.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Simple1C.Interface;
3 |
4 | namespace Simple1C.Impl.Generation.Rendering
5 | {
6 | internal class ClassModel
7 | {
8 | public ClassModel()
9 | {
10 | Properties = new List();
11 | NestedClasses = new List();
12 | }
13 |
14 | public string Name { get; set; }
15 | public ConfigurationScope? ConfigurationScope { get; set; }
16 | public string Synonym { get; set; }
17 | public string ObjectPresentation { get; set; }
18 | public List Properties { get; private set; }
19 | public List NestedClasses { get; private set; }
20 | }
21 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Generation/Rendering/ConstantFileModel.cs:
--------------------------------------------------------------------------------
1 | namespace Simple1C.Impl.Generation.Rendering
2 | {
3 | internal class ConstantFileModel
4 | {
5 | public string Namespace { get; set; }
6 | public string Name { get; set; }
7 | public string Synonym { get; set; }
8 | public string Type { get; set; }
9 | public int? MaxLength { get; set; }
10 | }
11 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Generation/Rendering/ConstantFileTemplate.tt:
--------------------------------------------------------------------------------
1 | <#@ template language="C#" visibility="internal" #>
2 | <#@ assembly name="System.Core" #>
3 | using System;
4 | using Simple1C.Interface.ObjectModel;
5 |
6 | namespace <#=Model.Namespace#>
7 | {
8 | [Synonym("<#=Model.Synonym#>")]
9 | <#if(Model.MaxLength.HasValue) {#> [MaxLength(<#=Model.MaxLength.Value#>)]
10 | <#}#> public class <#=Model.Name#> : Constant<<#=Model.Type#>>
11 | {
12 | }
13 | }<#+
14 | public ConstantFileModel Model { get; set; }
15 | #>
--------------------------------------------------------------------------------
/Simple1C/Impl/Generation/Rendering/EnumFileModel.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace Simple1C.Impl.Generation.Rendering
4 | {
5 | internal class EnumFileModel
6 | {
7 | public EnumFileModel()
8 | {
9 | Items = new List();
10 | }
11 |
12 | public string Namespace { get; set; }
13 | public string Name { get; set; }
14 | public List Items { get; private set; }
15 | }
16 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Generation/Rendering/EnumFileTemplate.tt:
--------------------------------------------------------------------------------
1 | <#@ template language="C#" visibility="internal" #>
2 | <#@ assembly name="System.Core" #>
3 | <#@ import namespace="System.Linq" #>
4 | <#@ import namespace="System.Text" #>
5 | <#@ import namespace="System.Collections.Generic" #>
6 | using System;
7 | using Simple1C.Interface.ObjectModel;
8 |
9 | namespace <#=Model.Namespace#>
10 | {
11 | public enum <#=Model.Name#>
12 | {<#for(var i = 0; i < Model.Items.Count; i++)
13 | {
14 | var item = Model.Items[i];#>
15 |
16 | [Synonym("<#=item.Synonym#>")] <#=item.Name#><#if(i != Model.Items.Count - 1){#>,<#}#><#}#>
17 |
18 | }
19 | }<#+
20 | public EnumFileModel Model { get; set; }
21 | #>
--------------------------------------------------------------------------------
/Simple1C/Impl/Generation/Rendering/EnumItemModel.cs:
--------------------------------------------------------------------------------
1 | namespace Simple1C.Impl.Generation.Rendering
2 | {
3 | public class EnumItemModel
4 | {
5 | public string Name { get; set; }
6 | public string Synonym { get; set; }
7 | }
8 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Generation/Rendering/GenerateHelpers.cs:
--------------------------------------------------------------------------------
1 | namespace Simple1C.Impl.Generation.Rendering
2 | {
3 | internal static class GenerateHelpers
4 | {
5 | public static string EscapeString(string input)
6 | {
7 | return input == null ? null : input.Replace("\\", "\\\\").Replace("\"", "\\\"");
8 | }
9 | }
10 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Generation/Rendering/PropertyModel.cs:
--------------------------------------------------------------------------------
1 | namespace Simple1C.Impl.Generation.Rendering
2 | {
3 | internal class PropertyModel
4 | {
5 | public string PropertyName { get; set; }
6 | public int? MaxLength { get; set; }
7 |
8 | public string FieldName
9 | {
10 | get { return char.ToLower(PropertyName[0]) + PropertyName.Substring(1); }
11 | }
12 |
13 | public string Type { get; set; }
14 | }
15 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Helpers/AttributesCache.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Concurrent;
3 | using System.Reflection;
4 |
5 | namespace Simple1C.Impl.Helpers
6 | {
7 | public class AttributesCache
8 | {
9 | private static readonly ConcurrentDictionary cache = new ConcurrentDictionary();
10 |
11 | private static readonly Func createDelegate =
12 | key => key.attributeProvider.GetCustomAttributes(key.attributeType, key.inherit);
13 |
14 | public static object GetCustomAttributes(ICustomAttributeProvider attributeProvider, Type attributeType,
15 | bool inherit)
16 | {
17 | return cache.GetOrAdd(new Key(attributeProvider, attributeType, inherit), createDelegate);
18 | }
19 |
20 | public static T GetCustomAttribute(ICustomAttributeProvider attributeProvider, bool inherit)
21 | {
22 | var attributes = (T[]) GetCustomAttributes(attributeProvider, typeof(T), inherit);
23 | if (attributes.Length == 0)
24 | {
25 | const string messageFormat = "[{0}] has no attribute [{1}]";
26 | throw new ArgumentOutOfRangeException(string.Format(messageFormat,
27 | FormatName(attributeProvider), typeof(T).Name));
28 | }
29 | if (attributes.Length > 1)
30 | {
31 | const string messageFormat = "[{0}] has more then one attribute [{1}]";
32 | throw new ArgumentOutOfRangeException(string.Format(messageFormat,
33 | FormatName(attributeProvider), typeof(T).Name));
34 | }
35 | return attributes[0];
36 | }
37 |
38 | private static string FormatName(ICustomAttributeProvider attributeProvider)
39 | {
40 | var t = (Type) attributeProvider;
41 | if (t != null)
42 | return t.FormatName();
43 | var m = (MemberInfo) attributeProvider;
44 | if (m != null)
45 | return m.DeclaringType.FormatName() + "." + m.Name;
46 | return attributeProvider.ToString();
47 | }
48 |
49 | private struct Key : IEquatable
50 | {
51 | public readonly ICustomAttributeProvider attributeProvider;
52 | public readonly Type attributeType;
53 | public readonly bool inherit;
54 |
55 | public Key(ICustomAttributeProvider attributeProvider, Type attributeType, bool inherit)
56 | {
57 | this.attributeProvider = attributeProvider;
58 | this.attributeType = attributeType;
59 | this.inherit = inherit;
60 | }
61 |
62 | public bool Equals(Key other)
63 | {
64 | var localInherit = inherit;
65 | return attributeProvider.Equals(other.attributeProvider) &&
66 | attributeType == other.attributeType &&
67 | localInherit.Equals(other.inherit);
68 | }
69 |
70 | public override bool Equals(object obj)
71 | {
72 | if (ReferenceEquals(null, obj)) return false;
73 | return obj is Key && Equals((Key) obj);
74 | }
75 |
76 | public override int GetHashCode()
77 | {
78 | unchecked
79 | {
80 | var hashCode = (attributeProvider != null ? attributeProvider.GetHashCode() : 0);
81 | hashCode = (hashCode*397) ^ (attributeType != null ? attributeType.GetHashCode() : 0);
82 | var localInherit = inherit;
83 | hashCode = (hashCode*397) ^ localInherit.GetHashCode();
84 | return hashCode;
85 | }
86 | }
87 | }
88 | }
89 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Helpers/ByteArrayHelpers.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Simple1C.Impl.Helpers
4 | {
5 | internal static class ByteArrayHelpers
6 | {
7 | public static string ToHex(this byte[] bytes)
8 | {
9 | var hex = BitConverter.ToString(bytes);
10 | return hex.Replace("-", "");
11 | }
12 |
13 | //http://stackoverflow.com/questions/623104/byte-to-hex-string/623184#623184
14 | public static byte[] FromHex(string hex, int offset = 0)
15 | {
16 | var bytes = new byte[(hex.Length - offset) / 2];
17 | for (int bx = 0, sx = 0; bx < bytes.Length; ++bx, ++sx)
18 | {
19 | var c = hex[sx + offset];
20 | bytes[bx] = (byte)((c > '9' ? (c > 'Z' ? c - 'a' + 10 : c - 'A' + 10) : c - '0') << 4);
21 | c = hex[++sx + offset];
22 | bytes[bx] |= (byte)(c > '9' ? (c > 'Z' ? c - 'a' + 10 : c - 'A' + 10) : c - '0');
23 | }
24 | return bytes;
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Helpers/DictionaryExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace Simple1C.Impl.Helpers
5 | {
6 | internal static class DictionaryExtensions
7 | {
8 | public static TValue GetOrAdd(this IDictionary dictionary, TKey key,
9 | Func valueFactory)
10 | {
11 | TValue result;
12 | if (!dictionary.TryGetValue(key, out result))
13 | dictionary.Add(key, result = valueFactory(key));
14 | return result;
15 | }
16 |
17 | public static TValue GetOrDefault(this IDictionary dictionary, TKey key)
18 | {
19 | TValue result;
20 | return dictionary.TryGetValue(key, out result) ? result : default(TValue);
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Helpers/EnumAttributesCache.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Concurrent;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Reflection;
6 |
7 | namespace Simple1C.Impl.Helpers
8 | {
9 | internal static class EnumAttributesCache
10 | where TAttribute : Attribute
11 | {
12 | private static readonly ConcurrentDictionary> enumToItems =
13 | new ConcurrentDictionary>();
14 |
15 | public static TAttribute GetAttribute(TEnum enumItem)
16 | where TEnum : struct
17 | {
18 | return GetAttributeUnsafe(enumItem);
19 | }
20 |
21 | public static TAttribute GetAttributeUnsafe(object enumItem)
22 | {
23 | TAttribute result;
24 | if (!GetAllAttributes(enumItem.GetType())
25 | .TryGetValue(enumItem.ToString(), out result))
26 | throw new ArgumentOutOfRangeException(
27 | "enumItem", string.Format("enum [{0}] has no [{1}] for [{2}]",
28 | enumItem.GetType().FullName, typeof(TAttribute).Name, enumItem));
29 | return result;
30 | }
31 |
32 | public static IDictionary GetAllAttributes(Type enumType)
33 | {
34 | return enumToItems.GetOrAdd(enumType, GetEnumItems);
35 | }
36 |
37 | private static IDictionary GetEnumItems(Type enumType)
38 | {
39 | return enumType
40 | .GetFields()
41 | .Where(item => !item.IsSpecialName)
42 | .Select(item => new {item.Name, Attr = GetEnumItemAttribute(item)})
43 | .Where(x => x.Attr != null)
44 | .ToDictionary(x => x.Name, x => x.Attr);
45 | }
46 |
47 | private static TAttribute GetEnumItemAttribute(FieldInfo enumItem)
48 | {
49 | return (TAttribute) enumItem
50 | .GetCustomAttributes(typeof(TAttribute), false)
51 | .FirstOrDefault();
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Helpers/EnumerableExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 |
4 | namespace Simple1C.Impl.Helpers
5 | {
6 | internal static class EnumerableExtensions
7 | {
8 | public static string JoinStrings(this IEnumerable source, string separator)
9 | {
10 | return string.Join(separator, source);
11 | }
12 |
13 | public static IEnumerable NotNull(this IEnumerable source) where T : class
14 | {
15 | return source.Where(x => x != null);
16 | }
17 |
18 | public static HashSet ToSet(this IEnumerable source, IEqualityComparer comparer = null)
19 | {
20 | return new HashSet(source, comparer);
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Helpers/ListFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Concurrent;
4 | using System.Collections.Generic;
5 |
6 | namespace Simple1C.Impl.Helpers
7 | {
8 | internal static class ListFactory
9 | {
10 | private static readonly ConcurrentDictionary factories =
11 | new ConcurrentDictionary();
12 |
13 | private static readonly Func createFactory = CreateFactory;
14 |
15 | public static IList Create(Type itemType, IList source, int capacity)
16 | {
17 | return factories.GetOrAdd(itemType, createFactory).Create(source, capacity);
18 | }
19 |
20 | private static IFactory CreateFactory(Type itemType)
21 | {
22 | return (IFactory) Activator.CreateInstance(typeof (Factory<>).MakeGenericType(itemType));
23 | }
24 |
25 | private interface IFactory
26 | {
27 | IList Create(IList source, int capacity);
28 | }
29 |
30 | private class Factory : IFactory
31 | {
32 | public IList Create(IList source, int capacity)
33 | {
34 | return source == null
35 | ? new List(capacity)
36 | : new List((IEnumerable) source);
37 | }
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Helpers/LogHelpers.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 |
4 | namespace Simple1C.Impl.Helpers
5 | {
6 | internal static class LogHelpers
7 | {
8 | public static void LogWithTiming(string description, Action action)
9 | {
10 | Console.Out.WriteLine(description);
11 | var s = Stopwatch.StartNew();
12 | action();
13 | s.Stop();
14 | Console.Out.WriteLine("done, took [{0}] millis", s.ElapsedMilliseconds);
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Helpers/MemberAccessor/BoxingCaster.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection.Emit;
3 |
4 | namespace Simple1C.Impl.Helpers.MemberAccessor
5 | {
6 | internal class BoxingCaster : Caster
7 | {
8 | public BoxingCaster(Type outputType, Type memberType)
9 | : base(outputType, memberType) {}
10 |
11 | protected override void EmitNullableCast(ILGenerator ilGenerator, Type nullableType)
12 | {
13 | ilGenerator.Emit(OpCodes.Newobj, nullableType.GetConstructor(new[] { memberType }));
14 | }
15 |
16 | protected override void EmitValueTypeCast(ILGenerator ilGenerator)
17 | {
18 | ilGenerator.Emit(OpCodes.Box, memberType);
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Helpers/MemberAccessor/Caster.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection.Emit;
3 |
4 | namespace Simple1C.Impl.Helpers.MemberAccessor
5 | {
6 | public abstract class Caster
7 | {
8 | protected readonly Type memberType;
9 | protected readonly Type outputType;
10 |
11 | protected Caster(Type outputType, Type memberType)
12 | {
13 | this.outputType = outputType;
14 | this.memberType = memberType;
15 | }
16 |
17 | protected abstract void EmitNullableCast(ILGenerator ilGenerator, Type nullableType);
18 |
19 | protected abstract void EmitValueTypeCast(ILGenerator ilGenerator);
20 |
21 | public void EmitCast(ILGenerator ilGenerator)
22 | {
23 | if (outputType == memberType)
24 | return;
25 |
26 | if (!outputType.IsAssignableFrom(memberType))
27 | throw new TypeMismatchException(outputType, memberType);
28 |
29 | if (memberType.IsValueType && !outputType.IsValueType)
30 | EmitValueTypeCast(ilGenerator);
31 |
32 | if (outputType.IsNullableOf(memberType))
33 | EmitNullableCast(ilGenerator, outputType);
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Helpers/MemberAccessor/FieldAccessorFactory.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Reflection.Emit;
3 |
4 | namespace Simple1C.Impl.Helpers.MemberAccessor
5 | {
6 | internal class FieldAccessorFactory: MemberAccessorFactory
7 | {
8 | private readonly FieldInfo fieldInfo;
9 |
10 | public FieldAccessorFactory(FieldInfo fieldInfo): base(fieldInfo)
11 | {
12 | this.fieldInfo = fieldInfo;
13 | }
14 |
15 | protected override bool TryEmitSet(ILGenerator ilGenerator)
16 | {
17 | if (!fieldInfo.IsStatic)
18 | ilGenerator.Emit(OpCodes.Ldarg_0);
19 | ilGenerator.Emit(OpCodes.Ldarg_1);
20 | EmitUnboxingCast(fieldInfo.FieldType, ilGenerator);
21 | ilGenerator.Emit(fieldInfo.IsStatic ? OpCodes.Stsfld : OpCodes.Stfld, fieldInfo);
22 | ilGenerator.Emit(OpCodes.Ret);
23 | return true;
24 | }
25 |
26 | protected override bool TryEmitGet(ILGenerator ilGenerator)
27 | {
28 | EmitLoadTarget(ilGenerator, fieldInfo);
29 | ilGenerator.Emit(fieldInfo.IsStatic ? OpCodes.Ldsfld : OpCodes.Ldfld, fieldInfo);
30 | EmitBoxingCast(fieldInfo.FieldType, ilGenerator);
31 | ilGenerator.Emit(OpCodes.Ret);
32 | return true;
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Helpers/MemberAccessor/IAccessMember.cs:
--------------------------------------------------------------------------------
1 | namespace Simple1C.Impl.Helpers.MemberAccessor
2 | {
3 | public interface IAccessMember
4 | {
5 | void Set(object entity, object value);
6 | object Get(object entity);
7 | }
8 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Helpers/MemberAccessor/IMemberAccessor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Simple1C.Impl.Helpers.MemberAccessor
4 | {
5 | public interface IMemberAccessor: IAccessMember
6 | {
7 | bool CanGet { get; }
8 | bool CanSet { get; }
9 | Type MemberType { get; }
10 | }
11 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Helpers/MemberAccessor/MappingMemberAccessor.cs:
--------------------------------------------------------------------------------
1 | namespace Simple1C.Impl.Helpers.MemberAccessor
2 | {
3 | internal class MappingMemberAccessor: IAccessMember
4 | {
5 | private readonly IAccessMember parent;
6 | private readonly IAccessMember child;
7 |
8 | public MappingMemberAccessor(IAccessMember parent, IAccessMember child)
9 | {
10 | this.parent = parent;
11 | this.child = child;
12 | }
13 |
14 | public void Set(object entity, object value)
15 | {
16 | var parentValue = parent.Get(entity);
17 | if (parentValue != null)
18 | child.Set(parentValue, value);
19 | }
20 |
21 | public object Get(object entity)
22 | {
23 | var parentValue = parent.Get(entity);
24 | return parentValue == null ? null : child.Get(parentValue);
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/Simple1C/Impl/Helpers/MemberAccessor/MemberAccessor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Concurrent;
3 | using System.Linq;
4 | using System.Reflection;
5 |
6 | namespace Simple1C.Impl.Helpers.MemberAccessor
7 | {
8 | internal class MemberAccessor: IMemberAccessor
9 | {
10 | private readonly Func