Skip to content

Commit

Permalink
Merge pull request #2 from 210342/FirstEval_FIX#1
Browse files Browse the repository at this point in the history
First eval fix#1
  • Loading branch information
210342 authored Nov 22, 2018
2 parents 0822083 + 5501e79 commit 602b3dc
Show file tree
Hide file tree
Showing 34 changed files with 454 additions and 155 deletions.
4 changes: 2 additions & 2 deletions CommandLineInterface/CommandLineInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public class CommandLineInterface

public void Start(string dllPath)
{
dataContext.FileSourceProvider = new TextFileSourceProvider(dllPath); //source provider
try
{
dataContext.LoadedAssembly = dllPath;
dataContext.ReloadAssemblyCommand.Execute(null);
dataContext.OpenFileCommand.Execute(null);
}
catch (FileNotFoundException e)
{
Expand Down
1 change: 1 addition & 0 deletions CommandLineInterface/CommandLineInterface.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<Compile Include="CommandLineInterface.cs" />
<Compile Include="Startup.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TextFileSourceProvider.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand Down
22 changes: 22 additions & 0 deletions CommandLineInterface/TextFileSourceProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Library.Logic.ViewModel;

namespace CommandLineInterface
{
internal class TextFileSourceProvider : ISourceProvider
{
string path;
internal TextFileSourceProvider(string dllPath)
{
this.path = dllPath;
}
public bool GetAccess()
{
return System.IO.File.Exists(this.path);
}

public string GetFilePath()
{
return this.path;
}
}
}
25 changes: 25 additions & 0 deletions GraphicalUserInterface/FileDialogProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Library.Logic.ViewModel;
using System;

namespace GraphicalUserInterface
{
internal class FileDialogProvider : ISourceProvider
{
Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog();
internal FileDialogProvider()
{
dialog.DefaultExt = "dll";
dialog.Filter = "Dynamically linked library (*dll)|*dll|All Files(*.*)|*.*";
}

public bool GetAccess()
{
return dialog.ShowDialog().Value;
}

public string GetFilePath()
{
return dialog.FileName;
}
}
}
1 change: 1 addition & 0 deletions GraphicalUserInterface/GraphicalUserInterface.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="FileDialogProvider.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
Expand Down
5 changes: 2 additions & 3 deletions GraphicalUserInterface/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
</TreeView.ItemContainerStyle>
</TreeView>
<TextBox IsEnabled="false" Text="{Binding Path=LoadedAssembly, Mode=OneWay}" x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="0,3,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="701" Grid.ColumnSpan="2"/>
<Button Click="FileDialog" x:Name="button" Content="Load" HorizontalAlignment="Left" Margin="330,4,0,0" VerticalAlignment="Top" Width="75" Grid.Column="1"/>
<TextBlock x:Name="textBlock" Grid.Column="1" HorizontalAlignment="Left" Margin="10,32,0,0" TextWrapping="Wrap" Text="{Binding Path=ObjectToDisplay.Details}" VerticalAlignment="Top" Height="356" Width="395"/>
<Button x:Name="details" Command="{Binding ShowCurrentObject}" Content="Show details" HorizontalAlignment="Left" Margin="10,405,0,0" VerticalAlignment="Top" Width="75"/>
<Button Command="{Binding Path=OpenFileCommand}" x:Name="button" Content="Load" HorizontalAlignment="Left" Margin="330,4,0,0" VerticalAlignment="Top" Width="75" Grid.Column="1"/>
<TextBlock x:Name="textBlock" Grid.Column="1" HorizontalAlignment="Left" Margin="10,32,0,0" TextWrapping="Wrap" Text="{Binding Path=ObjectSelected.Details}" VerticalAlignment="Top" Height="356" Width="395"/>
</Grid>
</Window>
16 changes: 2 additions & 14 deletions GraphicalUserInterface/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Library.Logic.ViewModel;
using Microsoft.Win32;
using System.Windows;

namespace GraphicalUserInterface
Expand All @@ -12,24 +11,13 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
if (DataContext is ViewModel)
((ViewModel)DataContext).FileSourceProvider = new FileDialogProvider();
}

private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
SelectedItemHelper.Content = e.NewValue;
}

