Skip to content

Commit 628abd9

Browse files
committed
fix some things + nuget stuff
1 parent 952570a commit 628abd9

7 files changed

Lines changed: 57 additions & 26 deletions

File tree

Datamodel.NET/Datamodel.NET.csproj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<RootNamespace>Datamodel</RootNamespace>
66
<PackageId>KeyValues2</PackageId>
77
<Version>0.8</Version>
8+
<Version>0.9</Version>
89
<Nullable>enable</Nullable>
910
<PackageLicenseFile>COPYING</PackageLicenseFile>
1011
<PackageReadmeFile>README.md</PackageReadmeFile>
@@ -53,11 +54,7 @@
5354
</ItemGroup>
5455

5556
<ItemGroup>
56-
<ProjectReference Include="..\ElementFactoryGenerator\ElementFactoryGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
57+
<ProjectReference Include="..\ElementFactoryGenerator\ElementFactoryGenerator.csproj" Version="0.1" OutputItemType="Analyzer" ReferenceOutputAssembly="true" />
5758
</ItemGroup>
58-
59-
<ItemGroup>
60-
<Analyzer Include="@(Analyzer)" Pack="true" />
61-
</ItemGroup>
6259

6360
</Project>

ElementFactoryGenerator/COPYING

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2013 Tom Edwards contact@steamreview.org
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
13+
all 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
21+
THE SOFTWARE.

ElementFactoryGenerator/ElementFactory.cs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ public class ElementFactory : Datamodel.Codecs.IElementFactory
4242

4343
var (compilation, classDeclList) = tuple;
4444

45-
var runningAssembly = new FactoryAssembly(compilation.AssemblyName!);
45+
var runningAssembly = new FactoryAssembly(compilation.AssemblyName);
4646
foreach (var classDecl in classDeclList)
4747
{
4848
var type = compilation.GetSemanticModel(classDecl.SyntaxTree).GetDeclaredSymbol(classDecl);
4949

50-
if(type is not null)
50+
if (type is not null)
5151
{
52-
runningAssembly.AddType(type.ContainingNamespace.Name, type);
52+
runningAssembly.AddType(type.ContainingNamespace.ToDisplayString(), type);
5353
}
5454
}
5555
assemblies.Add(runningAssembly);
@@ -66,7 +66,7 @@ public class ElementFactory : Datamodel.Codecs.IElementFactory
6666
var assemblyTypes = GetAllClassesFromAssembly(assemblySymbol);
6767
foreach (var assemblyType in assemblyTypes)
6868
{
69-
referencedAssembly.AddType(assemblyType.ContainingNamespace.Name, assemblyType);
69+
referencedAssembly.AddType(assemblyType.ContainingNamespace.ToDisplayString(), assemblyType);
7070
}
7171

7272
assemblies.Add(referencedAssembly);
@@ -97,26 +97,26 @@ public class ElementFactory : Datamodel.Codecs.IElementFactory
9797
var validTypes = 0;
9898
foreach (var type in nameSpace.Types)
9999
{
100-
if (ValidateType(type))
100+
if (ValidateType(type, compilation))
101101
{
102102
validTypes++;
103103

104-
typeseStringBuilder.AppendLine(
105-
$""""
104+
typeseStringBuilder.AppendLine(
105+
$""""
106106
107107
case "{type.Name}":
108108
return new {type.ToDisplayString()}();
109109
"""");
110110
}
111-
111+
112112
}
113113

114114
typeseStringBuilder.AppendLine(
115115
""""
116116
}
117117
"""");
118118

119-
if(validTypes > 0)
119+
if (validTypes > 0)
120120
{
121121
validNamespaces++;
122122
namespaceStringBuilder.AppendLine(
@@ -127,15 +127,15 @@ public class ElementFactory : Datamodel.Codecs.IElementFactory
127127
break;
128128
"""");
129129
}
130-
130+
131131
}
132132

133133
namespaceStringBuilder.AppendLine(
134134
""""
135135
}
136136
"""");
137137

138-
if(validNamespaces > 0)
138+
if (validNamespaces > 0)
139139
{
140140
elementFactory.AppendLine(
141141
$"""
@@ -145,7 +145,7 @@ public class ElementFactory : Datamodel.Codecs.IElementFactory
145145
146146
""");
147147
}
148-
148+
149149
}
150150

