static bool AssemblyPredicate( Type t )
 {
     return
         !t.IsAbstract &&
         t.IsSubclassOf( typeof(ScriptableObject) ) &&
         !t.IsSubclassOf( typeof(Editor) );
 }
Beispiel #2
0
 internal static WriteJsonValue GetWriteJsonMethod(Type type)
 {
     var t = Reflection.GetJsonDataType (type);
     if (t == JsonDataType.Primitive) {
         return typeof (decimal).Equals (type) ? WriteDecimal
                 : typeof (byte).Equals (type) ? WriteByte
                 : typeof (sbyte).Equals (type) ? WriteSByte
                 : typeof (short).Equals (type) ? WriteInt16
                 : typeof (ushort).Equals (type) ? WriteUInt16
                 : typeof (uint).Equals (type) ? WriteUInt32
                 : typeof (ulong).Equals (type) ? WriteUInt64
                 : typeof (char).Equals (type) ? WriteChar
                 : (WriteJsonValue)WriteUnknown;
     }
     else if (t == JsonDataType.Undefined) {
         return type.IsSubclassOf (typeof (Array)) && type.GetArrayRank () > 1 ? WriteMultiDimensionalArray
             : type.IsSubclassOf (typeof (Array)) && typeof (byte[]).Equals (type) == false ? WriteArray
             : typeof (KeyValuePair<string,object>).Equals (type) ? WriteKeyObjectPair
             : typeof (KeyValuePair<string,string>).Equals (type) ? WriteKeyValuePair
             : (WriteJsonValue)WriteObject;
     }
     else {
         return _convertMethods[(int)t];
     }
 }
 public virtual ICauterizeTypeFormatter GetFormatter(Type t)
 {
     ICauterizeTypeFormatter formatter;
     if (t.IsSubclassOf(typeof (CauterizeComposite)))
     {
         formatter = new CauterizeCompositeFormatter(this);
     }
     else if (t.IsSubclassOf(typeof (CauterizeGroup)))
     {
         formatter = new CauterizeGroupFormatter(this);
     }
     else if (t.IsSubclassOf(typeof (CauterizeFixedArray)))
     {
         formatter = new CauterizeFixedArrayFormatter(this);
     }
     else if (t.IsSubclassOf(typeof (CauterizeVariableArray)))
     {
         formatter = new CauterizeVariableArrayFormatter(this);
     }
     else if (t.IsSubclassOf(typeof (Enum)))
     {
         formatter = new CauterizeEnumFormatter();
     }
     else
     {
         formatter = new CauterizePrimitiveFormatter();
     }
     return formatter;
 }
Beispiel #4
0
        public static UnityEngine.Object[] GetFiltered(System.Type type, UnityEditor.SelectionMode mode)
        {
            ArrayList list = new ArrayList();

            if ((type == typeof(Component)) || type.IsSubclassOf(typeof(Component)))
            {
                foreach (Transform transform in GetTransforms(mode))
                {
                    Component component = transform.GetComponent(type);
                    if (component != null)
                    {
                        list.Add(component);
                    }
                }
            }
            else if ((type == typeof(GameObject)) || type.IsSubclassOf(typeof(GameObject)))
            {
                foreach (Transform transform2 in GetTransforms(mode))
                {
                    list.Add(transform2.gameObject);
                }
            }
            else
            {
                foreach (UnityEngine.Object obj2 in GetObjectsMode(mode))
                {
                    if ((obj2 != null) && ((obj2.GetType() == type) || obj2.GetType().IsSubclassOf(type)))
                    {
                        list.Add(obj2);
                    }
                }
            }
            return((UnityEngine.Object[])list.ToArray(typeof(UnityEngine.Object)));
        }
Beispiel #5
0
        /// <summary>
        ///   <para>Returns the current selection filtered by type and mode.</para>
        /// </summary>
        /// <param name="type">Only objects of this type will be retrieved.</param>
        /// <param name="mode">Further options to refine the selection.</param>
        public static UnityEngine.Object[] GetFiltered(System.Type type, SelectionMode mode)
        {
            ArrayList arrayList = new ArrayList();

            if (type == typeof(Component) || type.IsSubclassOf(typeof(Component)))
            {
                foreach (Component transform in Selection.GetTransforms(mode))
                {
                    Component component = transform.GetComponent(type);
                    if ((bool)((UnityEngine.Object)component))
                    {
                        arrayList.Add((object)component);
                    }
                }
            }
            else if (type == typeof(GameObject) || type.IsSubclassOf(typeof(GameObject)))
            {
                foreach (Transform transform in Selection.GetTransforms(mode))
                {
                    arrayList.Add((object)transform.gameObject);
                }
            }
            else
            {
                foreach (UnityEngine.Object @object in Selection.GetObjectsMode(mode))
                {
                    if (@object != (UnityEngine.Object)null && (@object.GetType() == type || @object.GetType().IsSubclassOf(type)))
                    {
                        arrayList.Add((object)@object);
                    }
                }
            }
            return((UnityEngine.Object[])arrayList.ToArray(typeof(UnityEngine.Object)));
        }
Beispiel #6
0
        static ILockTest CreateTest( Type testType, Type lockType, object[] parameters )
        {
            if ( ! testType.IsSubclassOf(typeof(ILockTest)) )
            {
                throw new InvalidCastException("Test type must be derived from ILockTest");
            }

            if ( null != lockType )
            {
                if ( ! testType.IsSubclassOf(typeof(ISyncLock)) )
                {
                    throw new InvalidCastException("Lock type must be derived from ISyncLock");
                }
            }

            ISyncLock syncLock = (ISyncLock) CreateTypeInstance(lockType);

            if ( null == syncLock )
            {
                throw new ArgumentException("Unable to construct an ISyncLock instance with specified parameters");
            }

            ILockTest test = (ILockTest) CreateTypeInstance(testType, new object[] {syncLock});

            if ( null == test )
            {
                throw new ArgumentException("Unable to construct an ILockTest instance with specified ISyncLock");
            }

            return test;
        }
		public static BulkGenericType Classify( BODType deedType, Type itemType )
		{
			if ( deedType == BODType.Tailor )
			{
				if ( itemType == null || itemType.IsSubclassOf( typeof( BaseArmor ) ) || itemType.IsSubclassOf( typeof( BaseShoes ) ) )
					return BulkGenericType.Leather;

				return BulkGenericType.Cloth;
			}
			//else if ( deedType == BODType.Fletcher )
//////////////////////////////////
//  Cap & Fletch BOD Addon 2/2  //
//////////////////////////////////
            else if ( deedType == BODType.Fletcher )
			{
				if ( itemType == null || itemType.IsSubclassOf( typeof( BaseRanged ) ) )
					return BulkGenericType.Wood;

				return BulkGenericType.Wood;
			}
            else if ( deedType == BODType.Carpenter )
			{
				if ( itemType == null || itemType.IsSubclassOf( typeof( BaseStaff ) ) || itemType.IsSubclassOf( typeof( BaseShield ) ) )
					return BulkGenericType.Wood;

				return BulkGenericType.Wood;
			}
//////////////////////////////////
//  End of Edit            2/2  //
//////////////////////////////////
				//return BulkGenericType.Wood;

			return BulkGenericType.Iron;
		}
