StringArg

Namespace: Svg
We found 10 examples in language CSharp for this search. You will see 32 fragments of code.

Other methods

namespace EasyRpc.Tests.Classes.Simple
{


    #region ISomePropertyService

    public interface ISomePropertyService
    {
        object SomeProperty { get; }
    }

    public class StringArgSomePropertyService : ISomePropertyService
    {
        public StringArgSomePropertyService(string testString)
        {
            SomeProperty = testString;
        }

        public object SomeProperty { get; private set; }
    }

    public class ReferenceArgSomePropertyService : ISomePropertyService
    {
        public ReferenceArgSomePropertyService(IBasicService basicService)
        {
            SomeProperty = basicService;
        }

        public object SomeProperty { get; private set; }
    }

    #endregion

    #region IArrayOfObjectsPropertyService

    public interface IArrayOfObjectsPropertyService
    {
        object[] Parameters { get; }
    }

    public class OneArgStringParameterService : IArrayOfObjectsPropertyService
    {
        public delegate IArrayOfObjectsPropertyService Activate(string stringArg);

        public OneArgStringParameterService(string stringArg)
        {
            Parameters = new object[] { stringArg };
        }

        public object[] Parameters { get; private set; }
    }

    public class OneArgRefParameterService : IArrayOfObjectsPropertyService
    {
        public delegate IArrayOfObjectsPropertyService ActivateWithBasicService(IBasicService basicService);

        public delegate IArrayOfObjectsPropertyService ActivateWithOutBasicService();

        public OneArgRefParameterService(IBasicService basicService)
        {
            Parameters = new object[] { basicService };
        }

        public object[] Parameters { get; private set; }
    }

    public class TwoArgParameterService : IArrayOfObjectsPropertyService
    {
        public delegate IArrayOfObjectsPropertyService ActivateWithBasicService(
            string stringArg,
            IBasicService basicService);

        public delegate IArrayOfObjectsPropertyService ActivateWithOutBasicService(
            string stringArg);

        public delegate IArrayOfObjectsPropertyService ActivateWithOutBasicServiceAndOutOfOrder(
            string stringArg);

        public TwoArgParameterService(string stringArg, IBasicService basicService)
        {
            Parameters = new object[] { stringArg, basicService };
        }

        public object[] Parameters { get; private set; }
    }

    public class ThreeArgParameterService : IArrayOfObjectsPropertyService
    {
        public delegate IArrayOfObjectsPropertyService ActivateWithBasicService(
            string stringArg,
            int intArg,
            IBasicService basicService);

        public delegate IArrayOfObjectsPropertyService ActivateWithOutBasicService(
            string stringArg,
            int intArg);

        public delegate IArrayOfObjectsPropertyService ActivateWithOutBasicServiceAndOutOfOrder(
            int intArg,
            string stringArg);

        public ThreeArgParameterService(string stringArg, int intArg, IBasicService basicService)
        {
            Parameters = new object[] { stringArg, intArg, basicService };
        }

        public object[] Parameters { get; private set; }
    }

    public class FourArgParameterService : IArrayOfObjectsPropertyService
    {
        public delegate IArrayOfObjectsPropertyService ActivateWithBasicService(
            string stringArg,
            int intArg,
            double doubleArg,
            IBasicService basicService);

        public delegate IArrayOfObjectsPropertyService ActivateWithOutBasicService(
            string stringArg,
            int intArg,
            double doubleArg);

        public delegate IArrayOfObjectsPropertyService ActivateWithOutBasicServiceAndOutOfOrder(
            double doubleArg,
            int intArg,
            string stringArg);

        public FourArgParameterService(string stringArg, int intArg, double doubleArg, IBasicService basicService)
        {
            Parameters = new object[] { stringArg, intArg, doubleArg, basicService };
        }

        public object[] Parameters { get; private set; }
    }

    public class FiveArgParameterService : IArrayOfObjectsPropertyService
    {
        public delegate IArrayOfObjectsPropertyService ActivateWithBasicService(
            string stringArg,
            int intArg,
            double doubleArg,
            decimal decimalArg,
            IBasicService basicService);