151151
elementFactory.AppendLine(
@@ -161,7 +161,7 @@ public class ElementFactory : Datamodel.Codecs.IElementFactory
161161
context.AddSource("ElementFactory.g.cs", elementFactory.ToString());
162162
}
163163

164-
private static bool ValidateType(INamedTypeSymbol type)
164+
private static bool ValidateType(INamedTypeSymbol type, Compilation compilation)
165165
{
166166
if (InheritsFromFullName(type, "Datamodel.Element"))
167167
{
@@ -171,12 +171,20 @@ private static bool ValidateType(INamedTypeSymbol type)
171171
return false;
172172
}
173173

174-
// only allow public and internal classes
175-
if (type.DeclaredAccessibility != Accessibility.Public && type.DeclaredAccessibility != Accessibility.Internal)
174+
if (type.DeclaredAccessibility != Accessibility.Internal && type.DeclaredAccessibility != Accessibility.Public)
176175
{
177176
return false;
178177
}
179178

179+
// only internal classes in execution assembly are fine
180+
if (type.DeclaredAccessibility == Accessibility.Internal)
181+
{
182+
if(compilation.Assembly != type.ContainingAssembly)
183+
{
184+
return false;
185+
}
186+
}
187+
180188
return true;
181189
}
182190

@@ -249,7 +257,7 @@ public void AddType(string nameSpaceName, INamedTypeSymbol type)
249257
{
250258
NamespacesContainsNamespace(nameSpaceName, out FactoryNamespace? foundNameSpace);
251259

252-
if(foundNameSpace == null)
260+
if (foundNameSpace == null)
253261
{
254262
foundNameSpace = new FactoryNamespace(nameSpaceName);
255263
Namespaces.Add(foundNameSpace);
@@ -262,7 +270,7 @@ private bool NamespacesContainsNamespace(string namespaceName, out FactoryNamesp
262270
{
263271
foreach (var nameSpace in Namespaces)
264272
{
265-
if(nameSpace.Name == namespaceName)
273+
if (nameSpace.Name == namespaceName)
266274
{
267275
outNameSpace = nameSpace;
268276
return true;

ElementFactoryGenerator/ElementFactoryGenerator.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<LangVersion>latest</LangVersion>
6+
<Version>0.1</Version>
7+
<PackageLicenseFile>COPYING</PackageLicenseFile>
8+
<PackageReadmeFile>README.md</PackageReadmeFile>
69
<Nullable>enable</Nullable>
7-
<IncludeBuildOutput>false</IncludeBuildOutput>
10+
<IncludeSymbols>true</IncludeSymbols>
11+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
812
<IsRoslynComponent>true</IsRoslynComponent>
913
</PropertyGroup>
1014

ElementFactoryGenerator/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Code generator for reflection based deserialisation in Datamodel.NET

Tests/Tests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using System.Numerics;
1010
using DM = Datamodel.Datamodel;
1111
using System.Globalization;
12-
using VMAP;
12+
using Tests.VMAP;
1313

1414
namespace Datamodel_Tests
1515
{
@@ -321,7 +321,7 @@ private static void Validate_Vmap_Reflection(Datamodel.Datamodel unserialisedVma
321321
Assert.AreEqual(vertexData.size, 8);
322322
Assert.AreEqual(vertexData.streams[0]["semanticName"], "position");
323323

324-
var typedPolygonMeshData = (VMAP.CDmePolygonMeshDataStream)vertexData.streams[0];
324+
var typedPolygonMeshData = (CDmePolygonMeshDataStream)vertexData.streams[0];
325325
Assert.AreEqual(typedPolygonMeshData.semanticName, "position");
326326

327327
var typedPolygonMeshDataStream = typedPolygonMeshData.data as Vector3Array;

Tests/ValveMap.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Numerics;
33
using DMElement = Datamodel.Element;
44

5-
namespace VMAP;
5+
namespace Tests.VMAP;
66

77
#nullable enable
88

0 commit comments

Comments
 (0)