当前位置: 首页>>代码示例>>C#>>正文


C# Value.GetType方法代码示例

本文整理汇总了C#中Value.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Value.GetType方法的具体用法?C# Value.GetType怎么用?C# Value.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Value的用法示例。


在下文中一共展示了Value.GetType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ValuesAreEqual

    private static bool ValuesAreEqual(Value value1, Value value2) {
       Dictionary<Type, ValueEqualityDelegate> switcher = 
         new Dictionary<Type, ValueEqualityDelegate>();
      switcher.Add(typeof(TextValue), new ValueEqualityDelegate(TextValuesAreEqual));
      switcher.Add(typeof(NumberValue), new ValueEqualityDelegate(NumberValuesAreEqual));
      switcher.Add(typeof(BooleanValue), new ValueEqualityDelegate(BooleanValuesAreEqual));
      switcher.Add(typeof(SetValue), new ValueEqualityDelegate(SetValuesAreEqual));
      switcher.Add(typeof(DateValue), new ValueEqualityDelegate(DateValuesAreEqual));
      switcher.Add(typeof(DateTimeValue), new ValueEqualityDelegate(DateTimeValuesAreEqual));

      if (switcher.ContainsKey(value1.GetType())) {
        return switcher[value1.GetType()](value1, value2);
      }
      throw new NotImplementedException(String.Format("Unknown Value type {0}", value1.GetType()));
    }
开发者ID:markgmarkg,项目名称:googleads-dotnet-lib,代码行数:15,代码来源:StatementBuilderTests.cs

示例2: GetValue

 /// <summary>
 /// Gets the underlying value of the Value object. For SetValues, returns
 /// a List of underlying values.
 /// </summary>
 /// <value>The Value object to get the value from.</value>
 /// <returns>The underlying value, or List of underlying values from a SetValue.</returns>
 public static object GetValue(Value value) {
   if (value is SetValue) {
     PropertyInfo propInfo = value.GetType().GetProperty("values");
     if(propInfo != null) {
       Value[] setValues = propInfo.GetValue(value, null) as Value[];
       List<object> extractedValues = new List<object>();
       foreach (Value setValue in setValues) {
         validateSetValueForSet(GetValue(setValue), extractedValues);
         extractedValues.Add(GetValue(setValue));
       }
       return extractedValues;
     }
   } else {
     PropertyInfo propInfo = value.GetType().GetProperty("value");
     if (propInfo != null) {
       return propInfo.GetValue(value, null);
     }
   }
   return null;
 }
开发者ID:everlive,项目名称:googleads-dotnet-lib,代码行数:26,代码来源:PqlUtilities.cs

示例3: UnsafeInvoke

        // Like the above except exceptions are allowed to escape.
        public Value UnsafeInvoke(ThreadMirror thread, Value target, string name)
        {
            Contract.Requires(thread != null, "thread is null");
            Contract.Requires(target != null, "target is null");
            Contract.Requires(target is ObjectMirror || target is StructMirror, "target is a " + target.GetType().FullName);
            Contract.Requires(!name.IsNullOrWhiteSpace());

            Value result;
            if (target is ObjectMirror)
                result = DoInvoke(thread, (ObjectMirror) target, name);
            else
                result = DoInvoke(thread, (StructMirror) target, name);

            return result;
        }
开发者ID:andyhebear,项目名称:Continuum,代码行数:16,代码来源:InvokeMethod.cs

示例4: Evaluate

        // Target should be a ObjectMirror or a StructMirror. Name should be the name of a
        // property (e.g. Count), field (eg Empty), or nullary method. Returns an error string.
        public static Value Evaluate(ThreadMirror thread, Value target, string name)
        {
            Contract.Requires(thread != null, "thread is null");
            Contract.Requires(target != null, "target is null");
            Contract.Requires(!string.IsNullOrEmpty(name), "name is null or empty");

            Value result = null;

            // Try fields,
            if (target is ObjectMirror)
                result = DoGetField((ObjectMirror) target, name, thread);

            else if (target is StructMirror)
                result = DoGetField((StructMirror) target, name, thread);

            // properties.
            if (result == null)
            {
                if (target is ObjectMirror)
                    result = DoEvaluateProperty(thread, (ObjectMirror) target, name);

                else if (target is StructMirror)
                    result = DoEvaluateProperty(thread, (StructMirror) target, name);
            }

            // and methods.
            if (result == null)
            {
                if (target is ObjectMirror)
                    result = DoEvaluateMethod(thread, (ObjectMirror) target, name);

                else if (target is StructMirror)
                    result = DoEvaluateMethod(thread, (StructMirror) target, name);

                else
                    Contract.Assert(false, "Expected an ObjectMirror or StructMirror but got a " + target.GetType().FullName);
            }

            if (result == null)
                result = target.VirtualMachine.RootDomain.CreateString(string.Empty);	// usually ShouldEvaluate was false

            return result;
        }