        public delegate IArrayOfObjectsPropertyService ActivateWithOutBasicService(
            string stringArg,
            int intArg,
            double doubleArg,
            decimal decimalArg);

        public delegate IArrayOfObjectsPropertyService ActivateWithOutBasicServiceAndOutOfOrder(
            decimal decimalArg,
            string stringArg,
            double doubleArg,
            int intArg);

        public FiveArgParameterService(string stringArg,
            int intArg,
            double doubleArg,
            decimal decimalArg,
            IBasicService basicService)
        {
            Parameters = new object[] { stringArg, intArg, doubleArg, decimalArg, basicService };
        }

        public object[] Parameters { get; private set; }
    }

    #endregion
}

namespace Grace.Tests.Classes.Simple
{


    #region ISomePropertyService

    public interface ISomePropertyService
    {
        object SomeProperty { get; }
    }

    public class StringArgSomePropertyService : ISomePropertyService
    {
        public StringArgSomePropertyService(string testString)
        {
            SomeProperty = testString;
        }

        public object SomeProperty { get; private set; }
    }

    public class ReferenceArgSomePropertyService : ISomePropertyService
    {
        public ReferenceArgSomePropertyService(IBasicService basicService)
        {
            SomeProperty = basicService;
        }

        public object SomeProperty { get; private set; }
    }

    #endregion

    #region IArrayOfObjectsPropertyService

    public interface IArrayOfObjectsPropertyService
    {
        object[] Parameters { get; }
    }

    public class OneArgStringParameterService : IArrayOfObjectsPropertyService
    {
        public delegate IArrayOfObjectsPropertyService Activate(string stringArg);

        public OneArgStringParameterService(string stringArg)
        {
            Parameters = new object[] { stringArg };
        }

        public object[] Parameters { get; private set; }
    }

    public class OneArgRefParameterService : IArrayOfObjectsPropertyService
    {
        public delegate IArrayOfObjectsPropertyService ActivateWithBasicService(IBasicService basicService);

        public delegate IArrayOfObjectsPropertyService ActivateWithOutBasicService();

        public OneArgRefParameterService(IBasicService basicService)
        {
            Parameters = new object[] { basicService };
        }

        public object[] Parameters { get; private set; }
    }

    public class TwoArgParameterService : IArrayOfObjectsPropertyService
    {
        public delegate IArrayOfObjectsPropertyService ActivateWithBasicService(
            string stringArg,
            IBasicService basicService);

        public delegate IArrayOfObjectsPropertyService ActivateWithOutBasicService(
            string stringArg);

        public delegate IArrayOfObjectsPropertyService ActivateWithOutBasicServiceAndOutOfOrder(
            string stringArg);

        public TwoArgParameterService(string stringArg, IBasicService basicService)
        {
            Parameters = new object[] { stringArg, basicService };
        }

        public object[] Parameters { get; private set; }
    }

    public class ThreeArgParameterService : IArrayOfObjectsPropertyService
    {
        public delegate IArrayOfObjectsPropertyService ActivateWithBasicService(
            string stringArg,
            int intArg,
            IBasicService basicService);

        public delegate IArrayOfObjectsPropertyService ActivateWithOutBasicService(
            string stringArg,
            int intArg);

        public delegate IArrayOfObjectsPropertyService ActivateWithOutBasicServiceAndOutOfOrder(
            int intArg,
            string stringArg);

        public ThreeArgParameterService(string stringArg, int intArg, IBasicService basicService)
        {
            Parameters = new object[] { stringArg, intArg, basicService };
        }

        public object[] Parameters { get; private set; }
    }

    public class FourArgParameterService : IArrayOfObjectsPropertyService
    {
        public delegate IArrayOfObjectsPropertyService ActivateWithBasicService(
            string stringArg,
            int intArg,
            double doubleArg,
            IBasicService basicService);

        public delegate IArrayOfObjectsPropertyService ActivateWithOutBasicService(
            string stringArg,
            int intArg,
            double doubleArg);

        public delegate IArrayOfObjectsPropertyService ActivateWithOutBasicServiceAndOutOfOrder(
            double doubleArg,
            int intArg,
            string stringArg);

