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


C# BaseObject.GetType方法代码示例

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


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

示例1: LinkBaseObject

        public LinkBaseObject(BaseObject obj)
        {
            if (obj != null)
            {
                Type objType = obj.GetType().GetBaseObjectType();

                this.ID = obj.ID;
                this.FullName = objType.FullName;
                this.Assembly = objType.Assembly.FullName;
            }
        }
开发者ID:altaricka,项目名称:vDesign,代码行数:11,代码来源:LinkBaseObject.cs

示例2: Render

        public string Render(string template, BaseObject obj, IDictionary<string, string> additional = null)
        {
            if (String.IsNullOrEmpty(template)) return template;

            IEnumerable<PropertyInfo> props = obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);

            return Regex.Replace(template, Pattern, m =>
            {
                string match = m.Groups[1].Value;

                return props.FirstOrDefault(x => x.Name == match || x.GetCustomAttribute<DetailViewAttribute>().With(a => a.Name) == match)
                    .With(x => x.GetValue(obj)).With(x => x.ToString()) ?? additional.With(x => x.ContainsKey(match).IfTrue(() => x[match])) ?? m.Groups[0].Value;
            });
        }
开发者ID:altaricka,项目名称:vDesign,代码行数:14,代码来源:TemplateRenderer.cs

示例3: Assign

    public bool Assign( bool checkLowercase )
    {
        // get object from ObjectManager
        baseObject = ObjectManager.GetInstance().GetBaseObject(Object);
        if (baseObject != null)
        {
            Type type = baseObject.GetType();
            if (type != null)
            {
                if ( checkLowercase == true )
				{
					string name = GetVariableFromLowerCase(Variable);
                    fieldInfo = type.GetField(name);
				} else
                    fieldInfo = type.GetField(Variable);

                if (fieldInfo != null)
                {
#if DEBUG_DECISION_ENGINE
                    if (fieldInfo.FieldType == typeof(System.Single))
                    {
                        UnityEngine.Debug.Log("DecisionVariable.Assign() : Value <FLOAT:" + Object + "." + Variable + ">=" + GetFloat());
                    }
                    if (fieldInfo.FieldType == typeof(System.String))
                    {
                        UnityEngine.Debug.Log("DecisionVariable.Assign() : Value <STRING:" + Object + "." + Variable + ">=" + GetString());
                    }
                    if (fieldInfo.FieldType == typeof(System.Boolean))
                    {
                        UnityEngine.Debug.Log("DecisionVariable.Assign() : Value <BOOLEAN:" + Object + "." + Variable + ">=" + GetBoolean());
                    }
                    if (fieldInfo.FieldType == typeof(System.Int32))
                    {
                        UnityEngine.Debug.Log("DecisionVariable.Assign() : Value <INT:" + Object + "." + Variable + ">=" + GetInt());
                    }
#endif
                    return true;
                }
                else
                {
                    // check for Property (get/set)
                    if ( checkLowercase == true )
					{
						string name = GetVariableFromLowerCase(Variable);
                        propInfo = type.GetProperty(name);
					}
                    else
					{
                        propInfo = type.GetProperty(Variable);
					}

                    if (propInfo == null)
					{
#if DEBUG_DECISION_ENGINE
                        UnityEngine.Debug.LogError("DecisionVariable.Assign() : Can't GetField or GetMethod=" + Object + "." + Variable);
#endif
					}
                    else
                    {
#if DEBUG_DECISION_ENGINE
                        UnityEngine.Debug.Log("DecisionVariable.Assign() : Variable is member=" + Object + "." + Variable);
#endif
						return true;
                    }
                }
            }
            else
                UnityEngine.Debug.LogError("DecisionVariable.Assign() : Can't GetType=" + Object);
        }
        else
            UnityEngine.Debug.LogError("DecisionVariable.Assign() : Can't find Object=" + Object);

        return false;
    }
开发者ID:MedStarSiTEL,项目名称:UnityTrauma,代码行数:74,代码来源:DecisionEngine.cs

示例4: GetVariableFromLowerCase

    public string GetVariableFromLowerCase(string name)
    {
        string match = "";

        baseObject = ObjectManager.GetInstance().GetBaseObject(Object);
        if (baseObject != null)
        {
            // incoming is lower case, check for matches
            Type type = baseObject.GetType();
            if (type != null)
            {
                // try to match all fields
                foreach (FieldInfo f in type.GetFields())
                {
                    if (f.Name.ToLower() == name.ToLower())
                        return f.Name;
                }
                // try to match all fields
                foreach (PropertyInfo p in type.GetProperties())
                {
                    if (p.Name.ToLower() == name.ToLower())
                    {
#if DEBUG_DECISION_ENGINE
                        UnityEngine.Debug.LogError("GetVariableFromLowerCase() : found property=" + p.Name);                           
#endif
                        return p.Name;
                    }
                }
            }
        }
        return match;
    }
