Skip to content

Commit 2825845

Browse files
committed
chore: added better documentation
1 parent 41e2aed commit 2825845

8 files changed

Lines changed: 172 additions & 377 deletions

File tree

Readme.md

Lines changed: 78 additions & 367 deletions
Large diffs are not rendered by default.

src/GameDevWare.Dynamic.Expressions.Unity.2021/Packages/com.gamedevware.csharpeval/Runtime/ArgumentsTree.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ public class ArgumentsTree : IDictionary<string, SyntaxTreeNode>
4343
/// <summary>
4444
/// Returns argument by its name.
4545
/// </summary>
46+
/// <param name="key">The name of the argument.</param>
47+
/// <returns>The syntax tree node of the argument.</returns>
4648
public SyntaxTreeNode this[string key] { get => this.innerDictionary[key]; set => throw new NotSupportedException(); }
4749
/// <summary>
4850
/// Returns argument by its position.
4951
/// </summary>
52+
/// <param name="position">The zero-based position of the argument.</param>
53+
/// <returns>The syntax tree node of the argument.</returns>
5054
public SyntaxTreeNode this[int position] { get => this.innerDictionary[Constants.GetIndexAsString(position)]; set => throw new NotSupportedException(); }
5155

5256
/// <summary>
@@ -66,7 +70,7 @@ private ArgumentsTree()
6670
/// <summary>
6771
/// Create list of arguments from existing dictionary.
6872
/// </summary>
69-
/// <param name="innerDictionary"></param>
73+
/// <param name="innerDictionary">The dictionary containing the arguments.</param>
7074
public ArgumentsTree(Dictionary<string, SyntaxTreeNode> innerDictionary)
7175
{
7276
if (innerDictionary == null) throw new ArgumentNullException(nameof(innerDictionary));
@@ -76,6 +80,7 @@ public ArgumentsTree(Dictionary<string, SyntaxTreeNode> innerDictionary)
7680
/// <summary>
7781
/// Check if passes positional argument is exists in list.
7882
/// </summary>
83+
/// <param name="position">The zero-based position of the argument.</param>
7984
/// <returns>true is exists, overwise false.</returns>
8085
public bool ContainsKey(int position)
8186
{
@@ -84,6 +89,8 @@ public bool ContainsKey(int position)
8489
/// <summary>
8590
/// Tries to retrieve argument by its position.
8691
/// </summary>
92+
/// <param name="position">The zero-based position of the argument.</param>
93+
/// <param name="value">When this method returns, contains the argument associated with the specified position, if the position is found; otherwise, null.</param>
8794
/// <returns>true is exists, overwise false.</returns>
8895
public bool TryGetValue(int position, out SyntaxTreeNode value)
8996
{
@@ -93,13 +100,16 @@ public bool TryGetValue(int position, out SyntaxTreeNode value)
93100
/// <summary>
94101
/// Compares two arguments list by reference.
95102
/// </summary>
103+
/// <param name="obj">The object to compare with the current object.</param>
104+
/// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
96105
public override bool Equals(object obj)
97106
{
98107
return this.innerDictionary.Equals(obj);
99108
}
100109
/// <summary>
101110
/// Returns hash code of arguments list.
102111
/// </summary>
112+
/// <returns>A hash code for the current object.</returns>
103113
public override int GetHashCode()
104114
{
105115
return this.innerDictionary.GetHashCode();
@@ -108,6 +118,7 @@ public override int GetHashCode()
108118
/// <summary>
109119
/// Converts argument list to string.
110120
/// </summary>
121+
/// <returns>A string that represents the current object.</returns>
111122
public override string ToString()
112123
{
113124
var sb = new StringBuilder();
@@ -129,6 +140,7 @@ void IDictionary<string, SyntaxTreeNode>.Add(string key, SyntaxTreeNode value)
129140
/// <summary>
130141
/// Check if passes named argument is exists in list.
131142
/// </summary>
143+
/// <param name="key">The name of the argument.</param>
132144
/// <returns>true is exists, overwise false.</returns>
133145
public bool ContainsKey(string key)
134146
{
@@ -143,6 +155,8 @@ bool IDictionary<string, SyntaxTreeNode>.Remove(string key)
143155
/// <summary>
144156
/// Tries to retrieve argument by its name.
145157
/// </summary>
158+
/// <param name="key">The name of the argument.</param>
159+
/// <param name="value">When this method returns, contains the argument associated with the specified name, if the name is found; otherwise, null.</param>
146160
/// <returns>true is exists, overwise false.</returns>
147161
public bool TryGetValue(string key, out SyntaxTreeNode value)
148162
{

src/GameDevWare.Dynamic.Expressions.Unity.2021/Packages/com.gamedevware.csharpeval/Runtime/Binder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public Binder(IList<ParameterExpression> parameters, Type resultType, ITypeResol
130130
/// </summary>
131131
/// <param name="node">Syntax tree. Not null.</param>
132132
/// <param name="global">Global object expression. Can be null. Usually <see cref="Expression.Constant(object)" />.</param>
133-
/// <returns></returns>
133+
/// <returns>A bound lambda expression.</returns>
134134
public LambdaExpression Bind(SyntaxTreeNode node, Expression global = null)
135135
{
136136
if (node == null) throw new ArgumentNullException(nameof(node));

src/GameDevWare.Dynamic.Expressions.Unity.2021/Packages/com.gamedevware.csharpeval/Runtime/CSharp/ParseTreeNode.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,13 @@ public override string ToString()
207207
private ParseTreeNodes nodes;
208208

209209
/// <summary>
210-
/// Get child node by index.
210+
/// Gets the child node at the specified index.
211211
/// </summary>
212-
/// <param name="index">Index of child node.</param>
213-
/// <returns>Child node at index.</returns>
212+
/// <param name="index">The zero-based index of the child node to get.</param>
213+
/// <returns>The child node at the specified index.</returns>
214214
public ParseTreeNode this[int index] => this.nodes[index];
215215
/// <summary>
216-
/// Returns number of child nodes.
216+
/// Gets the number of child nodes.
217217
/// </summary>
218218
public int Count => this.nodes.Count;
219219

@@ -283,25 +283,36 @@ public override string ToString()
283283
return sb.ToString();
284284
}
285285

286+
/// <summary>
287+
/// Returns an enumerator that iterates through the child nodes.
288+
/// </summary>
289+
/// <returns>An enumerator for the child nodes.</returns>
286290
IEnumerator<ParseTreeNode> IEnumerable<ParseTreeNode>.GetEnumerator()
287291
{
288292
for (var i = 0; i < this.nodes.Count; i++)
289293
yield return this.nodes[i];
290294
}
291295

296+
/// <summary>
297+
/// Returns an enumerator that iterates through the child nodes.
298+
/// </summary>
299+
/// <returns>An enumerator for the child nodes.</returns>
292300
IEnumerator IEnumerable.GetEnumerator()
293301
{
294302
return ((IEnumerable<ParseTreeNode>)this).GetEnumerator();
295303
}
296304

305+
/// <inheritdoc />
297306
int ILineInfo.GetLineNumber()
298307
{
299308
return this.Token.LineNumber;
300309
}
310+
/// <inheritdoc />
301311
int ILineInfo.GetColumnNumber()
302312
{
303313
return this.Token.ColumnNumber;
304314
}
315+
/// <inheritdoc />
305316
int ILineInfo.GetTokenLength()
306317
{
307318
return this.Token.TokenLength;

src/GameDevWare.Dynamic.Expressions.Unity.2021/Packages/com.gamedevware.csharpeval/Runtime/DelegateUtils.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,18 @@
33

44
namespace GameDevWare.Dynamic.Expressions
55
{
6+
/// <summary>
7+
/// Utility methods for working with delegates and reflection.
8+
/// </summary>
69
public static class DelegateUtils
710
{
11+
/// <summary>
12+
/// Creates a delegate of the specified type from the specified <see cref="MethodInfo" />.
13+
/// </summary>
14+
/// <param name="delegateType">The type of the delegate to create. Cannot be null.</param>
15+
/// <param name="method">The method to create the delegate for. Cannot be null.</param>
16+
/// <param name="throwOnBindingFailure">True to throw an exception if the delegate cannot be bound; otherwise, false.</param>
17+
/// <returns>The created delegate, or null if binding fails and <paramref name="throwOnBindingFailure" /> is false.</returns>
818
public static Delegate CreateDelegate(Type delegateType, MethodInfo method, bool throwOnBindingFailure = true)
919
{
1020
if (delegateType == null) throw new ArgumentNullException(nameof(delegateType));
@@ -27,13 +37,23 @@ public static Delegate CreateDelegate(Type delegateType, MethodInfo method, bool
2737
#endif
2838
}
2939
#if NETSTANDARD
40+
/// <summary>
41+
/// Gets the <see cref="MethodInfo" /> associated with the specified delegate instance.
42+
/// </summary>
43+
/// <param name="delegateInstance">The delegate instance. Cannot be null.</param>
44+
/// <returns>The <see cref="MethodInfo" /> of the delegate.</returns>
3045
public static MethodInfo GetMethodInfo(this Delegate delegateInstance)
3146
{
3247
if (delegateInstance == null) throw new ArgumentNullException(nameof(delegateInstance));
3348

3449
return RuntimeReflectionExtensions.GetMethodInfo(delegateInstance);
3550
}
3651
#else
52+
/// <summary>
53+
/// Gets the <see cref="MethodInfo" /> associated with the specified delegate instance.
54+
/// </summary>
55+
/// <param name="delegateInstance">The delegate instance. Cannot be null.</param>
56+
/// <returns>The <see cref="MethodInfo" /> of the delegate.</returns>
3757
public static MethodInfo GetMethodInfo(this Delegate delegateInstance)
3858
{
3959
if (delegateInstance == null) throw new ArgumentNullException("delegateInstance");

src/GameDevWare.Dynamic.Expressions.Unity.2021/Packages/com.gamedevware.csharpeval/Runtime/ExpressionPacker.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,30 @@
66

77
namespace GameDevWare.Dynamic.Expressions
88
{
9+
/// <summary>
10+
/// Provides methods for packing <see cref="Expression" /> trees into a serializable format and unpacking them back.
11+
/// </summary>
912
public static class ExpressionPacker
1013
{
14+
/// <summary>
15+
/// Packs the specified <see cref="Expression" /> into a dictionary-based serializable format.
16+
/// </summary>
17+
/// <param name="expression">The expression to pack. Cannot be null.</param>
18+
/// <returns>A dictionary representation of the packed expression.</returns>
1119
public static Dictionary<string, object> Pack(Expression expression)
1220
{
1321
if (expression == null) throw new ArgumentNullException(nameof(expression));
1422

1523
return AnyPacker.Pack(expression);
1624
}
25+
/// <summary>
26+
/// Unpacks a packed expression from its dictionary-based format back into an <see cref="Expression" />.
27+
/// </summary>
28+
/// <param name="packedExpression">The dictionary containing the packed expression. Cannot be null.</param>
29+
/// <param name="typeResolver">The type resolver to use for resolving types in the expression. Defaults to <see cref="KnownTypeResolver.Default"/>.</param>
30+
/// <param name="global">The global object expression to use as a context. Can be null.</param>
31+
/// <param name="expectedType">The expected result type of the expression. Defaults to <see cref="object"/>.</param>
32+
/// <returns>The unpacked <see cref="Expression" />.</returns>
1733
public static Expression Unpack
1834
(IDictionary<string, object> packedExpression, ITypeResolver typeResolver = null, Expression global = null, Type expectedType = null)
1935
{
@@ -31,6 +47,14 @@ public static Expression Unpack
3147

3248
return boundExpression;
3349
}
50+
/// <summary>
51+
/// Unpacks a packed expression into a <see cref="LambdaExpression" /> with the specified delegate type.
52+
/// </summary>
53+
/// <param name="delegateType">The type of the delegate to create. Cannot be null.</param>
54+
/// <param name="packedExpression">The dictionary containing the packed expression. Cannot be null.</param>
55+
/// <param name="typeResolver">The type resolver to use for resolving types. Can be null.</param>
56+
/// <param name="global">The global object expression to use as a context. Can be null.</param>
57+
/// <returns>The unpacked <see cref="LambdaExpression" />.</returns>
3458
public static LambdaExpression UnpackLambda
3559
(Type delegateType, IDictionary<string, object> packedExpression, ITypeResolver typeResolver = null, Expression global = null)
3660
{
@@ -42,6 +66,14 @@ public static LambdaExpression UnpackLambda
4266
var unpackedExpression = binder.Bind(syntaxTree, global);
4367
return unpackedExpression;
4468
}
69+
/// <summary>
70+
/// Unpacks a packed expression into an <see cref="Expression{TDelegate}" /> of the specified delegate type.
71+
/// </summary>
72+
/// <typeparam name="DelegateT">The type of the delegate.</typeparam>
73+
/// <param name="expressionTree">The dictionary containing the packed expression. Cannot be null.</param>
74+
/// <param name="typeResolver">The type resolver to use for resolving types. Can be null.</param>
75+
/// <param name="global">The global object expression to use as a context. Can be null.</param>
76+
/// <returns>The unpacked <see cref="Expression{TDelegate}" />.</returns>
4577
public static Expression<DelegateT> UnpackLambda<DelegateT>
4678
(IDictionary<string, object> expressionTree, ITypeResolver typeResolver = null, Expression global = null)
4779
{

src/GameDevWare.Dynamic.Expressions.Unity.2021/Packages/com.gamedevware.csharpeval/Runtime/ExpressionParserException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ int ILineInfo.GetTokenLength()
112112
/// <summary>
113113
/// Converts exception to string representation for debug purpose.
114114
/// </summary>
115-
/// <returns></returns>
115+
/// <returns>A string that represents the current object.</returns>
116116
public override string ToString()
117117
{
118118
if (this.TokenLength != 0)

src/GameDevWare.Dynamic.Expressions.Unity.2021/Packages/com.gamedevware.csharpeval/Runtime/SyntaxTreeNode.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class SyntaxTreeNode : IDictionary<string, object>, ILineInfo
4545
/// Returns contained node by its name;
4646
/// </summary>
4747
/// <param name="key">Name of contained node. Can't be null.</param>
48-
/// <returns></returns>
48+
/// <returns>The contained node associated with the specified key.</returns>
4949
public object this[string key] { get => this.innerDictionary[key]; set => throw new NotSupportedException(); }
5050

5151
/// <summary>
@@ -91,7 +91,7 @@ private static Dictionary<string, object> PrepareNode(IDictionary<string, object
9191
/// Default value node node with <paramref name="key" /> doesn't exists or value can't be casted
9292
/// to <typeparamref name="T" />.
9393
/// </param>
94-
/// <returns>True is node exists and value successfully casted to <typeparamref name="T" />, overwise false.</returns>
94+
/// <returns>The value of the node if it exists and can be cast to <typeparamref name="T" />; otherwise, <paramref name="defaultValue"/>.</returns>
9595
public T GetValueOrDefault<T>(string key, T defaultValue = default)
9696
{
9797
var value = default(T);
@@ -531,13 +531,16 @@ internal string GetCSharpExpressionOrNull(bool throwOnError)
531531
/// <summary>
532532
/// Compares two syntax tree by reference.
533533
/// </summary>
534+
/// <param name="obj">The object to compare with the current object.</param>
535+
/// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
534536
public override bool Equals(object obj)
535537
{
536538
return this.innerDictionary.Equals(obj);
537539
}
538540
/// <summary>
539541
/// Get hash code of syntax tree.
540542
/// </summary>
543+
/// <returns>A hash code for the current object.</returns>
541544
public override int GetHashCode()
542545
{
543546
return this.innerDictionary.GetHashCode();
@@ -546,7 +549,7 @@ public override int GetHashCode()
546549
/// <summary>
547550
/// Format syntax tree as a C# expression. Throw exceptions if exception could not be formed.
548551
/// </summary>
549-
/// <returns>C# Expression.</returns>
552+
/// <returns>C# Expression string.</returns>
550553
public string ToCSharpExpression()
551554
{
552555
var expression = this.GetCSharpExpressionOrNull(false);
@@ -560,6 +563,7 @@ public string ToCSharpExpression()
560563
/// <summary>
561564
/// Format syntax tree as C# expression.
562565
/// </summary>
566+
/// <returns>A string that represents the current object.</returns>
563567
public override string ToString()
564568
{
565569
try
@@ -589,6 +593,7 @@ void IDictionary<string, object>.Add(string key, object value)
589593
/// Check if syntax tree contain node with specified <paramref name="key" />.
590594
/// </summary>
591595
/// <param name="key">Name of contained node. Can't be null.</param>
596+
/// <returns>true if the syntax tree contains a node with the specified key; otherwise, false.</returns>
592597
public bool ContainsKey(string key)
593598
{
594599
return this.innerDictionary.ContainsKey(key);
@@ -602,6 +607,8 @@ bool IDictionary<string, object>.Remove(string key)
602607
/// <summary>
603608
/// Tries to retrieve node of syntax tree by its name.
604609
/// </summary>
610+
/// <param name="key">The name of the node to retrieve.</param>
611+
/// <param name="value">When this method returns, contains the node associated with the specified name, if the name is found; otherwise, null.</param>
605612
/// <returns>True is node exists, overwise false.</returns>
606613
public bool TryGetValue(string key, out object value)
607614
{

0 commit comments

Comments
 (0)