        public FourArgParameterService(string stringArg, int intArg, double doubleArg, IBasicService basicService)
        {
            Parameters = new object[] { stringArg, intArg, doubleArg, basicService };
        }

        public object[] Parameters { get; private set; }
    }

    public class FiveArgParameterService : IArrayOfObjectsPropertyService
    {
        public delegate IArrayOfObjectsPropertyService ActivateWithBasicService(
            string stringArg,
            int intArg,
            double doubleArg,
            decimal decimalArg,
            IBasicService basicService);

        public delegate IArrayOfObjectsPropertyService ActivateWithOutBasicService(
            string stringArg,
            int intArg,
            double doubleArg,
            decimal decimalArg);

        public delegate IArrayOfObjectsPropertyService ActivateWithOutBasicServiceAndOutOfOrder(
            decimal decimalArg,
            string stringArg,
            double doubleArg,
            int intArg);

        public FiveArgParameterService(string stringArg,
            int intArg,
            double doubleArg,
            decimal decimalArg,
            IBasicService basicService)
        {
            Parameters = new object[] { stringArg, intArg, doubleArg, decimalArg, basicService };
        }

        public object[] Parameters { get; private set; }
    }

    #endregion
}


        [Test]
        public void Should_do_with_argument_as_directed_and_if_pain_persists_see_your_coder()
        {
            string stringArg = null;
            _sub.Bar(Arg.Do<string>(x => stringArg = x), 1, _someObject);

            _sub.Bar("hello world", 1, _someObject);

            Assert.That(stringArg, Is.EqualTo("hello world"));
        }

        [Test]
        public void Setting_an_argument_do_should_not_count_as_a_call()
        {
            string stringArg = null;
            _sub.Bar(Arg.Do<string>(x => stringArg = x), 1, _someObject);

            _sub.DidNotReceiveWithAnyArgs().Bar(null, 0, null);
            Assert.That(stringArg, Is.Null);
        }

        [Test]
        public void Arg_do_with_when_for_any_args()
        {
            string stringArg = null;
            _sub.WhenForAnyArgs(x => x.Bar(Arg.Do<string>(arg => stringArg = arg), 1, _someObject)).Do(x => { });

            _sub.Bar("hello world", 42, null);

            Assert.That(stringArg, Is.EqualTo("hello world"));
        }

        [Test]
        public void Arg_do_when_action_requires_more_specific_type_should_only_run_action_when_arg_is_of_compatible_type()
        {
            string stringArg = null;
            _sub.Zap(Arg.Do<string>(arg => stringArg = arg));

            _sub.Zap("hello world");
            _sub.Zap(new object());

            Assert.That(stringArg, Is.EqualTo("hello world"));
        }


        [Test]
        public void Should_do_with_argument_as_directed_and_if_pain_persists_see_your_coder()
        {
            string stringArg = null;
            _sub.Bar(Arg.Do<string>(x => stringArg = x), 1, _someObject);

            _sub.Bar("hello world", 1, _someObject);

            Assert.That(stringArg, Is.EqualTo("hello world"));
        }

        [Test]
        public void Setting_an_argument_do_should_not_count_as_a_call()
        {
            string stringArg = null;
            _sub.Bar(Arg.Do<string>(x => stringArg = x), 1, _someObject);

            _sub.DidNotReceiveWithAnyArgs().Bar(null, 0, null);
            Assert.That(stringArg, Is.Null);
        }

        [Test]
        public void Arg_do_with_when_for_any_args()
        {
            string stringArg = null;
            _sub.WhenForAnyArgs(x => x.Bar(Arg.Do<string>(arg => stringArg = arg), 1, _someObject)).Do(x => { });

            _sub.Bar("hello world", 42, null);

            Assert.That(stringArg, Is.EqualTo("hello world"));
        }

        [Test]
        public void Arg_do_when_action_requires_more_specific_type_should_only_run_action_when_arg_is_of_compatible_type()
        {
            string stringArg = null;
            _sub.Zap(Arg.Do<string>(arg => stringArg = arg));

            _sub.Zap("hello world");
            _sub.Zap(new object());

            Assert.That(stringArg, Is.EqualTo("hello world"));
        }

        
        #endregion

        #region TOKEN INDEX FUNCTIONS

        protected internal void XDocIter(XElement xDoc, string stringArg)
        {
            ApplyStringValue(xDoc, stringArg);

            if(xDoc.HasElements)
                XDocIter((XElement)xDoc.FirstNode, stringArg);
            if(xDoc.NextNode != null)
                XDocIter((XElement)xDoc.NextNode, stringArg);
        }

        protected internal List<Token> AppendHeadToken(List<Token> allTokens, string stringArg)
        {
            //add a document level token to the all-tokens stack - needed for comparasion
            allTokens.Add(new TokenPair(0, stringArg.Length));
            allTokens = allTokens.OrderBy(t => t.Start).ToList();
            return allTokens;
        }


    [SetUp]
    public void SetUp() {
      node_ = new ProviderNode.Builder("provider",
        typeof (TestFactory).AssemblyQualifiedName)
        .Build();
    }

    [Test]
    public void ShouldNotThrowExceptionWhenTypeLoadFail() {
      try {
        var obj = RuntimeTypeFactory<TestFactory>
          .CreateInstanceNoException(node_, string.Empty);
        Assert.That(obj, Is.Null,
          "A exception should be raised but not propagated");
      } catch {
        Assert.Fail("Any raised exception should be not propagated");
      }
    }

    [Test]
    public void ShouldThrowExceptionWhenTypeLoadFail() {
      Assert.That(() => RuntimeTypeFactory<TestFactory>
        .CreateInstance(node_, string.Empty), Throws.Exception);
    }

    [Test]
    public void ShouldCreateInstanceForDefaultConstructor() {
      object obj = RuntimeTypeFactory<ITestFactory>.CreateInstance(node_);
      Assert.That(obj, Is.AssignableTo<TestFactory>());

      obj = RuntimeTypeFactory<ITestFactory>.CreateInstanceFallback(node_);
      Assert.That(obj, Is.AssignableTo<TestFactory>());

      obj = RuntimeTypeFactory<ITestFactory>.CreateInstanceNoException(node_);
      Assert.That(obj, Is.AssignableTo<TestFactory>());
    }

    [Test]
    public void ShouldCreateInstanceForNonDefaultConstructor() {
      object obj = RuntimeTypeFactory<ITestFactory>.CreateInstance(node_, 0);
      Assert.That(obj, Is.AssignableTo<TestFactory>());
      Assert.That(((TestFactory) obj).Arg, Is.EqualTo(0));

      obj = RuntimeTypeFactory<ITestFactory>.CreateInstanceFallback(node_, 10);
      Assert.That(obj, Is.AssignableTo<TestFactory>());
      Assert.That(((TestFactory) obj).Arg, Is.EqualTo(10));

      obj = RuntimeTypeFactory<ITestFactory>.CreateInstanceNoException(node_, 20);
      Assert.That(obj, Is.AssignableTo<TestFactory>());
      Assert.That(((TestFactory) obj).Arg, Is.EqualTo(20));
    }

    [Test]
    public void ShouldUseDefaultConstructorWhenMatchIsNotFound() {
      object obj = RuntimeTypeFactory<ITestFactory>
        .CreateInstanceFallback(node_, string.Empty);
      Assert.That(obj, Is.AssignableTo<TestFactory>());
      Assert.That(((TestFactory) obj).Arg, Is.EqualTo(-1));
    }

		public string Simulate(string stringArg, SampleClass sample)
		{
			var del = new DelegateWithArguments();
			var args = new MethodArgument[2];
            
			var arg = new MethodArgument();
            
			arg.Index = 0;
			arg.Name = "stringArg";
			arg.Value = stringArg;
			args[0] = arg;

			var arg1 = new MethodArgument();

			arg1.Index = 1;
			arg1.Name = "sample";
			arg1.Value = sample;
            
			args[1] = arg1;

			return del.Process(() => "lol", args);
		}


        void DecideArgType(string arg)
        {
            if (arg == TableArg)
            {
                ArgType = BDDStepArgType.TableArg;
            }
            else if (arg == DocStringArg)
            {
                ArgType = BDDStepArgType.DocStringArg;
            }
            else if ((arg.Length == 0) || (arg[0] == '\"'))
            {
                ArgType = BDDStepArgType.StringArg;
                RegexPattern = BDDUtil.StringRegex;
            }
            else if ((arg[0] == '<') && (arg[arg.Length - 1] == '>'))
            {
                ArgType = BDDStepArgType.TableColumnArg;
                RegexPattern = arg;
            }
            else if (!arg.Contains("."))
            {
                ArgType = BDDStepArgType.IntArg;
                RegexPattern = BDDUtil.IntRegex;
            }
            else
            {
                ArgType = BDDStepArgType.FloatArg;
                RegexPattern = BDDUtil.FloatRegex;
            }
        }


        internal void InternalVoidMethod()
        {
            LogMemberCalled();
        }

        private void PrivateVoidMethod()
        {
            LogMemberCalled();
        }

        protected void ProtectedVoidMethod()
        {
            LogMemberCalled();
        }

        public void PublicVoidMethod()
        {
            LogMemberCalled();
        }

        internal string InternalStringMethod()
        {
            LogMemberCalled();
            return "success";
        }

        private string PrivateStringMethod()
        {
            LogMemberCalled();
            return "success";
        }


		/// <summary>
		/// Checks whether Args contains a -Param statement, if so returns true else
		/// returns Default
		/// </summary>
		/// <param name="Param"></param>
		/// <param name="Default"></param>
		/// <param name="Args"></param>
		/// <returns></returns>
		static protected bool SwitchExists(string Param, string[] Args)
		{
			foreach (string Arg in Args)
			{
				string StringArg = Arg;

				if (StringArg.StartsWith("-"))
				{
					StringArg = Arg.Substring(1);
				}

				if (StringArg.ToString().Equals(Param, StringComparison.InvariantCultureIgnoreCase))
				{
					return true;
				}
			}
			return false;
		}

		/// <summary>
		/// Checks Args for a -param=value statement and either returns value or the
		/// provided default
		/// </summary>
		/// <param name="Param"></param>
		/// <param name="Default"></param>
		/// <param name="Args"></param>
		/// <returns></returns>
		static protected object ParaseAndCoerceParam(string Param, Type ParamType, string[] Args)
		{
			if (!Param.EndsWith("="))
			{
				Param += "=";
			}
			foreach (string Arg in Args)
			{
				string StringArg = Arg;

				if (StringArg.StartsWith("-"))
				{
					StringArg = Arg.Substring(1);
				}

				if (StringArg.StartsWith(Param, StringComparison.InvariantCultureIgnoreCase))
				{
					string StringVal = StringArg.Substring(Param.Length);

					if (ParamType.IsEnum)
					{
						var AllValues = Enum.GetValues(ParamType).Cast<object>();

						var Enums = AllValues.Where(P => string.Equals(StringVal, P.ToString(), StringComparison.OrdinalIgnoreCase));

						if (Enums.Count() == 0)
						{
							Log.Error("Could not convert param {0} to enum of type {1}", StringVal, ParamType);
						}

						return Enums.First();
					}
					else
					{
						return Convert.ChangeType(StringVal, ParamType);
					}
				}
			}

			return null;
		}

		/// <summary>
		/// Returns true if this type is considered a simple primitive (there is IsClass in c# but no IsStruct :()
		/// </summary>
		/// <param name="type"></param>
		/// <returns></returns>
		static bool IsSimple(Type type)
		{
			return type.IsPrimitive
			  || type.IsEnum
			  || type.Equals(typeof(string))
			  || type.Equals(typeof(decimal));
		}

		/// <summary>
		/// Call to process all CommandLineOption attributes on an objects members and set them based on the
		/// provided argument list
		/// </summary>
		/// <param name="Obj"></param>
		/// <param name="Args"></param>
		protected static void ApplyParamsAndDefaultsInternal(object Obj, string[] Args, bool ApplyDefaults)
		{
			// get all field and property members
			var Fields = Obj.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
			var Properties = Obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

			var AllMembers = Fields.Cast<MemberInfo>().Concat(Properties);

			foreach (var Member in AllMembers)
			{
				Type MemberType = null;

				// Get the type of the member (note - this is not Member.Type!)
				if (Member is PropertyInfo)
				{
					MemberType = ((PropertyInfo)Member).PropertyType;
				}
				else if (Member is FieldInfo)
				{
					MemberType = ((FieldInfo)Member).FieldType;
				}

				// Go through all attributes
				foreach (object Attrib in Member.GetCustomAttributes(true))
				{
					if (Attrib is AutoParam)
					{
						// If this is a struct then we want to recurse
						if (IsSimple(MemberType) == false)
						{
							object Value = null;

							// Get the reference value
							if (Member is PropertyInfo)
							{
								Value = ((PropertyInfo)Member).GetValue(Obj);
							}
							else if (Member is FieldInfo)
							{
								Value = ((FieldInfo)Member).GetValue(Obj);
							}

							// if null create a new one (e.g. a new instance of a struct);
							if (Value == null)
							{
								try
								{
									Value = Activator.CreateInstance(MemberType);
								}
								catch
								{
									throw new AutomationException("Add a default constructor to the class {0}!", MemberType);
								}

								// Set the new object as the refernce
								if (Member is PropertyInfo)
								{
									((PropertyInfo)Member).SetValue(Obj, Value);
								}
								else if (Member is FieldInfo)
								{
									((FieldInfo)Member).SetValue(Obj, Value);
								}
							}

							// Recurse into this struct
							ApplyParamsAndDefaultsInternal(Value, Args, ApplyDefaults);
						}
						else
						{
							AutoParam Opt = Attrib as AutoParam;

							// if the attribute had names provided use them, else use the name of the variable
							string[] ParamNames = (Opt.OptionNames != null && Opt.OptionNames.Length > 0) ? Opt.OptionNames : new string[] { Member.Name };

							// save the default
							object DefaultValue = Opt.Default;
							object NewValue = null;

							if (DefaultValue.GetType() != MemberType)
							{
								Log.Warning("AutoParam default value for member {0} is type {1}, not {2}", Member.Name, DefaultValue.GetType(), MemberType);
							}

							// Go through all params used to refer to this member
							foreach (string Name in ParamNames)
							{
								// if default is a bool then just check if the switch exists
								if (MemberType == typeof(bool))
								{
									if (SwitchExists(Name, Args))
									{
										NewValue = true;
									}
								}
								else
								{
									// for all other types try to parse out the value
									NewValue = ParaseAndCoerceParam(Name, MemberType, Args);
								}

								// stop as soon as we find something
								if (NewValue != null)
								{
									break;
								}
							}

							// If no value was found, use the default
							if (NewValue != null || (ApplyDefaults && DefaultValue != null))
							{
								if (NewValue == null)
								{
									NewValue = DefaultValue;
								}

								if (MemberType.IsEnum)
								{
									if (NewValue.GetType() != MemberType)
									{
										Log.Warning("Default for member {0} is an enum of an incorrect type!", Member.Name);
									}
								}
								else
								{
									// Force a conversion - need to do this even for default values incase someone specified a double for a float
									NewValue = Convert.ChangeType(NewValue, MemberType);
								}

								// Set the value on the member
								if (Member is PropertyInfo)
								{
									((PropertyInfo)Member).SetValue(Obj, NewValue);
								}
								else if (Member is FieldInfo)
								{
									((FieldInfo)Member).SetValue(Obj, NewValue);
								}
							}
						}
					}
				}
			}

			IAutoParamNotifiable ParamNotifable = Obj as IAutoParamNotifiable;

			if (ParamNotifable != null)
			{
				ParamNotifable.ParametersWereApplied(Args);
			}
		}

		public static void ApplyDefaults(object Obj)
		{
			ApplyParamsAndDefaultsInternal(Obj, new string[0], true);
		}

		public static void ApplyParams(object Obj, string[] Args)
		{
			ApplyParamsAndDefaultsInternal(Obj, Args, false);
		}

Svg.StringArg : SVGArg

Fields :

public String s
public String SessionID

Constructors :

public StringArg()

Methods :

public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()