Beispiel #8
0
 private int ReadField(Context context, FieldType field, int fieldIndex, ArrayList fieldValues, out object fieldValue, ref byte bitOffset)
 {
     fieldValue = null;
     System.Type type = field.GetType();
     if ((type == typeof(Integer)) || type.IsSubclassOf(typeof(Integer)))
     {
         return(this.ReadField(context, (Integer)field, out fieldValue));
     }
     if ((type == typeof(FloatingPoint)) || type.IsSubclassOf(typeof(FloatingPoint)))
     {
         return(this.ReadField(context, (FloatingPoint)field, out fieldValue));
     }
     if ((type == typeof(CharString)) || type.IsSubclassOf(typeof(CharString)))
     {
         return(this.ReadField(context, (CharString)field, fieldIndex, fieldValues, out fieldValue));
     }
     if ((type == typeof(BitString)) || type.IsSubclassOf(typeof(BitString)))
     {
         return(this.ReadField(context, (BitString)field, out fieldValue, ref bitOffset));
     }
     if (type != typeof(TypeReference))
     {
         throw new NotImplementedException("Fields of type '" + type.ToString() + "' are not implemented yet.");
     }
     return(this.ReadField(context, (TypeReference)field, out fieldValue));
 }
 private static bool IsEcommerceType(Type entityType)
 {
     return MrCMSApp.AllAppTypes.ContainsKey(entityType) &&
            MrCMSApp.AllAppTypes[entityType] == EcommerceApp.EcommerceAppName &&
            (!entityType.IsSubclassOf(typeof (Document)) &&
             !entityType.IsSubclassOf(typeof (UserProfileData)) && !entityType.IsSubclassOf(typeof (Widget)));
 }
Beispiel #10
0
 // Token: 0x060003EE RID: 1006 RVA: 0x0000B1B0 File Offset: 0x0000A1B0
 private int WriteField(Context context, FieldType field, int fieldIndex, ComplexValue[] fieldValues, object fieldValue, ref byte bitOffset)
 {
     System.Type type = field.GetType();
     if (type == typeof(Integer) || type.IsSubclassOf(typeof(Integer)))
     {
         return(this.WriteField(context, (Integer)field, fieldValue));
     }
     if (type == typeof(FloatingPoint) || type.IsSubclassOf(typeof(FloatingPoint)))
     {
         return(this.WriteField(context, (FloatingPoint)field, fieldValue));
     }
     if (type == typeof(CharString) || type.IsSubclassOf(typeof(CharString)))
     {
         return(this.WriteField(context, (CharString)field, fieldIndex, fieldValues, fieldValue));
     }
     if (type == typeof(BitString) || type.IsSubclassOf(typeof(BitString)))
     {
         return(this.WriteField(context, (BitString)field, fieldValue, ref bitOffset));
     }
     if (type == typeof(TypeReference) || type.IsSubclassOf(typeof(TypeReference)))
     {
         return(this.WriteField(context, (TypeReference)field, fieldValue));
     }
     throw new NotImplementedException("Fields of type '" + type.ToString() + "' are not implemented yet.");
 }
Beispiel #11
0
    public override void OnInspectorGUI()
    {
        if (target == null || !(target is MonoScript))
        {
            return;
        }
        MonoScript script = target as MonoScript;

        System.Type t = script.GetClass();
        if (t == null)
        {
            return;
        }
        if (!(t.IsSubclassOf(typeof(Editor)) || t.IsSubclassOf(typeof(EditorWindow))))
        {
            if (t.IsSubclassOf(typeof(ScriptableObject)) && GUILayout.Button("Create Asset"))
            {
                ScriptableObjectUtility.CreateAsset(t);
            }
        }

        showCode = EditorGUILayout.Foldout(showCode, "Code");
        if (showCode)
        {
            EditorGUILayout.TextArea(script.text);
        }
    }
Beispiel #12
0
        public static string GetDisplayedName(System.Type type)
        {
            var typename = type.FullName;

            KnownType info;

            if (KnownType.Register.TryGetValue(typename, out info))
            {
                return(info.GenericName);
            }

            if (type.IsSubclassOf(KnownType.AnimControllerType) &&
                KnownType.Register.ContainsKey(KnownType.AnimControllerType.FullName))
            {
                return(type.Name);
            }

            if (type.IsSubclassOf(KnownType.ComponentType) &&
                KnownType.Register.ContainsKey(KnownType.ComponentType.FullName))
            {
                return(type.Name);
            }

            if (type.IsSubclassOf(KnownType.ScriptableObjectType) &&
                KnownType.Register.ContainsKey(KnownType.ScriptableObjectType.FullName))
            {
                return(type.Name);
            }

            return(null);
        }
    void SetBehavioursEnabled(bool b)
    {
        foreach (string type in toDisable)
        {
            Component   c = GetComponent(type) as Component;
            System.Type t = c.GetType();

            if (t.IsSubclassOf(typeof(Behaviour)))
            {
                Behaviour behaviour = c as Behaviour;
                behaviour.enabled = b;
            }
            else if (t.IsSubclassOf(typeof(Renderer)))
            {
                Renderer renderer = c as Renderer;
                renderer.enabled = b;
            }
            else if (t.IsSubclassOf(typeof(Collider)))
            {
                Collider collider = c as Collider;
                collider.enabled = b;
            }
            else if (t.IsSubclassOf(typeof(ParticleEmitter)))
            {
                ParticleEmitter emitter = c as ParticleEmitter;
                emitter.enabled = b;
            }
        }
    }
