Confuser.Core/ProtectionParameters.cs
/// <summary>
///     Obtains the value of a parameter of the specified target.
/// </summary>
/// <typeparam name="T">The type of the parameter value.</typeparam>
/// <param name="context">The working context.</param>
/// <param name="target">The protection target.</param>
/// <param name="name">The name of the parameter.</param>
/// <param name="defValue">Default value if the parameter does not exist.</param>
/// <returns>The value of the parameter.</returns>
// Token: 0x060002F5 RID: 757 RVA: 0x0001266C File Offset: 0x0001086C
Obtains the value of a parameter of the specified target.
Obtains the value of a parameter of the specified target .
public T GetParameter<T>(ConfuserContext context, IDnlibDef target, string name, T defValue = default(T))
		{
			if (this.comp == null)
			{
				return defValue;
			}
			if (this.comp is Packer && target == null)
			{
				target = context.Modules[0];
			}
			ProtectionSettings objParams = context.Annotations.Get<ProtectionSettings>(target, ProtectionParameters.ParametersKey, null);
			if (objParams == null)
			{
				return defValue;
			}
			Dictionary<string, string> parameters;
			if (!objParams.TryGetValue(this.comp, out parameters))
			{
				return defValue;
			}
			string ret;
			if (!parameters.TryGetValue(name, out ret))
			{
				return defValue;
			}
			Type paramType = typeof(T);
			Type nullable = Nullable.GetUnderlyingType(paramType);
			if (nullable != null)
			{
				paramType = nullable;
			}
			if (paramType.IsEnum)
			{
				return (T)((object)Enum.Parse(paramType, ret, true));
			}
			return (T)((object)Convert.ChangeType(ret, paramType));
		}
public T GetParameter < T > ( ConfuserContext context , IDnlibDef target , string name , T defValue = default ( T ) ) { if ( this . comp == null ) { return defValue ; } if ( this . comp is Packer && target == null ) { target = context . Modules [ 0 ] ; } ProtectionSettings objParams = context . Annotations . Get < ProtectionSettings > ( target , ProtectionParameters . ParametersKey , null ) ; if ( objParams == null ) { return defValue ; } Dictionary < string , string > parameters ; if ( ! objParams . TryGetValue ( this . comp , out parameters ) ) { return defValue ; } string ret ; if ( ! parameters . TryGetValue ( name , out ret ) ) { return defValue ; } Type paramType = typeof ( T ) ; Type nullable = Nullable . GetUnderlyingType ( paramType ) ; if ( nullable != null ) { paramType = nullable ; } if ( paramType . IsEnum ) { return ( T ) ( ( object ) Enum . Parse ( paramType , ret , true ) ) ; } return ( T ) ( ( object ) Convert . ChangeType ( ret , paramType ) ) ; }
Obtains the value of a parameter of the specified target.
Obtains the value of a parameter of the specified target .
The value of the parameter.
The value of the parameter .
context
ConfuserContext
The working context.
The working context .
target
IDnlibDef
The protection target.
The protection target .
name
string
The name of the parameter.
The name of the parameter .
defValue
T
Default value if the parameter does not exist.
Default value if the parameter does not exist .
typeparam
The type of the parameter value.
The type of the parameter value .