开发者ID:MedStarSiTEL,项目名称:UnityTrauma,代码行数:32,代码来源:DecisionEngine.cs

示例5: InitializeObject

        public void InitializeObject(ISecurityUser securityUser, BaseObject src, BaseObject dest, IEnumerable<Entities.InitItem> inits)
        {
            var resultScript = String.Empty;

            try
            {
                var engine = Python.CreateEngine();

                engine.Runtime.LoadAssembly(Assembly.GetExecutingAssembly());

                var scope = engine.CreateScope(new Dictionary<string, object> { { "Dest", dest }, { "Src", src } });

                IEnumerable<RefObject> refObjects;

                var macroses = PrepareMacros(dest, inits, out refObjects);

                foreach (var refObj in refObjects)
                    scope.SetVariable(String.Format("_refobject_{0}", refObj.Property.Name), refObj.Object);

                foreach (var pair in macroses.AsEnumerable().Reverse())
                {
                    var script = new StringBuilder(String.Format("Dest.{0} =", pair.Property.Name));

                    foreach (var initItem in pair.Macroses)
                    {
                        switch (initItem.MacroType)
                        {
                            case MacroType.String:
                                script.AppendFormat(" '{0}'", initItem.Value);
                                break;
                            case MacroType.Number:
                                {
                                    if (pair.Property.PropertyType.IsEnum)
                                    {
                                        var tempName = String.Format("_enum{0}", pair.Property.Name);

                                        scope.SetVariable(tempName, Enum.Parse(pair.Property.PropertyType, initItem.Value));

                                        script.AppendFormat(tempName);

                                        break;
                                    }

                                    goto case MacroType.Operator;
                                }
                            case MacroType.Boolean:
                            {
                                script.AppendFormat(" '{0}'", initItem.Value);

                                break;
                            }
                            case MacroType.Operator:
                                script.AppendFormat(" {0}", initItem.Value);
                                break;
                            case MacroType.InitObject:
                                {
                                    script.AppendFormat(" Src.{0}", initItem.Value);
                                    break;
                                }
                            case MacroType.BaseObject:
                                if (dest is ICategorizedItem)
                                {
                                    var foreignKey = pair.Property.GetCustomAttribute<ForeignKeyAttribute>();

                                    if (foreignKey != null && foreignKey.Name == "CategoryID")
                                    {
                                        script.Append(" None");

                                        dest.GetType().GetProperty("CategoryID").SetValue(dest, JsonConvert.DeserializeObject<ObjectRefItem>(initItem.Value).ID);

                                        break;
                                    }
                                }

                                script.AppendFormat(" _refobject_{0}", pair.Property.Name);
                                break;
                            case MacroType.Function:
                                if (initItem.Value == "dtn()")
                                {
                                    var locVar = this.GenerateVaribleName();

                                    scope.SetVariable(locVar, DateTime.Now);

                                    script.AppendFormat(" {0}", locVar);
                                }
                                break;
                            case MacroType.DateTime:
                            {
                                DateTime dt;
                                if (DateTime.TryParse(initItem.Value, out dt))
                                {
                                    var locVar = this.GenerateVaribleName();

                                    scope.SetVariable(locVar, dt);

                                    script.AppendFormat(" {0}", locVar);

                                    break;
                                }

//.........这里部分代码省略.........
开发者ID:altaricka,项目名称:vDesign,代码行数:101,代码来源:WFObjectInitializer.cs

示例6: PrepareMacros

        private static IEnumerable<MacroPropertyPair> PrepareMacros(BaseObject dest, IEnumerable<Entities.InitItem> inits, out IEnumerable<RefObject> refObjects)
        {
            try
            {
                var macroses = inits.Join(dest.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance),
                    item => item.Member,
                    info => info.Name,
                    (item, info) => new MacroPropertyPair(JsonConvert.DeserializeObject<IEnumerable<InitItem>>(item.Value), info))
                    .ToList();

                refObjects = macroses.SelectMany(x => x.Macroses,
                    (x, init) => new { init.MacroType, InitItem = init, x.Property })
                    .Where(x => x.MacroType == MacroType.BaseObject)
                    .Select(x => new { x.Property, ObjectRefItem = JsonConvert.DeserializeObject<ObjectRefItem>(x.InitItem.Value) })
                    .Select(x => new RefObject(x.Property, Activator.CreateInstance(x.Property.PropertyType)
                        .IfNotNull(o => o.GetType().GetProperty("ID").SetValue(o, x.ObjectRefItem.ID))));

                return macroses;
            }
            catch (Exception e)
            {
                throw new BadMacroException("BadMacroException", e);
            }
        }
开发者ID:altaricka,项目名称:vDesign,代码行数:24,代码来源:WFObjectInitializer.cs


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