private void FileDialog(object sender, RoutedEventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.DefaultExt = "dll";
dialog.Filter = "Dynamically linked library (*dll)|*dll|All Files(*.*)|*.*";
if(dialog.ShowDialog().Value)
{
var viewModel = DataContext as ViewModel;
viewModel.LoadedAssembly = dialog.FileName;
viewModel.ReloadAssemblyCommand.Execute(null);
}
}
}
}
13 changes: 13 additions & 0 deletions Library/Data/DataLoadedDictionary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Library.Data.Model;
using System.Collections.Generic;

namespace Library.Data
{
public static class DataLoadedDictionary
{
public static readonly Dictionary<int, IMetadata> Items =
new Dictionary<int, IMetadata>();
public static readonly Dictionary<System.Type, IMetadata> Types =
new Dictionary<System.Type, IMetadata>();
}
}
2 changes: 1 addition & 1 deletion Library/Data/Model/AssemblyMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Library.Data.Model
{
internal class AssemblyMetadata : IMetadata
public class AssemblyMetadata : IMetadata
{

internal AssemblyMetadata(Assembly assembly)
Expand Down
2 changes: 1 addition & 1 deletion Library/Data/Model/AttributeMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
namespace Library.Data.Model
{
internal class AttributeMetadata : IMetadata
public class AttributeMetadata : IMetadata
{
internal AttributeMetadata(Attribute attribute)
{
Expand Down
19 changes: 11 additions & 8 deletions Library/Data/Model/MethodMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@

namespace Library.Data.Model
{
internal class MethodMetadata : IMetadata
public class MethodMetadata : IMetadata
{
public string Details
{
get
{
var ret = $"{(m_ReturnType.Name != null ? "Method: " + m_ReturnType.Name : "Constructor: ")} {m_Name}(";
foreach(var param in m_Parameters)
var ret = $"{(m_ReturnType?.Name != null ? "Method: " + m_ReturnType.Name : "Constructor: ")} {m_Name}";
if(m_Parameters.Count() == 0)
{
ret += $"{param.Details}, ";
ret += $"() {Environment.NewLine}";
}
if (ret[ret.Length - 2] == ',')
else
{
ret = ret.Remove(ret.Length - 2, 1);
ret += $"(";
foreach (var param in m_Parameters)
{
ret += $"{param.Details}, ";
}
ret = ret.Remove(ret.Length - 2, 1) + ")\n";
}
ret += $")\n";

ret += $"Modifiers: {m_Modifiers.Item1.ToString()}, " +
$"{m_Modifiers.Item2.ToString()}, {m_Modifiers.Item3.ToString()}, {m_Modifiers.Item4.ToString()}.";
return ret;
Expand Down
2 changes: 1 addition & 1 deletion Library/Data/Model/NamespaceMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Library.Data.Model
{
internal class NamespaceMetadata : IMetadata
public class NamespaceMetadata : IMetadata
{
public string Details
{
Expand Down
2 changes: 1 addition & 1 deletion Library/Data/Model/ParameterMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Library.Data.Model
{
internal class ParameterMetadata : IMetadata
public class ParameterMetadata : IMetadata
{

public string Details
Expand Down
2 changes: 1 addition & 1 deletion Library/Data/Model/PropertyMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Library.Data.Model
{
internal class PropertyMetadata : IMetadata
public class PropertyMetadata : IMetadata
{
public string Details
{
Expand Down
41 changes: 25 additions & 16 deletions Library/Data/Model/TypeMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,29 @@

namespace Library.Data.Model
{
internal class TypeMetadata : IMetadata
public class TypeMetadata : IMetadata
{
public string Details
{
get
{
var ret = $"Type: {m_typeName}{(m_BaseType != null ? ",extends " + m_BaseType.Name : string.Empty)}";
if (m_ImplementedInterfaces.Count() > 0)
if (m_ImplementedInterfaces != null)
{
ret += ",implements ";
foreach (var intf in m_ImplementedInterfaces)
ret += $"{intf.Name}, ";
}
ret += $"\nType Kind: {m_TypeKind.ToString()}\n";
ret += $"Modifiers: {m_Modifiers.Item1.ToString()}," +
$"{m_Modifiers.Item2.ToString()},{m_Modifiers.Item3.ToString()}.";
ret += $"Modifiers: {m_Modifiers?.Item1.ToString()}," +
$"{m_Modifiers?.Item2.ToString()},{m_Modifiers?.Item3.ToString()}.";
return ret;
}
}
public void Build()
{

}

#region constructors
internal TypeMetadata(Type type)
Expand Down Expand Up @@ -57,20 +61,23 @@ internal TypeMetadata(Type type)
if (m_GenericArguments != null)
elems.AddRange(m_GenericArguments);
Children = elems;
_cachedHash = type.GetHashCode();
}
#endregion

#region API
internal enum TypeKind
{
EnumType, StructType, InterfaceType, ClassType
Reference, EnumType, StructType, InterfaceType, ClassType
}
internal static TypeMetadata EmitReference(Type type)
{
if (!type.IsGenericType)
return new TypeMetadata(type.Name, type.GetNamespace());
return new TypeMetadata(type.Name, type.GetNamespace(),
type.GetHashCode());
else
return new TypeMetadata(type.Name, type.GetNamespace(), EmitGenericArguments(type.GetGenericArguments()));
return new TypeMetadata(type.Name, type.GetNamespace(), EmitGenericArguments(type.GetGenericArguments()),
type.GetHashCode());
}
internal static IEnumerable<TypeMetadata> EmitGenericArguments(IEnumerable<Type> arguments)
{
Expand Down Expand Up @@ -99,17 +106,20 @@ internal static IEnumerable<TypeMetadata> EmitGenericArguments(IEnumerable<Type>
public IEnumerable<IMetadata> Children { get; }

//constructors
private TypeMetadata(string typeName, string namespaceName)
private TypeMetadata(string typeName, string namespaceName, int hash)
{
if (typeName == null || namespaceName == null)
throw new ArgumentNullException("Type can't be null.");
m_typeName = typeName;
m_NamespaceName = namespaceName;
_cachedHash = hash;
}
private TypeMetadata(string typeName, string namespaceName, IEnumerable<TypeMetadata> genericArguments) : this(typeName, namespaceName)
private TypeMetadata(string typeName, string namespaceName, IEnumerable<TypeMetadata> genericArguments, int hash)
: this(typeName, namespaceName, hash)
{
m_GenericArguments = genericArguments;
}

//methods
private TypeMetadata EmitDeclaringType(Type declaringType)
{
Expand Down Expand Up @@ -164,24 +174,23 @@ private static TypeMetadata EmitExtends(Type baseType)
}
#endregion

private int _cachedHash = 0;

public override int GetHashCode()
{
//return savedHash;
var hash = 37;
hash *= 17 + m_typeName.GetHashCode();
//hash *= 17 + m_NamespaceName.GetHashCode();
return hash;
return _cachedHash;
}

public override bool Equals(object obj)
{
if (this.GetType() != obj.GetType())
if (GetType() != obj.GetType())
return false;
TypeMetadata tm = ((TypeMetadata)obj);
if (this.m_typeName == tm.m_typeName)
if (m_typeName == tm.m_typeName)
{
if (m_NamespaceName != tm.m_NamespaceName)
return false;
return true;
}
return false;
}
Expand Down
13 changes: 10 additions & 3 deletions Library/Library.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Configuration" />
Expand Down Expand Up @@ -61,8 +59,17 @@
<Compile Include="Data\Model\TypeMetadata.cs" />
<Compile Include="Data\Model\Enums\VirtualEnum.cs" />
<Compile Include="Data\Reflector.cs" />
<Compile Include="Logic\TreeView\DataLoadedDictionary.cs" />
<Compile Include="Data\DataLoadedDictionary.cs" />
<Compile Include="Logic\TreeView\Items\PropertyItem.cs" />
<Compile Include="Logic\TreeView\Items\ParameterItem.cs" />
<Compile Include="Logic\TreeView\Items\MethodItem.cs" />
<Compile Include="Logic\TreeView\Items\NamespaceItem.cs" />
<Compile Include="Logic\TreeView\Items\AssemblyItem.cs" />
<Compile Include="Logic\TreeView\Items\AttributeItem.cs" />
<Compile Include="Logic\TreeView\Items\TreeViewItemFactory.cs" />
<Compile Include="Logic\TreeView\Items\TypeItem.cs" />
<Compile Include="Logic\TreeView\TreeViewItem.cs" />
<Compile Include="Logic\ViewModel\ISourceProvider.cs" />
<Compile Include="Logic\ViewModel\ViewModel.cs" />
<Compile Include="Logic\ViewModel\RelayCommand.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
11 changes: 0 additions & 11 deletions Library/Logic/TreeView/DataLoadedDictionary.cs

This file was deleted.

Loading

0 comments on commit 602b3dc

Please sign in to comment.