开发者ID:andyhebear,项目名称:Continuum,代码行数:45,代码来源:EvalMember.cs

示例5: set

        private const int Timeout = 500; // TODO: might want to allow this to be set (especially when we get an immediate window)

        #endregion Fields

        #region Methods

        // Invokes a nullary method on an ObjectMirror or StructMirror. If the call
        // times out a StringMirror is returned with an error message.
        public Value Invoke(ThreadMirror thread, Value target, string name)
        {
            Contract.Requires(thread != null, "thread is null");
            Contract.Requires(target != null, "target is null");
            Contract.Requires(target is ObjectMirror || target is StructMirror, "target is a " + target.GetType().FullName);
            Contract.Requires(!name.IsNullOrWhiteSpace());

            Value result;

            try
            {
                result = UnsafeInvoke(thread, target, name);
            }
            catch (Exception e)
            {
                result = thread.Domain.CreateString(e.Message);
            }

            return result;
        }
开发者ID:andyhebear,项目名称:Continuum,代码行数:28,代码来源:InvokeMethod.cs

示例6: GetTypeFromValue

        /// <summary>
        /// Gets the type from the provided value.
        /// </summary>
        /// <param name="value">Value to be analyzed for the type.</param>
        /// <returns>Returns the type of the value.</returns>
        internal static Type GetTypeFromValue(Value value)
        {
            Type type = value.GetType();

            switch (type.Name)
            {
                case "DateTimeValue":
                    return typeof(DateTime);
                case "CategoryObjectListValue":
                    return typeof(IContractList<CategoryObject>);
                case "CategoryObjectValue":
                    return typeof(CategoryObject);
                case "EntityObjectListValue":
                    return typeof(IContractList<EntityObject>);
                case "EntityObjectValue":
                    return typeof(EntityObject);
                case "GuidValue":
                    return typeof(Guid);
                case "LocalStringValue":
                    return typeof(LocalString);
                case "LocalTextValue":
                    return typeof(LocalText);
                case "BooleanValue":
                    return typeof(Boolean);
                case "DecimalValue":
                    return typeof(Decimal);
                case "IntegerValue":
                    return typeof(Int32);
                case "StringValue":
                    return typeof(String);
                case "ValueObjectListValue":
                    return typeof(IContractList<ValueObject>);
                case "ValueObjectValue":
                    return typeof(ValueObject);
                default:
                    return null;
            }
        }
开发者ID:PongpetTurneo,项目名称:LightHouse,代码行数:43,代码来源:GenerateCodeService.cs

示例7: ResultCachesView

 public ResultCachesView(Value syntax, SourceView master)
     : base(master, "ResultCaches: " + syntax.GetType().PrettyName() + "-" + syntax.ObjectId)
 {
     Client = syntax.ResultCache.CreateClient(Master);
     Source = syntax.SourcePart;
 }
开发者ID:hahoyer,项目名称:reni.cs,代码行数:6,代码来源:ResultCachesView.cs

示例8: Operate

        public override Value Operate( Value First, Value Second )
        {
            if ( ( First is Identifier || Second is Identifier ) && !Compiler.Runtime ) return NoValue.Value;
            if ( First is Reference ) First = ( First as Reference ).ReferencingValue;
            if ( Second is Reference ) Second = ( Second as Reference ).ReferencingValue;

            if ( !( First is NoValue || Second is NoValue ) && First.GetType() == Second.GetType() )
            {
                if ( First is Number ) return new Boolean( ( First as Number ).Val == ( (Number)Second ).Val );
                if ( First is String ) return new Boolean( ( First as String ).Val == ( (String)Second ).Val );
                if ( First is Boolean ) return new Boolean( ( First as Boolean ).Val == ( (Boolean)Second ).Val );
                throw new Exception( "Operands are not comparable" );
            }
            throw new Exception( "Operands are not comparable" );
        }
开发者ID:LukaHorvat,项目名称:Kento,代码行数:15,代码来源:Operators.cs

示例9: CreateMenuItem

        MenuItem CreateMenuItem(Value syntax)
        {
            var text = syntax.GetType().PrettyName() + " " + syntax.ObjectId;

            if (syntax.ResultCache.Count > 1)
                text += " (" + syntax.ResultCache.Count + ")";

            var menuItem = new MenuItem
                (text, (s, a) => ResultCachesViews[syntax].Run());
            menuItem.Select += (s, a) => SignalContextMenuSelect(syntax);
            return menuItem;
        }
开发者ID:hahoyer,项目名称:reni.cs,代码行数:12,代码来源:SourceView.cs


注:本文中的Value.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。