Beispiel #14
0
    void AddModType(GameObject go, System.Type name, bool modobj)
    {
        if (go)
        {
            if (!name.IsSubclassOf(typeof(MegaModifier)) && !name.IsSubclassOf(typeof(MegaWarp)))
            {
                go.AddComponent(name);
            }
            else
            {
                MeshFilter mf = go.GetComponent <MeshFilter>();
                if (mf != null)
                {
                    if (modobj)
                    {
                        if (name.IsSubclassOf(typeof(MegaModifier)))
                        {
                            MegaModifyObject mod = go.GetComponent <MegaModifyObject>();

                            if (mod == null)
                            {
                                mod = go.AddComponent <MegaModifyObject>();
                                mod.NormalMethod = NormalMethod;
                            }
                        }
                    }

                    if (name != null)
                    {
                        if (name.IsSubclassOf(typeof(MegaModifier)))
                        {
                            MegaModifier md = (MegaModifier)go.AddComponent(name);
                            if (md)
                            {
                                md.gizCol1 = col1;
                                md.gizCol2 = col2;
                            }
                        }
                        else
                        {
                            if (name.IsSubclassOf(typeof(MegaWarp)))
                            {
                                MegaWarp md = (MegaWarp)go.AddComponent(name);
                                if (md)
                                {
                                    md.GizCol1 = col1;
                                    md.GizCol2 = col2;
                                }
                            }
                            else
                            {
                                go.AddComponent(name);
                            }
                        }
                    }
                }
            }
        }
    }
 public object GetService(Type serviceType)
 {
     return serviceType.IsSubclassOf(typeof (ControllerBase))
         ? Activator.CreateInstance(serviceType, new ServiceManager())
         : serviceType.IsSubclassOf(typeof (ApiController))
             ? Activator.CreateInstance(serviceType)
             : null;
 }
 public IBsonSerializer GetSerializer(Type type)
 {
     if (type == typeof(IGameObject) || type.IsSubclassOf(typeof(IGameObject)) || type.GetInterface(typeof(IGameObject).Name) != null)
         return new GameObjectSerializer();
     if (type == typeof(IDataObject) || type.IsSubclassOf(typeof(IDataObject)) || type.GetInterface(typeof(IDataObject).Name) != null)
         return new DataObjectSerializer<IDataObject>();
     return null;
 }
 private static bool IsTypeCompatible(System.Type type)
 {
     if ((type == null) || (!type.IsSubclassOf(typeof(MonoBehaviour)) && !type.IsSubclassOf(typeof(ScriptableObject))))
     {
         return(false);
     }
     return(true);
 }
 private static bool IsTypeCompatible(Type type)
 {
     if ((type == null) || (!type.IsSubclassOf(typeof(MonoBehaviour)) && !type.IsSubclassOf(typeof(ScriptableObject))))
     {
         return false;
     }
     return true;
 }
		public override bool CanConvert(Type objectType)
		{
		    return objectType == typeof (RavenJToken) ||
		           objectType == typeof (DynamicJsonObject) ||
		           objectType == typeof (DynamicNullObject) ||
		           objectType.IsSubclassOf(typeof (RavenJToken)) ||
		           objectType.IsSubclassOf(typeof (DynamicJsonObject));
		}
        public object Get(string name, System.Type type)
        {
            object obj = null;

            if (type == typeof(UnityEngine.Object) || type.IsSubclassOf(typeof(UnityEngine.Object)))
            {
                obj = objects.Get(name);
            }
            else if (type == typeof(float))
            {
                obj = floats.Get(name);
            }
            else if (type == typeof(int))
            {
                obj = ints.Get(name);
            }
            else if (type == typeof(string))
            {
                obj = strings.Get(name) ?? string.Empty;
            }
            else if (type == typeof(bool))
            {
                obj = bools.Get(name);
            }
            else if (type.IsSubclassOf(typeof(System.Enum)))
            {
                obj = enums.Get(name);
            }
            else if (type == typeof(Vector3))
            {
                obj = vector3s.Get(name);
            }
            else if (type == typeof(Vector2))
            {
                obj = vector2s.Get(name);
            }
            else if (type == typeof(Vector4))
            {
                obj = vector4s.Get(name);
            }
            else if (type == typeof(Color))
            {
                obj = colors.Get(name);
            }
            else if (type == typeof(LayerMaskMap))
            {
                obj = layerMasks.Get(name);
            }
            else
            {
                throw new NotSupportedException($"Type {type.AssemblyQualifiedName} is not supported. ({name})");
            }
            if (obj == null && type.IsValueType)
            {
                return(Activator.CreateInstance(type));
            }
            return(obj);
        }
Beispiel #21
0
        protected void BuildPropertySet(Type p, StringCollection propertySet)
        {
            if (TypeToLdapPropListMap[this.MappingTableIndex].ContainsKey(p))
            {
                Debug.Assert(TypeToLdapPropListMap[this.MappingTableIndex].ContainsKey(p));
                string[] props = new string[TypeToLdapPropListMap[this.MappingTableIndex][p].Count];
                TypeToLdapPropListMap[this.MappingTableIndex][p].CopyTo(props, 0);
                propertySet.AddRange(props);
            }
            else
            {
                Type baseType;

                if (p.IsSubclassOf(typeof(UserPrincipal)))
                {
                    baseType = typeof(UserPrincipal);
                }
                else if (p.IsSubclassOf(typeof(GroupPrincipal)))
                {
                    baseType = typeof(GroupPrincipal);
                }
                else if (p.IsSubclassOf(typeof(ComputerPrincipal)))
                {
                    baseType = typeof(ComputerPrincipal);
                }
                else if (p.IsSubclassOf(typeof(AuthenticablePrincipal)))
                {
                    baseType = typeof(AuthenticablePrincipal);
                }
                else
                {
                    baseType = typeof(Principal);
                }

                Hashtable propertyList = new Hashtable();

                // Load the properties for the base types...
                foreach (string s in TypeToLdapPropListMap[this.MappingTableIndex][baseType])
                {
                    if (!propertyList.Contains(s))
                    {
                        propertyList.Add(s, s);
                    }
                }

                // Reflect the properties off the extension class and add them to the list.                
                BuildExtensionPropertyList(propertyList, p);

                foreach (string property in propertyList.Values)
                {
                    propertySet.Add(property);
                }

                // Cache the list for this property type so we don't need to reflect again in the future.                                
                this.AddPropertySetToTypePropListMap(p, propertySet);
            }
        }
Beispiel #22
0
 static bool IsAsset(System.Type type)
 {
     return(!type.IsSubclassOf(typeof(UnityEngine.Component)) &&
            type.IsSubclassOf(typeof(UnityEngine.Object)) &&
            type.Name != "Component"
            //exceptions
            && type.Name != "LightmapSettings" && type.Name != "RenderSettings"
            );
 }
        public override bool IsDiscriminated(Type type)
        {
            //return true;
            if (type.IsSubclassOf(typeof(BillingTransaction)) || type.IsSubclassOf(typeof(AccountMeta)))
            {
                return true;
            }

            return false;
        }
Beispiel #24
0
        /// <summary>
        /// 绑定列表控件和数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="T1"></typeparam>
        /// <param name="list"></param>
        public void ObserverListAll <T, T1>(UniRx.IReactiveCollection <T1> list, bool autoWidth = false) where T : UIBase where T1 : IViewModel
        {
            System.Type type   = typeof(T);
            System.Type vmType = typeof(T1);
            bool        isImpleIViewModelCtrl     = vmType.IsSubclassOf(typeof(IViewModelCtrl));
            bool        isImpleIViewModelPosition = vmType.IsSubclassOf(typeof(IViewModelStyle));
            var         g          = gObject;
            var         u          = uiBase;
            var         observeAdd = list.ObserveAdd();
            var         subAdd     = observeAdd.Subscribe((o) =>
            {
                if (isImpleIViewModelCtrl)
                {
                    type = (o.Value as IViewModelCtrl).CtrlType;
                }
                var ctrl = System.Activator.CreateInstance(type, g, o.Value) as T;
                ctrl.SetMainViewModel(o.Value as IViewModel);
                ctrl.CreateUIInstance(false);

                if (isImpleIViewModelPosition)
                {
                    var vmPos = (o.Value as IViewModelStyle);
                    var pos   = vmPos.LocalPosition;
                    ctrl.gObject.SetPosition(pos.x, pos.y, pos.z);
                }
                //g.AddSelection(g.numItems, true);
                u.TempKv[o.Value] = ctrl;
                ctrl.AddToPanel(u);
            });
            var it = list.GetEnumerator();

            while (it.MoveNext())
            {
                if (isImpleIViewModelCtrl)
                {
                    type = (it.Current as IViewModelCtrl).CtrlType;
                }

                var ctrl = System.Activator.CreateInstance(type, g, it.Current) as T;
                ctrl.SetMainViewModel(it.Current as IViewModel);
                ctrl.CreateUIInstance(false);
                if (isImpleIViewModelPosition)
                {
                    var vmPos = (it.Current as IViewModelStyle);
                    var pos   = vmPos.LocalPosition;
                    ctrl.gObject.SetPosition(pos.x, pos.y, pos.z);
                }
                //g.AddSelection(g.numItems, true);
                u.TempKv[it.Current] = ctrl;
                ctrl.AddToPanel(uiBase);
            }

            uiBase.AddDisposable(subAdd);
        }
Beispiel #25
0
        //TODO: If placed in your domain, uncomment and replace MyDbContext with your domain's DbContext/ObjectContext class.
        //public UniqueAttribute() : this(typeof(MyDbContext)) { }
        /// <summary>
        /// Initializes a new instance of <see cref="UniqueAttribute"/>.
        /// </summary>
        /// <param name="contextType">The type of <see cref="DbContext"/> or <see cref="ObjectContext"/> subclass that will be used to search for duplicates.</param>
        public UniqueAttribute(Type contextType)
        {
            if (contextType == null)
                throw new ArgumentNullException("contextType");
            if (!contextType.IsSubclassOf(typeof(DbContext)) && !contextType.IsSubclassOf(typeof(ObjectContext)))
                throw new ArgumentException("The contextType Type must be a subclass of DbContext or ObjectContext.", "contextType");
            if (contextType.GetConstructor(Type.EmptyTypes) == null)
                throw new ArgumentException("The contextType type must declare a public parameterless consructor.");

            _ContextType = contextType;
        }
		public static BulkGenericType Classify( BODType deedType, Type itemType )
		{
			if ( deedType == BODType.Tailor )
			{
				if ( itemType == null || itemType.IsSubclassOf( typeof( BaseArmor ) ) || itemType.IsSubclassOf( typeof( BaseShoes ) ) )
					return BulkGenericType.Leather;

				return BulkGenericType.Cloth;
			}

			return BulkGenericType.Iron;
		}
Beispiel #27
0
        internal object DataMarshal(IntPtr data)
        {
            object ret = null;

            if (element_type != null)
            {
                if (element_type == typeof(string))
                {
                    ret = Marshaller.Utf8PtrToString(data);
                }
                else if (element_type == typeof(FilenameString))
                {
                    ret = Marshaller.FilenamePtrToString(data);
                }
                else if (element_type == typeof(IntPtr))
                {
                    ret = data;
                }
                else if (element_type.IsSubclassOf(typeof(GLib.Object)))
                {
                    ret = GLib.Object.GetObject(data, false);
                }
                else if (element_type.IsSubclassOf(typeof(GLib.Opaque)))
                {
                    ret = GLib.Opaque.GetOpaque(data, element_type, elements_owned);
                }
                else if (element_type == typeof(int))
                {
                    ret = (int)data;
                }
                else if (element_type.IsValueType)
                {
                    ret = Marshal.PtrToStructure(data, element_type);
                }
                else if (element_type.IsInterface)
                {
                    Type adapter_type = element_type.Assembly.GetType(InterfaceToAdapterTypeName(element_type));
                    System.Reflection.MethodInfo method = adapter_type.GetMethod("GetObject", new Type[] { typeof(IntPtr), typeof(bool) });
                    ret = method.Invoke(null, new object[] { data, false });
                }
                else
                {
                    ret = Activator.CreateInstance(element_type, new object[] { data });
                }
            }
            else if (Object.IsObject(data))
            {
                ret = GLib.Object.GetObject(data, false);
            }

            return(ret);
        }
Beispiel #28
0
        /// <summary>
        /// Factory method which creates declaration corresponding to given type.
        /// </summary>
        public static IDecl ToDecl(System.Type type, CommentNavigator navigator, ProjectNavigator projNavigator)
        {
            if (type.IsSubclassOf(typeof(Enum)))
            {
                return(EnumToDecl(type, navigator, projNavigator));
            }

            if (type.IsSubclassOf(typeof(Data)))
            {
                return(TypeToDecl(type, navigator, projNavigator));
            }

            throw new ArgumentException($"{type.FullName} is not subclass of Enum or Data", nameof(type));
        }
Beispiel #29
0
        /// <summary>
        /// Checks if type could be used in declaration.
        /// Namely, it checks if it is one of the following: is primitive, is enum or derived from Data
        /// </summary>
        private static bool IsAllowedType(System.Type type)
        {
            if (IsRoot(type))
            {
                return(false);
            }

            type = GetListArgument(type);
            type = GetNullableArgument(type);

            return(AllowedPrimitiveTypes.Contains(type) ||
                   type.IsSubclassOf(typeof(Data)) ||
                   type.IsSubclassOf(typeof(Enum)));
        }
        protected override void GenerateCodeFor(Type type)
        {
            var codeNamespace = GetNamespace(type);

            Action<Action<Type>> run = action =>
            {
                AppendUsings(UsingNamespaces);
                sb.AppendLine();

                cw.Indented("namespace ");
                sb.AppendLine(codeNamespace);
                cw.InBrace(delegate {
                    action(type);
                });
            };

            if (type.GetIsEnum())
                run(GenerateEnum);
            else if (type.IsSubclassOf(typeof(Controller)))
                run(GenerateService);
            else
            {
                var formScriptAttr = type.GetCustomAttribute<FormScriptAttribute>();
                if (formScriptAttr != null)
                {
                    run(t => GenerateForm(t, formScriptAttr));
                    EnqueueTypeMembers(type);

                    if (type.IsSubclassOf(typeof(ServiceRequest)))
                    {
                        AddFile(RemoveRootNamespace(codeNamespace,
                            this.fileIdentifier + (IsTS() ? ".ts" : ".cs")));

                        this.fileIdentifier = type.Name;
                        run(GenerateBasicType);
                    }

                    return;
                }
                else if (type.GetCustomAttribute<ColumnsScriptAttribute>() != null)
                {
                    //GenerateColumns(type);
                    run(EnqueueTypeMembers);
                    return;
                }
                else
                    run(GenerateBasicType);
            }
        }
 public static SqlCodeGeneratorBase CreateCodeGenerator(Type t)
 {
     if (t == typeof(Schema.SqlServer.SqlServerDataset) || t.IsSubclassOf(typeof(Schema.SqlServer.SqlServerDataset)))
     {
         return new SqlServerCodeGenerator();
     }
     else if (t == typeof(Schema.MySql.MySqlDataset) || t.IsSubclassOf(typeof(Schema.MySql.MySqlDataset)))
     {
         return new MySqlCodeGenerator();
     }
     else
     {
         return new PostgreSqlCodeGenerator();
     }
 }
Beispiel #32
0
        public static KnownType GetKnownType(System.Type type)
        {
            if (type == null)
            {
                return(null);
            }

            var typename = type.FullName;

            KnownType info;

            if (KnownType.Register.TryGetValue(typename, out info))
            {
                return(info);
            }

            if (type.IsSubclassOf(KnownType.AnimControllerType))
            {
                typename = KnownType.AnimControllerType.FullName;

                if (KnownType.Register.TryGetValue(typename, out info))
                {
                    return(info);
                }
            }

            if (type.IsSubclassOf(KnownType.ComponentType))
            {
                typename = KnownType.ComponentType.FullName;

                if (KnownType.Register.TryGetValue(typename, out info))
                {
                    return(info);
                }
            }

            if (type.IsSubclassOf(KnownType.ScriptableObjectType))
            {
                typename = KnownType.ScriptableObjectType.FullName;

                if (KnownType.Register.TryGetValue(typename, out info))
                {
                    return(info);
                }
            }

            return(null);
        }
Beispiel #33
0
        public DynamicMetaObject ConvertWorker(DynamicMetaObjectBinder binder, Type toType, ConversionResultKind kind) {
            if (toType.IsSubclassOf(typeof(Delegate))) {
                return MakeDelegateTarget(binder, toType, Restrict(typeof(Method)));
            }

            return FallbackConvert(binder);
        }
        /// <summary>
        /// This code was taken from Mike Bouck's July 31st, 2005 blog post located here: http://blog.gatosoft.com/
        /// Many thanks to Mike for this updated .NET 2.0-compatible code.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="priority"></param>
        /// <param name="group"></param>
        private static void RegisterSoapExtension(Type type, int priority, PriorityGroup group)
        {
            if (!type.IsSubclassOf(typeof(SoapExtension)))
            {
                throw new ArgumentException("Type must be derived from SoapException.", "type");
            }

            if (priority < 1)
            {
                throw new ArgumentOutOfRangeException("priority", priority, "Priority must be greater or equal to 1.");
            }

            // get the current web services settings...
            WebServicesSection wss = WebServicesSection.Current;

            // set SoapExtensionTypes collection to read/write...
            FieldInfo readOnlyField = typeof(System.Configuration.ConfigurationElementCollection).GetField("bReadOnly", BindingFlags.NonPublic | BindingFlags.Instance);
            readOnlyField.SetValue(wss.SoapExtensionTypes, false);

            // inject SoapExtension...
            wss.SoapExtensionTypes.Add(new SoapExtensionTypeElement(type, priority, group));

            // set SoapExtensionTypes collection back to readonly and clear modified flags...
            MethodInfo resetModifiedMethod = typeof(System.Configuration.ConfigurationElement).GetMethod("ResetModified", BindingFlags.NonPublic | BindingFlags.Instance);
            resetModifiedMethod.Invoke(wss.SoapExtensionTypes, null);
            MethodInfo setReadOnlyMethod = typeof(System.Configuration.ConfigurationElement).GetMethod("SetReadOnly", BindingFlags.NonPublic | BindingFlags.Instance);
            setReadOnlyMethod.Invoke(wss.SoapExtensionTypes, null);
        }
        public SessionBuilderAttribute(Type sessionBuilderType)
        {
            if (!(sessionBuilderType.IsSubclassOf(typeof(SingletonSessionBuilder))))
                throw new ArgumentException("SessionBuilderType must derive from SingletonSessionBuilder");

            SessionBuilderType = sessionBuilderType;
        }
        // 

        internal ConnectionPoint(MethodInfo callbackMethod, Type interfaceType, Type controlType, string displayName, string id, bool allowsMultipleConnections) {
            if (callbackMethod == null) {
                throw new ArgumentNullException("callbackMethod");
            }

            if (interfaceType == null) {
                throw new ArgumentNullException("interfaceType");
            }

            if (controlType == null) {
                throw new ArgumentNullException("controlType");
            }

            if (!controlType.IsSubclassOf(typeof(Control))) {
                throw new ArgumentException(SR.GetString(SR.ConnectionPoint_InvalidControlType), "controlType");
            }

            if (String.IsNullOrEmpty(displayName)) {
                throw new ArgumentNullException("displayName");
            }

            _callbackMethod = callbackMethod;
            _interfaceType = interfaceType;
            _controlType = controlType;
            _displayName = displayName;
            _id = id;
            _allowsMultipleConnections = allowsMultipleConnections;
        }
Beispiel #37
0
        private IGuiStyle FindDefaultStyle(StyleTypeNode root, System.Type elementType)
        {
            IGuiStyle result = null;

            if (root != null)
            {
                if (root.RegisteredType == elementType)
                {
                    result = root.DefaultStyle;
                }
                else
                {
                    foreach (StyleTypeNode child in root.Children)
                    {
                        if (elementType.IsSubclassOf(child.RegisteredType))
                        {
                            result = FindDefaultStyle(child, elementType);
                        }
                        else if (elementType == child.RegisteredType)
                        {
                            result = child.DefaultStyle;
                        }
                    }

                    if (result == null)
                    {
                        result = root.DefaultStyle;
                    }
                }
            }

            return(result);
        }
Beispiel #38
0
        private static Attribute[] InternalGetCustomAttributes(PropertyInfo element, Type type, bool inherit)
        {
            Contract.Requires(element != null);
            Contract.Requires(type != null);
            Contract.Requires(type.IsSubclassOf(typeof(Attribute)) || type == typeof(Attribute));

            // walk up the hierarchy chain
            Attribute[] attributes = (Attribute[])element.GetCustomAttributes(type, inherit);

            if (!inherit)
                return attributes;

            // create the hashtable that keeps track of inherited types
            Dictionary<Type, AttributeUsageAttribute> types = new Dictionary<Type, AttributeUsageAttribute>(11);

            // create an array list to collect all the requested attibutes
            List<Attribute> attributeList = new List<Attribute>();
            CopyToArrayList(attributeList, attributes, types);

            //if this is an index we need to get the parameter types to help disambiguate
            Type[] indexParamTypes = GetIndexParameterTypes(element);
            

            PropertyInfo baseProp = GetParentDefinition(element, indexParamTypes);
            while (baseProp != null)
            {
                attributes = GetCustomAttributes(baseProp, type, false);
                AddAttributesToList(attributeList, attributes, types);
                baseProp = GetParentDefinition(baseProp, indexParamTypes);
            }
            Array array = CreateAttributeArrayHelper(type, attributeList.Count);
            Array.Copy(attributeList.ToArray(), 0, array, 0, attributeList.Count);
            return (Attribute[])array;
        }
Beispiel #39
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="decoratorType"></param>
 public void AddDecorator(System.Type decoratorType)
 {
     if (decoratorType.IsSubclassOf(typeof(LineDecorator)))
     {
         this.Items.Add(new DecoratorEntry(decoratorType));
     }
 }
        /// <summary>
        ///     Use to ensure certain aspect is used when method is intercepted.
        /// </summary>
        /// <param name="aspectType"></param>
        /// <param name="missingAspectOption"></param>
        /// <param name="constructorArgs"></param>
        public RequiredAspectAttribute(Type aspectType, WhenRequiredAspectIsMissing missingAspectOption, params object[] constructorArgs)
        {
            if(aspectType == null)
                throw new ArgumentNullException("aspectType");

            if(!aspectType.IsSubclassOf(typeof(Aspect)))
                throw new ArgumentException("aspectType must be a subclass of the Aspect class.");

            this.AspectClassType = aspectType;

            if(missingAspectOption != WhenRequiredAspectIsMissing.DontInstantiate)
            {
                // Need to instantiate missing aspect
                Func<object> rawActivator = aspectType.GetFastActivatorWithEmbeddedArgs(constructorArgs);
                if(rawActivator != null)
                {
                    this.activator = () => (Aspect)rawActivator();
                } else
                {
                    // No activator found
                    string strErrorMsg = "Unable to find {0}({1}) constructor necessary to instantiate required missing aspect {0}."
                        .SmartFormat(aspectType.FormatCSharp(),
                            string.Join(", ", constructorArgs.Select(arg => arg == null ? "[ANY]" : arg.GetType().FormatCSharp()))
                        );

                    throw new ArgumentException(strErrorMsg, "aspectType");
                }
            }

            this.InstantiateIfMissing = missingAspectOption;
        }
		// The main method used
		public static bool UseBluePower( Mobile from, Type t )
		{
			if ( t == null )
				return false;
			else if ( Array.IndexOf( m_Spells, t ) == -1 )
				return false;
			else if ( t.IsSubclassOf( typeof( BlueMove ) ) )
			{
				BlueMove bluemove = NewMove( t, from );

				if ( bluemove != null )
				{
					BlueMove.SetCurrentMove( from, bluemove );
					from.SendMessage( "You prepare to use a monster's special attack" );
					return true;
				}
			}
			else if ( t.IsSubclassOf( typeof( BlueSpell ) ) )
			{
				BlueSpell bluespell = BlueSpellInfo.NewSpell( t, from );

				if ( bluespell != null )
				{
					bluespell.Cast();
					return true;
				}
			}

			return false;
		}
Beispiel #42
0
    static bool GetBaseType(System.Type type, System.Type baseType)
    {
        if (type == null || baseType == null || type == baseType)
        {
            return(false);
        }

        if (baseType.IsGenericType == false)
        {
            if (type.IsGenericType == false)
            {
                return(type.IsSubclassOf(baseType));
            }
        }
        else
        {
            baseType = baseType.GetGenericTypeDefinition();
        }

        type = type.BaseType;
        System.Type objectType = typeof(object);
        while (type != objectType && type != null)
        {
            System.Type curentType = type.IsGenericType ?
                                     type.GetGenericTypeDefinition() : type;
            if (curentType == baseType)
            {
                return(true);
            }

            type = type.BaseType;
        }

        return(false);
    }
        /// <summary>
        /// 指定されたビューモデルのインスタンスの IWindowCloseCommand インターフェイス の
        /// WindowClose メソッドを実行します。
        /// </summary>
        /// <returns></returns>
        public static void CloseViewModels(Type type)
        {
            if (!type.IsSubclassOf(typeof(ViewModelBase))) throw new ArgumentException(
                string.Format("引数の型が ViewModelBase の派生クラスになっていません(引数の型:{0})。", type.Name));
            if (Count(type) == 0) return;

            var list = GetViewModels(type);
            if (list.First() as IWindowCloseCommand == null)
            {
                throw new InvalidCastException(
                "オブジェクトは IWindowCloseCommand インターフェイスを実装していません。: " + type.ToString());
            }

            // ウィンドウが閉じることのできる状態か確認
            if (!isReadyCloseWindows(list))
            {
                throw new WindowPendingProcessException(
                    string.Format("ViewModel:{0} が閉じることの出来る状態にありません。", type.Name));
            }
            // ウィンドウを閉じる
            foreach (var n in list)
            {
                (n as IWindowCloseCommand).WindowClose();
            }
        }
        /// <summary>
        /// Deserialize a previously serialized game object.
        /// </summary>

        static void DeserializeComponents(this GameObject go, DataNode root)
        {
            DataNode scriptNode = root.GetChild("Components");

            if (scriptNode == null)
            {
                return;
            }

            for (int i = 0; i < scriptNode.children.size; ++i)
            {
                DataNode    node = scriptNode.children[i];
                System.Type type = UnityTools.GetType(node.name);

                if (type != null && type.IsSubclassOf(typeof(Component)))
                {
                    Component comp = go.GetComponent(type);
                    if (comp == null)
                    {
                        comp = go.AddComponent(type);
                    }
                    comp.Deserialize(node);
                }
            }
        }
Beispiel #45
0
 public static bool IsUserDefinedBehaviour(System.Type type)
 {
     return(type == typeof(UdonSharpBehaviour) ||
            type.IsSubclassOf(typeof(UdonSharpBehaviour)) ||
            (type.IsArray && (type.GetElementType() == typeof(UdonSharpBehaviour) || type.GetElementType().IsSubclassOf(typeof(UdonSharpBehaviour)) ||
                              type.GetElementType() == typeof(UdonBehaviour) || type.GetElementType().IsSubclassOf(typeof(UdonBehaviour)))));
 }
Beispiel #46
0
        public List <AssetReferenceMeta> GetAssociatedResourcesMeta(System.Type InType)
        {
            if ((InType != typeof(BaseEvent)) && !InType.IsSubclassOf(typeof(BaseEvent)))
            {
                return(null);
            }
            List <AssetReferenceMeta> list = null;

            if (!this.Repositories.TryGetValue(InType, out list))
            {
                list = new List <AssetReferenceMeta>();
                this.Repositories.Add(InType, list);
                for (System.Type type = InType; (type == typeof(BaseEvent)) || type.IsSubclassOf(typeof(BaseEvent)); type = type.BaseType)
                {
                    FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance);
                    if (fields != null)
                    {
                        for (int i = 0; i < fields.Length; i++)
                        {
                            FieldInfo      element         = fields[i];
                            AssetReference customAttribute = Attribute.GetCustomAttribute(element, typeof(AssetReference)) as AssetReference;
                            if (customAttribute != null)
                            {
                                AssetReferenceMeta item = new AssetReferenceMeta {
                                    MetaFieldInfo = element,
                                    Reference     = customAttribute
                                };
                                list.Add(item);
                            }
                        }
                    }
                }
            }
            return(list);
        }
        internal static string GetTypeIdentity(Type type)
        {
            Assumes.NotNull(type);
            string typeIdentity = null;

            if (!TypeIdentityCache.TryGetValue(type, out typeIdentity))
            {
                if (!type.IsAbstract && type.IsSubclassOf(typeof(Delegate)))
                {
                    MethodInfo method = type.GetMethod("Invoke");
                    typeIdentity = ContractNameServices.GetTypeIdentityFromMethod(method);
                }
                else
                {
                    StringBuilder typeIdentityStringBuilder = new StringBuilder();
                    WriteTypeWithNamespace(typeIdentityStringBuilder, type);
                    typeIdentity = typeIdentityStringBuilder.ToString();
                }

                Assumes.IsTrue(!string.IsNullOrEmpty(typeIdentity));
                TypeIdentityCache.Add(type, typeIdentity);
            }

            return typeIdentity;
        }
        public static string[] GetAddresses(Type bindingType,string mexAddress,Type contractType,string issuer,string secret)
        {
            Debug.Assert(bindingType.IsSubclassOf(typeof(Binding)) || bindingType == typeof(Binding));

             if(contractType.IsInterface == false)
             {
            Debug.Assert(false,contractType + " is not an interface");
            return new string[]{};
             }

             object[] attributes = contractType.GetCustomAttributes(typeof(ServiceContractAttribute),false);
             if(attributes.Length == 0)
             {
            Debug.Assert(false,"Interface " + contractType + " does not have the ServiceContractAttribute");
            return new string[]{};
             }

             ServiceEndpoint[] endpoints = GetEndpoints(mexAddress,issuer,secret);

             List<string> addresses = new List<string>();

             foreach(ServiceEndpoint endpoint in endpoints)
             {
            if(bindingType.IsInstanceOfType(endpoint.Binding))
            {
               ContractDescription description = ContractDescription.GetContract(contractType);
               if(endpoint.Contract.Name == description.Name && endpoint.Contract.Namespace == description.Namespace)
               {
                  Debug.Assert(addresses.Contains(endpoint.Address.Uri.AbsoluteUri) == false);
                  addresses.Add(endpoint.Address.Uri.AbsoluteUri);
               }
            }
             }
             return addresses.ToArray();
        }
Beispiel #49
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TerminalType"/> class.
        /// </summary>
        /// <param name="type">The <see cref="Type"/> of the <see cref="Terminal"/> described by this <see cref="TerminalType"/>.</param>
        public TerminalType(Type type)
            : base(LanguageElementTypes.Terminal)
        {
            if (!type.IsSubclassOf(typeof(Terminal)))
            {
                throw new ArgumentException("Type must be a subclass of Terminal.", "type");
            }

            _fullName = type.AssemblyQualifiedName;
            _name = GetName(type);
            _constructor = () => (Terminal) Activator.CreateInstance(type);

            var attributes = type.GetCustomAttributes(typeof(TerminalAttribute), false);
            foreach (var terminalAttribute in attributes.Cast<TerminalAttribute>())
            {
                if (terminalAttribute.IsStop)
                {
                    IsStop = true;
                }
                if (terminalAttribute.Ignore)
                {
                    Ignore = true;
                }
                Pattern = terminalAttribute.Pattern;
            }
        }
Beispiel #50
0
            public static bool DoObjectFieldProxy(ref System.Type objType, SerializedProperty property, ref object validator)
            {
                if (validator == null)
                {
                    if (objType != null && (objType == typeof(UdonSharpBehaviour) || objType.IsSubclassOf(typeof(UdonSharpBehaviour))))
                    {
                        validator = validationDelegate;
                    }
                    else if (property != null)
                    {
                        if (getFieldInfoFunc == null)
                        {
                            Assembly editorAssembly = AppDomain.CurrentDomain.GetAssemblies().First(e => e.GetName().Name == "UnityEditor");

                            System.Type scriptAttributeUtilityType = editorAssembly.GetType("UnityEditor.ScriptAttributeUtility");

                            MethodInfo fieldInfoMethod = scriptAttributeUtilityType.GetMethod("GetFieldInfoFromProperty", BindingFlags.NonPublic | BindingFlags.Static);

                            getFieldInfoFunc = (GetFieldInfoDelegate)Delegate.CreateDelegate(typeof(GetFieldInfoDelegate), fieldInfoMethod);
                        }

                        getFieldInfoFunc(property, out System.Type fieldType);

                        if (fieldType != null && (fieldType == typeof(UdonSharpBehaviour) || fieldType.IsSubclassOf(typeof(UdonSharpBehaviour))))
                        {
                            objType   = fieldType;
                            validator = validationDelegate;
                        }
                    }
                }

                return(true);
            }
Beispiel #51
0
        public static void RegisterNewAttributeType(string key, Type attributType)
        {
            if(!attributType.IsSubclassOf(typeof(Attribut)))
                throw new ArgumentException("Type must be subclass of Rtsp.Sdp.Attribut","attributType");

            attributMap[key] = attributType;
        }
 private static void DoEditRegularParameters(AnimationEvent evt, System.Type selectedParameter)
 {
     if ((selectedParameter == typeof(AnimationEvent)) || (selectedParameter == typeof(float)))
     {
         evt.floatParameter = EditorGUILayout.FloatField("Float", evt.floatParameter, new GUILayoutOption[0]);
     }
     if (selectedParameter.IsEnum)
     {
         evt.intParameter = EnumPopup("Enum", selectedParameter, evt.intParameter);
     }
     else if ((selectedParameter == typeof(AnimationEvent)) || (selectedParameter == typeof(int)))
     {
         evt.intParameter = EditorGUILayout.IntField("Int", evt.intParameter, new GUILayoutOption[0]);
     }
     if ((selectedParameter == typeof(AnimationEvent)) || (selectedParameter == typeof(string)))
     {
         evt.stringParameter = EditorGUILayout.TextField("String", evt.stringParameter, new GUILayoutOption[0]);
     }
     if (((selectedParameter == typeof(AnimationEvent)) || selectedParameter.IsSubclassOf(typeof(UnityEngine.Object))) || (selectedParameter == typeof(UnityEngine.Object)))
     {
         System.Type objType = typeof(UnityEngine.Object);
         if (selectedParameter != typeof(AnimationEvent))
         {
             objType = selectedParameter;
         }
         bool allowSceneObjects = false;
         evt.objectReferenceParameter = EditorGUILayout.ObjectField(ObjectNames.NicifyVariableName(objType.Name), evt.objectReferenceParameter, objType, allowSceneObjects, new GUILayoutOption[0]);
     }
 }
		public static void Register( int spellID, Type type )
		{
			if ( spellID < 0 || spellID >= m_Types.Length )
				return;

			if ( m_Types[spellID] == null )
				++m_Count;

			m_Types[spellID] = type;

			if( !m_IDsFromTypes.ContainsKey( type ) )
				m_IDsFromTypes.Add( type, spellID );

			if( type.IsSubclassOf( typeof( SpecialMove ) ) )
			{
				SpecialMove spm = null;

				try
				{
					spm = Activator.CreateInstance( type ) as SpecialMove;
				}
				catch
				{
				}

				if( spm != null )
					m_SpecialMoves.Add( spellID, spm );
			}
		}
        public Delegate GetStaticMethod(string name, System.Type delegShape)
        {
            if (!delegShape.IsSubclassOf(typeof(Delegate)))
            {
                throw new ArgumentException("Type must inherit from Delegate.", "delegShape");
            }

            var binding = PUBLIC_STATIC_MEMBERS;

            if (_includeNonPublic)
            {
                binding |= BindingFlags.NonPublic;
            }

            var invokeMeth = delegShape.GetMethod("Invoke");
            var paramTypes = (from p in invokeMeth.GetParameters() select p.ParameterType).ToArray();
            var meth       = _wrappedType.GetMethod(name, binding, null, paramTypes, null);

            if (meth != null)
            {
                try
                {
                    return(Delegate.CreateDelegate(delegShape, meth));
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("A method matching the name and shape requested could not be found.", ex);
                }
            }
            else
            {
                throw new InvalidOperationException("A method matching the name and shape requested could not be found.");
            }
        }
Beispiel #55
0
 private Script InstantiateScript(System.Type scripttype)
 {
     if (scripttype.IsSubclassOf(typeof(Script)))
     {
         string[] message = new string[] { "Instantiating script '", scripttype.FullName, "' in script domain '", this.Name, "' ..." };
         GTA.Log("[INFO]", message);
         try
         {
             return((Script)Activator.CreateInstance(scripttype));
         }
         catch (MissingMethodException)
         {
             string[] strArray4 = new string[] { "Failed to instantiate script '", scripttype.FullName, "' because no public default constructor was found." };
             GTA.Log("[ERROR]", strArray4);
         }
         catch (TargetInvocationException exception1)
         {
             string[] strArray2 = new string[] { "Failed to instantiate script '", scripttype.FullName, "' because constructor threw an exception:", Environment.NewLine, exception1.InnerException.ToString() };
             GTA.Log("[ERROR]", strArray2);
         }
         catch (Exception exception3)
         {
             string[] strArray = new string[] { "Failed to instantiate script '", scripttype.FullName, "':", Environment.NewLine, exception3.ToString() };
             GTA.Log("[ERROR]", strArray);
         }
     }
     return(null);
 }
    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        CustomValidator validator = (CustomValidator)source;

        args.IsValid = false;
        try {
            string      fullClassName = BuildFullClassName();
            System.Type classType     = System.Web.Compilation.BuildManager.GetType(fullClassName, true);
            //now that we have the type, make sure it has the proper base class.
            if (classType.IsSubclassOf(typeof(Commerce.Promotions.Coupon)))
            {
                args.IsValid = true;
            }
            else
            {
                validator.ErrorMessage = "The specified class does not inherit from Commerce.Promotions.Coupon";
            }
        }
        catch (TypeLoadException tlx) {
            validator.ErrorMessage = "The class could not be loaded. " + tlx.Message;
        }
        catch (ArgumentException argEx) {
            validator.ErrorMessage = "The type name specified is invalid. " + argEx.Message;
        }
        catch (Exception) {
            validator.ErrorMessage = "An unspecified error occured while loading the type";
        }
    }
Beispiel #57
0
        private static void InsertStyleDefault(StyleTypeNode root, System.Type type, IGuiStyle style)
        {
            if (type.IsSubclassOf(root.RegisteredType))
            {
                // Construct the branch to this type
                StyleTypeNode newBranchRoot = root.Find(type);
                if (newBranchRoot == null)
                {
                    newBranchRoot = new StyleTypeNode(type, style);

                    // Create empty elements up a known point in the tree
                    StyleTypeNode ancestor = FindClosestAncestor(root, type);

                    while (newBranchRoot.RegisteredType.BaseType != ancestor.RegisteredType)
                    {
                        StyleTypeNode oldBranchRoot = new StyleTypeNode(newBranchRoot);
                        newBranchRoot        = new StyleTypeNode(oldBranchRoot.RegisteredType.BaseType, null);
                        oldBranchRoot.Parent = newBranchRoot;
                        newBranchRoot.Children.Add(oldBranchRoot);
                    }

                    newBranchRoot.Parent = ancestor;
                    ancestor.Children.Add(newBranchRoot);
                }
            }
            else
            {
                throw new ArgumentException("Argument type(" + type.Name + ") must be a subclass of root.RegisteredType(" + root.RegisteredType.Name + ")");
            }
        }
Beispiel #58
0
        internal static object GetValue(object value, System.Type type)
        {
            if (value == System.DBNull.Value)
            {
                value = null;
            }
            System.Type type2 = type;
            object      result;

            if (value != null && EntityFactory.IsPrimitiveType(type, out type2))
            {
                result = EntityFactory.ChangeType(value, type2);
            }
            else if (value != null && type2.IsEnum && !value.GetType().IsEnum)
            {
                result = System.Enum.ToObject(type2, value);
            }
            else if (value == null && type2.IsSubclassOf(typeof(System.ValueType)))
            {
                result = EntityFactory.GetDefaultValue(type);
            }
            else
            {
                result = value;
            }
            return(result);
        }
 private void ValidateExceptionType(Type expectedExceptionType) {
    if(   !expectedExceptionType.IsSubclassOf(typeof(Exception))
          && !(expectedExceptionType == typeof(Exception))) {
       throw new ArgumentException("Argument value must refer to System.Exception or a type derived from it.");
    }
    _expectedExceptionType = expectedExceptionType;
 }
        private static string[] GetTaggedPropertyNames()
        {
            var properties = new HashSet <string>();

            var movements =
                from assembly in AppDomain.CurrentDomain.GetAssemblies()
                from type in assembly.GetTypes()
                where type.IsSubclassOf(typeof(Movement))
                select type;

            foreach (Type type in movements)
            {
                System.Reflection.FieldInfo[] fields = type.GetFields();
                foreach (System.Reflection.FieldInfo field in fields)
                {
                    TaggedProperty[] attributes = (TaggedProperty[])field.GetCustomAttributes(typeof(TaggedProperty), true);
                    foreach (TaggedProperty attribute in attributes)
                    {
                        properties.Add(attribute.name);
                    }
                }
            }

            return(properties.ToArray());
        }