-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/orcomp 644 #278
base: develop
Are you sure you want to change the base?
Feature/orcomp 644 #278
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace Orc.CommandLine | ||
{ | ||
using System.Collections.Generic; | ||
public class CommandLineParsingContextBase : ICommandLineParsingContext | ||
{ | ||
public CommandLineParsingContextBase(string commandLine) | ||
{ | ||
QuoteSplitCharacters = new List<char>(new[] { '\"', '\'' }); | ||
CommandLine = commandLine; | ||
} | ||
|
||
public CommandLineParsingContextBase() | ||
{ | ||
} | ||
|
||
public List<char> QuoteSplitCharacters { get; } | ||
|
||
public string CommandLine { get; set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Orc.CommandLine | ||
{ | ||
using System.Collections.Generic; | ||
|
||
public interface ICommandLineParsingContext | ||
{ | ||
string CommandLine { get; set; } | ||
List<char> QuoteSplitCharacters { get; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,19 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="IContext.cs" company="WildGums"> | ||
// Copyright (c) 2008 - 2015 WildGums. All rights reserved. | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
|
||
namespace Orc.CommandLine | ||
namespace Orc.CommandLine | ||
{ | ||
using System.Collections.Generic; | ||
|
||
public interface IContext | ||
public interface IContext : ICommandLineParsingContext | ||
{ | ||
#region Properties | ||
string OriginalCommandLine { get; set; } | ||
|
||
bool IsHelp { get; set; } | ||
|
||
Dictionary<string, string> RawValues { get; } | ||
|
||
List<char> QuoteSplitCharacters { get; } | ||
#endregion | ||
|
||
#region Methods | ||
void Finish(); | ||
#endregion | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Orc.CommandLine | ||
{ | ||
using Catel.Data; | ||
|
||
public interface IResult : IContext | ||
{ | ||
#region Properties | ||
ValidationContext ValidationContext { get; set; } | ||
#endregion | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Orc.CommandLine | ||
{ | ||
using Catel.Data; | ||
|
||
public interface IValidatedResult : IContext | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. read the comments for the IResult |
||
{ | ||
public IValidationContext ValidationContext { get; set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace Orc.CommandLine | ||
{ | ||
using System.Collections.Generic; | ||
using Catel.Data; | ||
|
||
public abstract class ResultBase : IResult | ||
{ | ||
public string OriginalCommandLine { get; set; } | ||
|
||
public bool IsHelp { get; set; } | ||
|
||
public Dictionary<string, string> RawValues { get; set; } | ||
|
||
public ValidationContext ValidationContext { get; set; } | ||
|
||
public string CommandLine { get; set; } | ||
|
||
public List<char> QuoteSplitCharacters { get; set; } | ||
|
||
public void Finish() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure why we need it |
||
{ | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
namespace Orc.CommandLine | ||
{ | ||
using System; | ||
using System.Reflection; | ||
|
||
internal static class PropertyHelper | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename the class to ObjectExtensions |
||
{ | ||
|
||
internal static void SetPrivatePropertyValue(this object obj, string propName, object value) | ||
{ | ||
var objType = obj.GetType(); | ||
var property = objType.GetProperty(propName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); | ||
if (property is null) | ||
{ | ||
throw new InvalidOperationException($"Property {propName} was not found in Type {objType}"); | ||
} | ||
var setter = property.GetSetMethod(nonPublic: true); | ||
if (setter is null) | ||
{ | ||
var backingField = property.DeclaringType.GetField($"<{property.Name}>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance); | ||
if (backingField is null) | ||
{ | ||
throw new InvalidOperationException( | ||
$"Could not find a way to set {property.DeclaringType.FullName}.{property.Name}. Try adding a private setter."); | ||
} | ||
backingField.SetValue(obj, value); | ||
} | ||
else | ||
{ | ||
setter.Invoke(obj, new object[] | ||
{ | ||
value | ||
}); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one of the points of the issue is to split
IContext
intoIResult
andICommandLineParsingContext
it means
IResult
should not be inherited fromIContext
I would extract two different interfaces from
IContext
:ICommandLineParsingContext
and something likeICommandLineParsingResult
and do something like that: